- 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:
What happens: It displays the message "Hero already has the buff!", but the function
What's wrong? Thanks,
Mr_Bean
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