Jump to content

How to disabled magic on map?


bookkc

Recommended Posts

so i need if player change map, the spell is disabled, and player can not use it on map. I know how to check Kalimdor Or Azeroth map, but i can not know how to disable spell?

function Mchange(event, player, spell, skipCheck)

end
RegisterPlayerEvent(28, Mchange)

i need to disable 10912 spell

Link to comment
Share on other sites

i try this... 

Look, or i need to remove aura 10912 from creature (its controll NPC) i remove like this

function Mchange(event, player, spell, skipCheck)
    local Target = spell:GetTarget()

    
    if spell:GetEntry() == 10912 then
    local function Dummy(_,_,_,plr)
    Target:RemoveAura(10912)
    end
    player:RegisterEvent(Dummy, math.random(1000, 1000), 1) 
    end

end
RegisterPlayerEvent(5, Mchange)
2018-04-24 14:37:29 ERROR Eluna: lua_scripts/date.lua:8: calling 'RemoveAura' on bad self (Creature expected, got pointer to nonexisting (invalidated) object (userdata). Check your code.)

 

Link to comment
Share on other sites

There is a potential problem with your code.
Even though you would be able to run it and it would probably work, a safety measure is raising an error.

The problem with the code is that you try to use "Target" after a timed event.
If the "Target" is a creature, the creature could have been despawned.
If the "Target" is a player, he could have logged out.
Using a nonexisting object would normally result in a crash or worse.

There are different solutions to your problem. Often the best one depends on what exactly you want to happen.
For example in your current code you register the timed event for the player. What this means is that the timed event WILL NOT execute if the player logs out and as a result the aura is never removed from the target.

Here is one solution I assume you attempted to do, it will add the timed event to the target and remove the aura from the target after the timer runs out.
This solution uses the Target to keep track of the timed event, so you can access it through the parameters in the function that is called and remove the aura through that.
 

function Mchange(event, player, spell, skipCheck)
    if spell:GetEntry() == 10912 then
        local Target = spell:GetTarget()
        if Target then
            local function Dummy(_,_,_,target)
                target:RemoveAura(10912)
            end
            Target:RegisterEvent(Dummy, math.random(1000, 1000), 1) 
        end
    end
end
RegisterPlayerEvent(5, Mchange)


Here is another, but it follows your code more specifically in the way that it will not remove the aura if the caster of the spell logged out.
This solution uses the guid value to search for the target when the timed event triggers. This way you can check if the target exists and remove the aura if he does.
 

function Mchange(event, player, spell, skipCheck)
    if spell:GetEntry() == 10912 then
        local Target = spell:GetTarget()
        if Target then
            local guid = Target:GetGUID()
            local function Dummy(_,_,_,plr)
                local target = plr:GetMap():GetWorldObject(guid)
                if target then
                    target:RemoveAura(10912)
                end
            end
            player:RegisterEvent(Dummy, math.random(1000, 1000), 1) 
        end
    end
end
RegisterPlayerEvent(5, Mchange)

 

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue. Privacy Policy Terms of Use