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

Best way to do this?

Status
Not open for further replies.
Level 12
Joined
Dec 2, 2016
Messages
733
I have an ability that the Hero creates a gold coin. When this gold coin is picked up it sets that units HP to 15%.

The cooldown is one minute, but I need an effective way to remove the created coin/item after 60 seconds has passed. I was originally going to us a unit expiry timer but that same idea doesn't seem to work for items. There's multiple players that can use this spell in the game. How would I best go about creating this item and having it expire after 60 seconds?
 
Level 39
Joined
Feb 27, 2007
Messages
5,028
This is an instance where using Waits is actually more practicable than a timer and the accuracy isn't super important. All you need is to create 1 item variable in the variable editor and then use a local item via custom script to store during the wait; in the below code example that variable is called "TEMP_ITEM". To use this in your map with a variable with a different name, you will need to change the bit of two of the custom script line that says "udg_TEMP_ITEM" to "udg_" + TheNameOfTheVariable, else you will get errors.
  • Events
    • -------- your event that spawns coins --------
  • Conditions
  • Actions
    • Custom script: local item Coin = null
    • -------- THE ABOVE LINE MUST BE FIRST IN THE TRIGGER --------
    • -------- Do all your normal stuff here --------
    • Set TEMP_ITEM = (last created item) //or however you would refer to the item
    • Custom script: set Coin = udg_TEMP_ITEM
    • Wait - 60.00 game-time seconds
    • Custom script: set udg_TEMP_ITEM = Coin
    • If (all conditions) then do (actions) else (actions)
      • If - Conditions
        • (TEMP_ITEM) not equal to No Item
      • Then - Actions
        • Item - Destroy TEMP_ITEM //or remove it if you don't want to play its death animation
      • Else - Actions
        • -------- If the trigger gets here the item was used during the 60s wait, so you do nothing --------
 
Level 6
Joined
Aug 28, 2015
Messages
213
You could even shadow udg_TemItem as local variabe and use it in gui the trigger will then preoritise the local
That means...
Do the trigger from above but the first line will be
Set local item udg_TempItem = null
And leave out the other custom scripts.
 
Level 12
Joined
Dec 2, 2016
Messages
733
So you use a local variable to store the coin so that the trigger running again can't overwrite the current coin?

Wouldn't the local coin = null at the start of the trigger if ran again before the 60 seconds is up overwrite the current coin variable contents and make it null?
 
Level 39
Joined
Feb 27, 2007
Messages
5,028
Yes thats correct. The first line of the trigger suggested above makes the global variable act as a local with the same name. So within the scope of the trigger actions it is local, thus each time it only nulls the local instance instead. I believe it's actually a bug but shadowing a variable like that is a neat trick that I totally forgot about!
 
Status
Not open for further replies.
Top