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

Item Timers

Status
Not open for further replies.
Level 12
Joined
Feb 5, 2018
Messages
521
Hello all,

Im trying to make a timer for items that are created on the map so they would expire instead of staying on the ground indefinetly.

Sample: A unit dies
Create Item(X)
Start a Timer that expires in X seconds
Timer expires
Remove Item(X)

Im looking a simple way to do it like maybe using loop integer A?
Dont know JASS or vJASS so needs to be done in GUI
Thanks in advance! :)
 
No need to make loop or anything else. As you stated above, first create a trigger with this event:
Unit - Generic Unit Event 》 A Unit Dies
Then, make your condition that what unit dies:
Unit Comparison 》 (Triggering unit) equal to (YourUnit)
Then, make four actions like these:
Item - Create Item X
Set (ItemY) = (Last Created Item) 》 ItemY is an item variable
Countdown Timer - Start Timer that will expire in X seconds
Set (TimerZ) = (last created/started timer) 》 TimerZ is a timer variable

After that, create a new trigger and make this event:
Timer - TimerZ Expires
Then, use the item removing action:
Item - Remove (ItemY)
 
^And what happens when two units die shortly after one another? The system is bugged.

Your trigger should look more like

Events
> Unit dies

Actions
> Custom script: local item udg_TempItem
> Create fitting item
> Set udg_TempItem to last created item
> Wait <Number of Seconds>
> Remove udg_TempItem

This uses a "shadow variable" trick where GUI uses the local instead of the global.
 
^And what happens when two units die shortly after one another? The system is bugged.

Your trigger should look more like

Events
> Unit dies

Actions
> Custom script: local item udg_TempItem
> Create fitting item
> Set udg_TempItem to last created item
> Wait <Number of Seconds>
> Remove udg_TempItem

This uses a "shadow variable" trick where GUI uses the local instead of the global.
Yeah, I didn't pay attention to more units. Though I haven't learned local variables yet.
 
Level 12
Joined
Feb 5, 2018
Messages
521
Yeah I had the problem with multiple units dying at once or dying shortly after. I´m gonna try storing them locally like HappyTauren said and reply later if it worked :) thanks. Also I thought (Waits) leak
 
Level 12
Joined
Feb 5, 2018
Messages
521
Don't post it as an image. Just right click it in the trigger editor, copy as text, and post here in tags like this:
  • Events
  • Some Event
  • Conditions
  • Stuff
  • Action
  • Some Actions
  • A Creep Dies
    • Events
      • Unit - A unit owned by Neutral Hostile Dies
    • Conditions
    • Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Level of (Triggering unit)) Less than or equal to 2
        • Then - Actions
          • Set Droprate[1] = (Random integer number between 1 and 100)
          • Set Droprate[2] = (Random integer number between 1 and 100)
          • Set Droprate[3] = (Random integer number between 1 and 100)
          • Set Droprate[4] = (Random integer number between 1 and 100)
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • Droprate[1] Less than or equal to 25
            • Then - Actions
              • Set ItemDropPosition[1] = (Position of (Triggering unit))
              • Custom script: local item (udg_TempItem)
              • Item - Create Wolf Pelt at ItemDropPosition[1]
              • Set TempItem = (Last created item)
              • Item - Set the custom value of (Last created item) to 11
              • Game - Display to (All players) for 8.00 seconds the text: |c00FFFC01GAME:|r W...
              • Set Droprate[1] = 0
              • Custom script: call RemoveLocation (udg_ItemDropPosition[1])
              • Wait 15.00 seconds
              • Item - Remove TempItem
            • Else - Actions
              • Skip remaining actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • Droprate[2] Less than or equal to 15
            • Then - Actions
              • Set ItemDropPosition[2] = (Position of (Triggering unit))
              • Item - Create Sword at ItemDropPosition[2]
              • Item - Set the custom value of (Last created item) to 7
              • Game - Display to (All players) for 8.00 seconds the text: |c00FFFC01GAME:|r S...
              • Set Droprate[2] = 0
              • Custom script: call RemoveLocation (udg_ItemDropPosition[2])
            • Else - Actions
              • Do nothing
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • Droprate[3] Less than or equal to 20
            • Then - Actions
              • Set ItemDropPosition[3] = (Position of (Triggering unit))
              • Item - Create Staff at ItemDropPosition[3]
              • Item - Set the custom value of (Last created item) to 3
              • Game - Display to (All players) for 8.00 seconds the text: |c00FFFC01GAME:|r S...
              • Set Droprate[3] = 0
              • Custom script: call RemoveLocation (udg_ItemDropPosition[3])
            • Else - Actions
              • Do nothing
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • Droprate[4] Less than or equal to 10
            • Then - Actions
              • Set ItemDropPosition[4] = (Position of (Triggering unit))
              • Item - Create Bronze Ring at ItemDropPosition[4]
              • Item - Set the custom value of (Last created item) to 4
              • Game - Display to (All players) for 8.00 seconds the text: |c00FFFC01GAME:|r B...
              • Set Droprate[4] = 0
              • Custom script: call RemoveLocation (udg_ItemDropPosition[4])
            • Else - Actions
              • Do nothing
        • Else - Actions
 
Level 12
Joined
Feb 5, 2018
Messages
521
Where did you move it? Post the trigger.
  • A Creep Dies Copy
    • Events
      • Unit - A unit owned by Neutral Hostile Dies
    • Conditions
    • Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Level of (Triggering unit)) Less than or equal to 2
        • Then - Actions
          • Set Droprate[1] = (Random integer number between 1 and 100)
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • Droprate[1] Less than or equal to 25
            • Then - Actions
              • Custom script: local item (udg_TempItem)
              • Set ItemDropPosition[1] = (Position of (Triggering unit))
              • Item - Create Wolf Pelt at ItemDropPosition[1]
              • Item - Set the custom value of (Last created item) to 11
              • Set TempItem = (Last created item)
              • Game - Display to (All players) for 8.00 seconds the text: |c00FFFC01GAME:|r W...
              • Set Droprate[1] = 0
              • Custom script: call RemoveLocation (udg_ItemDropPosition[1])
            • Else - Actions
              • Skip remaining actions
        • Else - Actions
          • Do nothing
 
  • A Creep Dies Copy
    • Events
      • Unit - A unit owned by Neutral Hostile Dies
    • Conditions
    • Actions
      • Custom script: local item udg_TempItem
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Level of (Triggering unit)) Less than or equal to 2
        • Then - Actions
          • Set Droprate[1] = (Random integer number between 1 and 100)
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • Droprate[1] Less than or equal to 25
            • Then - Actions
              • Set ItemDropPosition[1] = (Position of (Triggering unit))
              • Item - Create Wolf Pelt at ItemDropPosition[1]
              • Item - Set the custom value of (Last created item) to 11
              • Set TempItem = (Last created item)
              • Game - Display to (All players) for 8.00 seconds the text: |c00FFFC01GAME:|r W...
              • Set Droprate[1] = 0
              • Custom script: call RemoveLocation (udg_ItemDropPosition[1])
            • Else - Actions
              • Skip remaining actions
        • Else - Actions
          • Do nothing
there
 
Level 12
Joined
Feb 5, 2018
Messages
521
  • A Creep Dies Copy
    • Events
      • Unit - A unit owned by Neutral Hostile Dies
    • Conditions
    • Actions
      • Custom script: local item (udg_TempItem)
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Level of (Triggering unit)) Less than or equal to 2
        • Then - Actions
          • Set Droprate[1] = (Random integer number between 1 and 100)
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • Droprate[1] Less than or equal to 25
            • Then - Actions
              • Set ItemDropPosition[1] = (Position of (Triggering unit))
              • Item - Create Wolf Pelt at ItemDropPosition[1]
              • Item - Set the custom value of (Last created item) to 11
              • Set TempItem = (Last created item)
              • Game - Display to (All players) for 8.00 seconds the text: |c00FFFC01GAME:|r W...
              • Set Droprate[1] = 0
              • Custom script: call RemoveLocation (udg_ItemDropPosition[1])
            • Else - Actions
              • Skip remaining actions
        • Else - Actions
          • Do nothing
So if I do it like this I get 4 errors (instead of 1) now it has 3 lines of expected "endif" and Expected a reserved type or handle type :D this is impossible.
 

Dr Super Good

Spell Reviewer
Level 63
Joined
Jan 18, 2005
Messages
27,191
One approach would be a set of items with expiration ticks. One array for the items, another for how many ticks left before they expire and a separate variable to track number of items in the system.

When an item is added, place it at the position of the current item count and increment current item count by 1. If current item count was 0 then start the periodic trigger.

The periodic trigger every second picks every item in the array and decrement the ticks remaining for that item by 1. If ticks remaining is equal to 0 then the item is removed (expired) and the entry deleted and current iterator position decremented by 1.

Entry deletion works by decrementing the item count by 1 and then swapping the values of the end of list with the item being removed. If current item count is then 0, stop the periodic trigger.

When an item is picked up, or made permanent else wise, then it is deleted from the list. One can perform a linear search (check each index of the array up until current item count) to find which index the item is at.

Although the polling and linear search nature is not efficient, it should be more than suitable for dozens of items at any given time. Especially if the decay time is kept short, eg 60 seconds, it should be impossible to reach item quantities that will cause performance concerns.
 
Status
Not open for further replies.
Top