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

Cooldown problem

Status
Not open for further replies.
Level 6
Joined
Feb 27, 2008
Messages
222
Ok, so i'm trying to create a swap position spell in GUI. Everything works ok with one problem - the cooldown of the spell is not used, meaning you can constantly use it.

I know this is related to the fact that the unit is moved right after casting the spell and the animation isn't finished or that sort of thing. So i was wondering how can i make such a spell where the cooldown will be used?

  • Events
    • Unit - A unit Starts the effect of an ability
  • Conditions
    • (Ability being cast) Equal to Swap [Q]
  • Actions
    • Set Loc[1] = (Position of (Target unit of ability being cast))
    • Unit - Create 1 dum for (Owner of (Target unit of ability being cast)) at Loc[1] facing Default building facing degrees
    • Set Loc[1] = (Position of (Casting unit))
    • Unit - Move (Target unit of ability being cast) instantly to Loc[1]
    • Set Loc[1] = (Position of (Last created unit))
    • Unit - Move (Casting unit) instantly to Loc[1]
    • Custom script: call RemoveLocation(udg_Loc[1])

What i used is above.
 
Level 8
Joined
Aug 21, 2009
Messages
333
I've had this problem before.

You just need to put a wait command in before you move the unit to allow the spell to finish casting.

I fixed a few other things too. ie. fixed leaks and there was no need for the dummy unit.

(This spell is not completely multi-instanceable, but because the wait time is very short, it shouldn't matter)

  • Events
    • Unit - A unit Starts the effect of an ability
  • Conditions
    • (Ability being cast) Equal to Swap [Q]
  • Actions
    • Set Swap_Caster = (Casting unit)
    • Set Swapped_Unit = (Target unit of ability being cast)
    • Set Loc[1] = (Position of Swap_Caster)
    • Set Loc[2] = (Position of Swapped_Unit)
    • Wait for 0.10 seconds
    • Unit - Move (Swapped_Unit) instantly to Loc[1]
    • Unit - Move (Swap_Caster) instantly to Loc[2]
    • Unit - Move (Swapped_Unit) instantly to Loc[1]
    • Custom script: call RemoveLocation(udg_Loc[1])
    • Custom script: call RemoveLocation(udg_Loc[2])
PS: the swapped unit is moved twice because the first time it is moved it will be offset by the casting unit's collision size. the second time it is moved it will be in the correct place.
 
Level 12
Joined
Jul 27, 2008
Messages
1,181
I've had this problem before.

You just need to put a wait command in before you move the unit to allow the spell to finish casting.

I fixed a few other things too. ie. fixed leaks and there was no need for the dummy unit.

(This spell is not completely multi-instanceable, but because the wait time is very short, it shouldn't matter)

  • Events
    • Unit - A unit Starts the effect of an ability
  • Conditions
    • (Ability being cast) Equal to Swap [Q]
  • Actions
    • Set Swap_Caster = (Casting unit)
    • Set Swapped_Unit = (Target unit of ability being cast)
    • Set Loc[1] = (Position of Swap_Caster)
    • Set Loc[2] = (Position of Swapped_Unit)
    • Wait for 0.10 seconds
    • Unit - Move (Swapped_Unit) instantly to Loc[1]
    • Unit - Move (Swap_Caster) instantly to Loc[2]
    • Unit - Move (Swapped_Unit) instantly to Loc[1]
    • Custom script: call RemoveLocation(udg_Loc[1])
    • Custom script: call RemoveLocation(udg_Loc[2])
PS: the swapped unit is moved twice because the first time it is moved it will be offset by the casting unit's collision size. the second time it is moved it will be in the correct place.

Wait = bad, just try unit finishes channeling (with channel :xxd:).
 
Level 8
Joined
Aug 21, 2009
Messages
333
wait is usually bad because it allows important variables to be re-written before the action.

ie. in this case another unit could cast swap before the wait is up, and the first instance of the swap spell wouldn't do anything.

However, the wait time is short enough that it shouldn't matter. Also, I doubt he will be giving the swap spell to more than one unit.
 
Status
Not open for further replies.
Top