• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

[JASS] need help with stoping a spell

Status
Not open for further replies.
Level 3
Joined
Sep 14, 2007
Messages
43
i want to make a spell where the hero cant move and if he does or get stunned the spell stops (like most channel spells).
i know how to stop the unit from casting a spell, but how do i tell it when to stop the spell?

there is a trigger event that launch the trigger when a unit stops to channel an ability, the problem is that if the unit stops casting a spell once it will launch the trigger all the time.
 
Level 13
Joined
Nov 22, 2006
Messages
1,260
If this is in the JASS section, then I suppose I may use a little JASS :p

Base the spell you want of a channeling spell (starfall, tranquility.....). You will have to create a local trigger that will have the event when a unit stops the effect of an ability. In triggered channeling spells you always use a timer, right? So attach it to the trigger and then get it like this:

JASS:
function MySpell_Stop_Conditions takes nothing returns boolean
    return GetSpellAbilityId() == 'A000' or GetTriggerUnit() == null
endfunction

function MySpell_Stop_Actions takes nothing returns nothing
    local trigger trig = GetTriggeringTrigger()
    local timer t = GetHandleTimer(trig, "t")
    // ....do whatever you must kill/remove/destroy/stop/change.......
    call FlushHandleLocals(t) // most likely
    call PauseTimer(t) // to avoid a bug
    call DestroyTimer(t)
    call FlushHandleLocals(trig)
    call DestroyTrigger(t)
    set trig = null
    set t = null
    // .....some more nullifications if necessary.....
endfunction

//===========================================

function MySpell_Conditions takes nothing returns boolean
    return GetSpellAbilityId() == 'A000'
endfunction

function MySpell_Actions takes nothing returns nothing
    local timer t = CreateTimer()
    local unit c = GetTriggerUnit()
    local trigger trig = CreateTrigger()
    local trigggeraction ta = TriggerAddAction(trig, function MySpell_Stop_Actions)
    local triggercondition tc = TriggerAddCondition(trig, Condition(function MySpell_Stop_Conditions)
    // ....some more locals......
    call TriggerRegisterPlayerUnitEvent(trig, GetOwningPlayer(c), EVENT_PLAYER_UNIT_SPELL_ENDCAST, null)
    call TriggerRegisterTimerEvent(trig, <spell duration>, false) // this is when the spell finishes, meaning it hasn't been stopped
    // ....attach stuff to the timer......
    call SetHandleHandle(trig, "t", t) //!
    call TimerStart(t, 1, true, function SomeFunctionThatIsNotHere)
    set t = null
    set c = null
    set trig = null
    set ta = null
    set tc = null
    // .....nullify the rest of the handles.......
endfunction


And you'll probably want to destroy those triggeraction and triggercondition to avoid leaks, you can do that by attaching them to the trigger and then using TriggerRemoveAction() and TriggerRemoveCondition().
 
Level 3
Joined
Sep 14, 2007
Messages
43
doesnt EVENT_PLAYER_UNIT_SPELL_ENDCAST launches the trigger nonstop after the unit stops casting a spell once?
 
Level 3
Joined
Sep 14, 2007
Messages
43
Can someone explain to me or even better give me a link to a tutorial about handler and game cache and how to use them?
 
Level 3
Joined
Sep 14, 2007
Messages
43
Ok that doesnt really cover what i asked for.
What is game cache var used for?

edit:
function H2I takes handle h returns integer
return h
return 0
endfunction

i also dont understand this function, wouldnt it just return h and skip the other return?
 
Status
Not open for further replies.
Top