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