• 🏆 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!

[Wurst] How to store a players only hero in a variable?

Status
Not open for further replies.
Level 7
Joined
Sep 16, 2016
Messages
185
Hello,

Having some problems with my channel ability.

Code:
package main

import ClosureEvents
import OrderIds
import Jump

unit caster

init

    // caster = GetTriggerUnit() <-- Tried this both with and without, still same result

    EventListener.add(EVENT_PLAYER_UNIT_SPELL_CHANNEL) ->
        if EventData.getSpellAbilityId() == 'A000'
            print("Channel ability casted. ")
            UnitRemoveAbility(caster, 'A001') // <-- This works as intended


    EventListener.add(EVENT_PLAYER_UNIT_SPELL_CHANNEL) ->
        if EventData.getSpellAbilityId() == 'A000'
            if caster.getCurrentOrder() != Orders.channel or not caster.isAlive()
                print("Channel ability cancelled. ") // <-- This still plays on initial cast, I do not want that only on cancel channel or when it finishes

Basically, on channel cast the print "Channel ability casted" works, just as intended.

But for some reason, the other print also plays on initial, but its only intended to show on cancel/finished the channel ability. I tried some stuff like UnitRemoveAbility, but it does not work. So my theory is that "caster" is not correct. What is a good way to store a players only hero in a variable? Perhaps then it will work.
 
Level 7
Joined
Sep 16, 2016
Messages
185
Woah, now it works! Although how come

Code:
if caster.getCurrentOrder() != Orders.channel or not caster.isAlive()

does not work?

Code:
package main

import ClosureEvents
import OrderIds
import Jump

unit caster

init

    UnitAddAbility(caster, JUMP_ID)

    EventListener.add(EVENT_PLAYER_UNIT_SPELL_CHANNEL) ->
        caster = GetTriggerUnit()
        if EventData.getSpellAbilityId() == 'A000'
            print("Channel ability casted. ")
            UnitRemoveAbility(caster, 'A001') //this works now!!!


    EventListener.add(EVENT_PLAYER_UNIT_SPELL_CHANNEL) ->
        caster = GetTriggerUnit()
        if EventData.getSpellAbilityId() == 'A000'
            if caster.getCurrentOrder() != Orders.channel or not caster.isAlive()
                print("Channel ability cancelled. ") //this does not play

edit:

EVENT_PLAYER_UNIT_SPELL_FINISH

Code works if I do this, but only if finish, if I interrupt/cancel, it wont. :( So this approach wont work I think

edit2:

EVENT_PLAYER_UNIT_SPELL_ENDCAST This seems to do what I want! haha
 
Last edited:
Status
Not open for further replies.
Top