-- this should be done in localization.lua so that you can easily localize it to German/French. FearEffectNames = { "Bellowing Roar", "Cowardly Flight", "Dreadful Fright", "Fear", "Howl of Terror", "Intimidating", "Intimidation", "Panic", "Psychic Scream", "Repulsive Gaze", "Terrify" }; -- retrieves a spell name from a string spell name, -- meaning it can get a spell name from "Spell(Blah 515)" and "Spell" function ExtractSpellNameRankFromString(stringSpellName) local index = string.find(stringSpellName, "%("); local spellName = stringSpellName; local rank = nil; if ( index ) then spellName = string.sub(stringSpellName, 1, index-1); local index2 = string.find(stringSpellName, "%)"); if ( not index2 ) then index2 = strlen(stringSpellName)+1; end rank = string.sub(stringSpellName, index+1, index2-1); end return spellName, rank; end -- converts a spellname into an id -- if spell name does not contain a rank specification, will use the highest level of spell function GetSpellIdFromSpellName(spellName, spellBook) if ( not spellBook ) then spellBook = "spell"; end local tmpName, tmpRank; local rank = nil; spellName, rank = ExtractSpellNameRankFromString(spellName); -- up to 200 spells are checked. This should be more than sufficient. for i = 1, 200 do tmpName, tmpRank = GetSpellName(i, spellBook); -- end of spellbook = terminate checking. if ( not tmpName ) then break; end if ( tmpName == spellName ) then if ( rank ) then if ( tmpRank ) then if ( rank == tmpRank ) then return i; end end else return i; end end end return nil; end -- -- Fancy callthrough for IsSpellReady. -- function IsSpellReadyByName(spellName, spellBook) return IsSpellReady(GetSpellIdFromSpellName(spellName, spellBook), spellBook); end -- -- Checks if a spell has a cooldown. -- function IsSpellReady(spellId, spellBook) if ( not spellBook ) then spellBook = "spell"; end local start, duration, enable = GetSpellCooldown(spellId, spellBook); if ( start + duration <= 0 ) and ( enable == 1 ) then return true; else return false; end end -- -- New shiny function that cast spell a if feared -- and does nothing if it can't cast spell a while feared or if spell a is not available. -- function HandleFear(antiFearSpell) local antiFearSpellId = antiFearSpell; if ( type(antiFearSpellId) ~= "number" ) then antiFearSpellId = GetSpellIdFromSpellName(antiFearSpell); end local hasFearEffect = false; if ( IsAnyDebuffsActive ) then hasFearEffect = IsAnyDebuffsActive(FearEffectNames); else for k, v in FearEffectNames do if ( IsBuffActive(v) ) then hasFearEffect = true; break; end end end local spellId = nil; if ( hasFearEffect ) then spellId = antiFearSpellId; end if ( spellId ) then if ( not IsSpellReady(spellId) ) then return false; end CastSpell(spellId, "spell"); return true; else return false; end end -- -- Mimics example code -- function ExampleOneHandleFear() local antiFearSpell = "Will of the Forsaken(Racial)"; return HandleFear(antiFearSpell); end -- -- Mimics example code but uses highest rank of Shadowburn -- function ExampleTwoHandleFear() local antiFearSpell = "Will of the Forsaken"; return HandleFear(antiFearSpell); end -- -- Mimics example code, uses highest rank of Shadowburn and caches the spell id -- (dunno if retrieving spell id takes much time, but is possible). -- function ExampleThreeHandleFear() local antiFearSpell = "Will of the Forsaken"; local nonFearSpell = "Shadowburn"; if ( ExampleThreeHandleFear_aID ) then local name = GetSpellName(ExampleThreeHandleFear_aID, "spell"); if ( name ~= antiFearSpell ) then ExampleThreeHandleFear_aID = nil; end end if ( not ExampleThreeHandleFear_aID ) then ExampleThreeHandleFear_aID = GetSpellIdFromSpellName(antiFearSpell); end if ( ExampleThreeHandleFear_aID ) then return HandleFear(ExampleThreeHandleFear_aID); else return false; end end