Thread Tools Display Modes
04-23-07, 07:10 AM   #1
sirspikey
A Deviate Faerie Dragon
 
sirspikey's Avatar
Join Date: Feb 2007
Posts: 19
Show/Hide debuffbars for Bongos

Have done a small addon that control Bongos bars depending on certain scenarios, but have problem to detect debuffs on 'player' and make two bars show/hide tried to do a table (a{}) but i must have gone wrong somewher.

Any Ideas?
__________________________________________________
function BarStateCtrl_OnLoad()

this:RegisterEvent("PLAYER_TARGET_CHANGED");
this:RegisterEvent("PLAYER_REGEN_DISABLED");
this:RegisterEvent("PLAYER_AURAS_CHANGED");
this:RegisterEvent("UNIT_HEALTH");
this:RegisterEvent("CHAT_MSG_SPELL_PERIODIC_HOSTILEPLAYER_BUFFS");
this:RegisterEvent("CHAT_MSG_SPELL_PERIODIC_CREATURE_BUFFS");
this:RegisterEvent("CHAT_MSG_SPELL_AURA_GONE_OTHER");

AttBar = 1;
BuffBar = 2;
HealthBar = 3;
DebuffEnemyBar = 4;
CurePoisonBar = 5;
CureDiseaseBar = 6;
nrBuffs = 0;
Pstate = 0;
Dstate = 0;
P = 0;
D = 0;
c = 0;
bar = 0;
alpha =0;
a = {};
end


-----------------------------------------

function BarStateCtrl_event()

-------
if (event=="PLAYER_TARGET_CHANGED") or
(event=="PLAYER_REGEN_DISABLED") then
nrBuffs = 0; debuffenemybars(); attackbars();
end
-------
if (event=="UNIT_HEALTH") then
healthbars();
end
-------
if (event=="CHAT_MSG_SPELL_PERIODIC_HOSTILEPLAYER_BUFFS") or
(event=="CHAT_MSG_SPELL_PERIODIC_CREATURE_BUFFS") then
nrBuffs = nrBuffs+1; debuffenemybars();
end

if (event=="CHAT_MSG_SPELL_AURA_GONE_OTHER") and nrBuffs>0 then
nrBuffs = nrBuffs-1; debuffenemybars();
end
-------
if (event=="PLAYER_AURAS_CHANGED") then
curebars();
end

end

-----------------------------------------
function curebars()

P=0
D=0
a={}
c=0
local Buffs = ",";
local i=1;

name, x2, x3, x4, myDebuffType = UnitDebuff("player",i)

while ( name ~= nil ) do
Buffs = Buffs .. name .. ","

if ( myDebuffType == "Poison") then
a[i] = "Poison"; -- adds Poison to index 'i' if there is a Poisonbuff

elseif ( myDebuffType == "Disease") then
a[i] = "Disease"; -- adds Disease to index 'i' if there is a Diseasebuff
end

c=c+1
i=i+1
name, x2, x3, x4, myDebuffType = UnitDebuff("player",i)

end

-- checks if there is "poison" in the table --

for i=1,c do
if a[c] == "Poison" then P=P+1 else
P=0 end
end

-- checks if there is "disease" in the table --

for i=1,c do
if a[c] == "Disease" then D=D+1 else
D=0 end
end

if P==0 then
barstate(CurePoisonBar,0); -- hide poisonbar
end

if D==0 then
barstate(CureDiseaseBar,0); -- hide diseasebar
end

if P>=1 then
barstate(CurePoisonBar,1); -- show poisonbar
end

if D>=1 then
barstate(CureDiseaseBar,1); -- show Diseasebar
end

DEFAULT_CHAT_FRAME:AddMessage("P", P)
DEFAULT_CHAT_FRAME:AddMessage("D", D)


end
-----------------------------------------
-- Show/hides the bar depending on state --
function barstate(bar,alpha)

BActionBar.Get(bar):SetAlpha(alpha);

end
  Reply With Quote
04-23-07, 10:19 AM   #2
Shirik
Blasphemer!
Premium Member
WoWInterface Super Mod
AddOn Author - Click to view addons
Join Date: Mar 2007
Posts: 818
A few things....

function BarStateCtrl_OnLoad()

this:RegisterEvent("PLAYER_TARGET_CHANGED");
this:RegisterEvent("PLAYER_REGEN_DISABLED");
this:RegisterEvent("PLAYER_AURAS_CHANGED");
this:RegisterEvent("UNIT_HEALTH");
this:RegisterEvent("CHAT_MSG_SPELL_PERIODIC_HOSTILEPLAYER_BUFFS");
this:RegisterEvent("CHAT_MSG_SPELL_PERIODIC_CREATURE_BUFFS");
this:RegisterEvent("CHAT_MSG_SPELL_AURA_GONE_OTHER");



-- ...

function BarStateCtrl_event()
Do not expect "event" or "this" to come. This is a deprecated syntax and will be removed in the future. Use:

Code:
function BarStateCtrl_OnLoad(self)

self:RegisterEvent("PLAYER_TARGET_CHANGED");
self:RegisterEvent("PLAYER_REGEN_DISABLED");
self:RegisterEvent("PLAYER_AURAS_CHANGED");
self:RegisterEvent("UNIT_HEALTH");
self:RegisterEvent("CHAT_MSG_SPELL_PERIODIC_HOSTILEPLAYER_BUFFS");
self:RegisterEvent("CHAT_MSG_SPELL_PERIODIC_CREATURE_BUFFS");
self:RegisterEvent("CHAT_MSG_SPELL_AURA_GONE_OTHER");

-- ...

function BarStateCtrl_event(event)
Not only will your code be faster, but it's also not deprecated either. Note you will have to slightly change your XML as well to make this work.



(2)
P=0
D=0
a={}
c=0
name, x2, x3, x4, myDebuffType = UnitDebuff("player",i)
Please change this to

Code:
-- (Outside of function)
local P;
local D;
local a;
local c;

-- (Inside of function)
P=0
D=0
a={}
c=0
local name, x2, x3, x4, myDebuffType = UnitDebuff("player", i);
Pollution of the global namespace is bad and you run the risk of conflicting with other addons. If you're going to use them in several functions, make them at least file-local. Also, locals (like mentioned before) are faster to access.



Finally... your big problem:

-- checks if there is "poison" in the table --

for i=1,c do
if a[c] == "Poison" then P=P+1 else
P=0 end
end

-- checks if there is "disease" in the table --

for i=1,c do
if a[c] == "Disease" then D=D+1 else
D=0 end
end
This will reset to 0 in almost any case. You want

Code:
-- checks if there is "poison" in the table --

P = 0;
for i=1,c do
if a[c] == "Poison" then P=P+1 end
end

-- checks if there is "disease" in the table --
D=0;
for i=1,c do
if a[c] == "Disease" then D=D+1 end
end
__________________
たしかにひとつのじだいがおわるのお
ぼくはこのめでみたよ
だけどつぎがじぶんおばんだってことわ
しりたくなかったんだ
It's my turn next.

Shakespeare liked regexes too!
/(bb|[^b]{2})/
  Reply With Quote
04-23-07, 10:41 AM   #3
sirspikey
A Deviate Faerie Dragon
 
sirspikey's Avatar
Join Date: Feb 2007
Posts: 19
Thnx, that did it



-- (Outside of function)
local P;
local D;
local a;
local c;

-- (Inside of function)
P=0
D=0
a={}
c=0
local name, x2, x3, x4, myDebuffType = UnitDebuff("player", i);

When you say 'Outside the function' do you mean that they shouldn't be in any function at all?

regards
SirSpikey

Last edited by sirspikey : 04-23-07 at 10:44 AM.
  Reply With Quote
04-23-07, 11:47 AM   #4
Shirik
Blasphemer!
Premium Member
WoWInterface Super Mod
AddOn Author - Click to view addons
Join Date: Mar 2007
Posts: 818
Originally Posted by sirspikey
Thnx, that did it
When you say 'Outside the function' do you mean that they shouldn't be in any function at all?
Correct. That will make your variables local to your file, and not the specific function.

See http://www.wowwiki.com/Lua_variable_...ocal_Variables
__________________
たしかにひとつのじだいがおわるのお
ぼくはこのめでみたよ
だけどつぎがじぶんおばんだってことわ
しりたくなかったんだ
It's my turn next.

Shakespeare liked regexes too!
/(bb|[^b]{2})/
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » Show/Hide debuffbars for Bongos


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off