-- if the character is the wrong class, do not load the addon!
if select(2, UnitClass("player")) ~= "SHAMAN" then -- select() picks the 2nd argument returned by UnitClass() API. The 1st argument is always localized so avoid using that if you wish to have a mod that works on all game versions of WoW!
return -- Used in functions, in addon root it stops reading at this line, sort of speak.
local f = CreateFrame("Frame") -- hidden frame
f:RegisterEvent("UNIT_SPELLCAST_SUCCEEDED") -- register the spell cast succeeded event with the frame
-- register a scriptwhen the event occurs. Usually we would watch "event" argument and match it up to UNIT_SPELLCAST_SUCCEEDED but as we only monitor one event the function will only fire when that event occurs.
f:SetScript("OnEvent", function(self, event, unit, _, _, _, spellid) -- the parameters can be found on wowwiki or wowprogramming article for "UNIT_SPELLCAST_SUCCEEDED" event, also what each of them means and returns.
if unit == "player" and spellid == 421 then -- we only want to play the sound when the spell cast source is the player, and when it's Chain Lightning. I use spellid to match it as we again won't have cross locale problems.
PlaySoundFile("Interface\\AddOns\\TCL\\ChainLightning.mp3") -- 'nuff said
local addon = CreateFrame("Frame", "MyCoolAddonFrame")
addon.totaltime = 0
addon:SetScript("OnUpdate", function(self, elapsed)
self.totaltime = self.totaltime + elapsed -- adding the seconds since last "OnUpdate" ran, thus counting each call the total seconds since last time the function ran
if self.totaltime >= 5 then
print("This message will show up each 5 seconds.")
self.totaltime = 0
1x <string>:"ChainLightning:OnLoad":1: attempt to index global 'this' (a nil value)