• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

[vJASS] Cancel Casting Ability

Status
Not open for further replies.
Level 17
Joined
Feb 11, 2011
Messages
1,860
Hi,

I am having trouble with cancelling an ability from being cast. I want it to not be cast when the unit has a specific buff. My code is like this:

JASS:
private function EvaluateCaster takes nothing returns boolean
    if IsUnitInGroup(GetTriggerUnit(), units) and GetSpellAbilityId() == SPELL_ID then
        call IssueImmediateOrder(GetTriggerUnit(), "stop")
        call DisplayTextToPlayer(GetTriggerPlayer(), 0, 0, "|cffffcc00Hero already has the buff!|r")
        return false
    else
        return true
    endif
endfunction

private function onInit takes nothing returns nothing
    local trigger t = CreateTrigger()
    
    // Register cast to detect if caster already has buff.
    set t = CreateTrigger()
    call TriggerRegisterAnyUnitEventBJ(t, EVENT_PLAYER_UNIT_SPELL_CAST)
    call TriggerAddCondition(t, Condition(function EvaluateCaster))
    
    // Register spell cast.
    call RegisterSpellEffectEvent(SPELL_ID, function SpellActions)
    
    set t = null
endfunction

What happens: It displays the message "Hero already has the buff!", but the function SpellActions still gets executed!

What's wrong? Thanks,

Mr_Bean
 
Level 17
Joined
Apr 27, 2008
Messages
2,455
Pause forbid the issued order on event, and then you can give an other order.
However it depends the type of issued order and the type of order you want to give (point, immediate, target), i mean most of times just give the order stop on order event will work.
 
Level 17
Joined
Apr 27, 2008
Messages
2,455
Well, you can try, but i think that the spell order would just be re-issued without the order stop.
Also instead of stop you could use the hidden order "851973", which is the "stun" order.
I'm tired to say why this one is better, use the search :p
 
Status
Not open for further replies.
Top