Are you also hiding the indicator on startup?
|
No. I need to do that?
I have no experience in Lua, so I only following the tutorial and here is nothing about hiding it on startup.
But why sign exists on startup?
CombatState is 1 by default? Or default value is sth like "CombatState = nil" and it must be set to zero manually?
If you can help me and show how to hide it on startup, i'll be thankful to you.
Full listing:
Warning: Spoiler
Lua Code:
testplugin = {}
testplugin.name = "testplugin"
function testplugin:Initialize()
self.inCombat = IsUnitInCombat("player")
EVENT_MANAGER:RegisterForEvent(self.name, EVENT_PLAYER_COMBAT_STATE, self.OnPlayerCombatState)
end
-- Then we create an event handler function which will be called when the "addon loaded" event
-- occurs. We'll use this to initialize our addon after all of its resources are fully loaded.
function testplugin.OnAddOnLoaded(event, addonName)
-- The event fires each time *any* addon loads - but we only care about when our own addon loads.
if addonName == testplugin.name then
testplugin:Initialize()
end
end
function testplugin.OnPlayerCombatState(event, inCombat)
-- The ~= operator is "not equal to" in Lua.
if inCombat ~= testplugin.inCombat then
-- The player's state has changed. Update the stored state...
testplugin.inCombat = inCombat
-- ...and then update the control.
testpluginIndicator:SetHidden(not inCombat)
d(inCombat)
end
end
-- Finally, we'll register our event handler function to be called when the proper event occurs.
EVENT_MANAGER:RegisterForEvent(testplugin.name, EVENT_ADD_ON_LOADED, testplugin.OnAddOnLoaded)