azerothcore / mod-eluna

Eluna Lua Engine © for WoW Emulators
https://elunaluaengine.github.io/
GNU General Public License v3.0
96 stars 126 forks source link

add unit method SetImmuneTo #167

Closed 55Honey closed 6 months ago

55Honey commented 7 months ago

Adds a new method to add and remove mechanic immunities.

Tested with:

local function ImmunityOff(eventid, delay, repeats, creature)
    creature:SetImmuneTo(26, false)
    creature:SendUnitSay("I am interruptable now.", 0)
end

local function Cast(eventid, delay, repeats, creature)
    creature:CastSpell(creature, 57775, false)
end

local function EnterCombat(event, creature, target)
    creature:SetImmuneTo(26, true)
    creature:SendUnitSay("You can not interrupt me.", 0)

    creature:RegisterEvent(Cast, 5500, 0)
    creature:RegisterEvent(ImmunityOff, 15000, 1)
end

local function LeaveCombat(event, creature)
    creature:RemoveEvents()
end

RegisterCreatureEvent(113, 1, EnterCombat)
RegisterCreatureEvent(113, 2, LeaveCombat) -- OnLeaveCombat
RegisterCreatureEvent(113, 4, LeaveCombat) -- OnDied

image