[GUI] Timed Item Remover v1.0

===================
Timed Item Remover v1.0
===================
This system periodically checks for the time remaining of an item that has been registered into the system by creating a new instance when that item is registered. When time is up, the item will be killed and eventually removed from the game. Each item can have different duration of existing, it's configurable. If the item is acquired, it will stay in inventory and the timer will be reset. This system can be useful, especially in RPG maps. This system also supports tomes and runes as it can properly remove them. However, it doesn't support built-in item tables.

Important Notes:
  1. Don't forget to set TIR_DebugMode = False from TimedItemRemover Init Trigger if you're going to use this in your map. I intentionally left it as "True" in the testmap for testing purposes.
  2. Due to the fact that tomes and runes have a bug where they will not be properly removed after usage, I'd recommend copy "Item Drop" trigger into your map as well. Because of how the bug behaves, Unit - A unit Loses an item event will detect when a tome or a rune is used. This way, the trigger will register the dropped invisible tome and rune, then remove them properly. Although not immediately, it gets the job done.
  3. Due to reason on Note #2, I would also recommend to use these systems in conjunction to mine, although they are optional:

How to use:
  • How to use
    • Events
    • Conditions
    • Actions
      • -------- ------------------------------------------------------------------------ --------
      • -------- How to use the system --------
      • -------- ------------------------------------------------------------------------ --------
      • -------- This will be the item you want to register --------
      • Set TIR_Item = (Item being manipulated)
      • -------- ------------------------------------------------------------------------ --------
      • -------- This will be the duration before the item gets killed --------
      • Set TIR_Duration = 5.00
      • -------- ------------------------------------------------------------------------ --------
      • -------- This will register previous variables into the system --------
      • Trigger - Run TIR_Register (ignoring conditions)
      • -------- ------------------------------------------------------------------------ --------
In case you're still clueless on how to use the system, please take a look at some examples from the demo triggers.

Demo:
  • Item Drop
    • Events
      • Unit - A unit Loses an item
    • Conditions
    • Actions
      • -------- - --------
      • Set TIR_Item = (Item being manipulated)
      • Set TIR_Duration = 5.00
      • Trigger - Run TIR_Register (ignoring conditions)
      • -------- - --------
  • Loot
    • Events
      • Unit - A unit Dies
    • Conditions
      • (Owner of (Triggering unit)) Equal to Player 2 (Blue)
      • (Unit-type of (Triggering unit)) Not equal to Peon
    • Actions
      • Set TIR_TempLoc = (Position of (Triggering unit))
      • -------- - --------
      • Item - Create (Random level 3 item-type) at TIR_TempLoc
      • Set TIR_Item = (Last created item)
      • Set TIR_Duration = -1.50
      • Trigger - Run TIR_Register (ignoring conditions)
      • -------- - --------
      • Custom script: call RemoveLocation(udg_TIR_TempLoc)
  • TomeRune Specific Loot
    • Events
      • Unit - A unit Dies
    • Conditions
      • (Owner of (Triggering unit)) Equal to Player 2 (Blue)
      • (Unit-type of (Triggering unit)) Equal to Peon
    • Actions
      • Set TIR_TempLoc = (Position of (Triggering unit))
      • -------- - --------
      • If ((Random integer number between 1 and 2) Equal to 1) then do (Item - Create Tome of Power at TIR_TempLoc) else do (Item - Create Rune of Dispel Magic at TIR_TempLoc)
      • Set TIR_Item = (Last created item)
      • Set TIR_Duration = 10.00
      • Trigger - Run TIR_Register (ignoring conditions)
      • -------- - --------
      • Custom script: call RemoveLocation(udg_TIR_TempLoc)
  • Custom Created Item
    • Events
      • Player - Player 1 (Red) types a chat message containing -i as An exact match
    • Conditions
    • Actions
      • Set TIR_TempLoc = (Center of (Playable map area))
      • -------- - --------
      • Item - Create (Random level 1 item-type) at TIR_TempLoc
      • Set TIR_Item = (Last created item)
      • Set TIR_Duration = 5.00
      • Trigger - Run TIR_Register (ignoring conditions)
      • -------- - --------
      • Custom script: call RemoveLocation(udg_TIR_TempLoc)
  • Mask of Death
    • Events
      • Player - Player 1 (Red) types a chat message containing -register mod as An exact match
    • Conditions
    • Actions
      • -------- - --------
      • Set TIR_Item = Mask of Death 0035 <gen>
      • Set TIR_Duration = 5.00
      • Trigger - Run TIR_Register (ignoring conditions)
      • -------- - --------
      • Trigger - Turn off (This trigger)

How to Import:
- Make sure your World Editor has "Automatically Create Unknown Variable" enabled. You can find it in File => Preferences
- Copy all the triggers in "Timed Item Remover" folder
- Make sure the variables are assigned properly
- Enjoy!

Triggers:
  • TimedItemRemover Init
    • Events
      • Map initialization
    • Conditions
    • Actions
      • -------- ------------------------------------------------------------------------------------------------------------------ --------
      • -------- Configuration --------
      • -------- I would advise not to change any of this unless you know what you're doing --------
      • -------- ------------------------------------------------------------------------------------------------------------------ --------
      • -------- The interval value used by the system to update counter periodically --------
      • Set TIR_Interval = 0.50
      • -------- ------------------------------------------------------------------------------------------------------------------ --------
      • -------- This value will determine the time required for the items to be able --------
      • -------- to show their dead animation first before they get removed --------
      • Set TIR_Timeout = 1.50
      • -------- ------------------------------------------------------------------------------------------------------------------ --------
      • -------- The trigger used to register an instance --------
      • Set TIR_Register = TimedItemRemover <gen>
      • -------- ------------------------------------------------------------------------------------------------------------------ --------
      • -------- The trigger used to loop through every instance --------
      • Set TIR_Loop = TimedItemRemover Loop <gen>
      • -------- ------------------------------------------------------------------------------------------------------------------ --------
      • -------- - --------
      • Trigger - Add to TIR_Loop the event (Time - Every TIR_Interval seconds of game time)
      • -------- - --------
      • Set TIR_DebugMode = True
  • TimedItemRemover
    • Events
    • Conditions
    • Actions
      • Set TIR_ItemCount = (TIR_ItemCount + 1)
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • TIR_ItemCount Equal to 1
        • Then - Actions
          • Trigger - Turn on TIR_Loop
        • Else - Actions
          • -------- loop is already on; do nothing --------
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • TIR_RecycledSize Equal to 0
        • Then - Actions
          • Set TIR_MaxIndex = (TIR_MaxIndex + 1)
          • Set TIR_Item_ID = TIR_MaxIndex
        • Else - Actions
          • Set TIR_RecycledSize = (TIR_RecycledSize - 1)
          • Set TIR_Item_ID = TIR_RecycledStack[TIR_RecycledSize]
      • -------- - --------
      • Set TIR_NodeNext[TIR_Item_ID] = 0
      • Set TIR_NodeNext[TIR_NodePrev[0]] = TIR_Item_ID
      • Set TIR_NodePrev[TIR_Item_ID] = TIR_NodePrev[0]
      • Set TIR_NodePrev[0] = TIR_Item_ID
      • -------- - --------
      • Set TIR_ItemArr[TIR_Item_ID] = TIR_Item
      • Set TIR_Counter[TIR_Item_ID] = TIR_Duration
      • Set TIR_CleanUp[TIR_Item_ID] = False
  • TimedItemRemover Loop
    • Events
    • Conditions
    • Actions
      • Set TIR_Item_ID = 0
      • For each (Integer TIR_LoopInt) from 1 to TIR_ItemCount, do (Actions)
        • Loop - Actions
          • Set TIR_Item_ID = TIR_NodeNext[TIR_Item_ID]
          • -------- - --------
          • -------- Check if duration is up --------
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • TIR_Counter[TIR_Item_ID] Less than or equal to 0.00
            • Then - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • TIR_CleanUp[TIR_Item_ID] Equal to False
                • Then - Actions
                  • -------- It's up; kill the item first to show dead animation --------
                  • Item - Set life of TIR_ItemArr[TIR_Item_ID] to 0.39
                  • -------- Clean up stage --------
                  • Set TIR_CleanUp[TIR_Item_ID] = True
                  • -------- Restart the timer --------
                  • Set TIR_Counter[TIR_Item_ID] = TIR_Timeout
                • Else - Actions
                  • -------- It's up; kill the item first --------
                  • Item - Set life of TIR_ItemArr[TIR_Item_ID] to 0.41
                  • Item - Remove TIR_ItemArr[TIR_Item_ID]
                  • -------- Recycle --------
                  • Set TIR_RecycledStack[TIR_RecycledSize] = TIR_Item_ID
                  • Set TIR_RecycledSize = (TIR_RecycledSize + 1)
                  • Set TIR_NodeNext[TIR_NodePrev[TIR_Item_ID]] = TIR_NodeNext[TIR_Item_ID]
                  • Set TIR_NodePrev[TIR_NodeNext[TIR_Item_ID]] = TIR_NodePrev[TIR_Item_ID]
                  • Set TIR_ItemCount = (TIR_ItemCount - 1)
                  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                    • If - Conditions
                      • TIR_ItemCount Equal to 0
                    • Then - Actions
                      • Trigger - Turn off TIR_Loop
                    • Else - Actions
                      • -------- there's still an instance running; do not turn off --------
            • Else - Actions
              • -------- Debug purpose --------
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • TIR_DebugMode Equal to True
                • Then - Actions
                  • Set TIR_TempLoc = (Position of TIR_ItemArr[TIR_Item_ID])
                  • Floating Text - Create floating text that reads (String(TIR_Counter[TIR_Item_ID])) at TIR_TempLoc with Z offset 7.50, using font size 8.00, color (70.00%, 70.00%, 100.00%), and 0.00% transparency
                  • Floating Text - Change (Last created floating text): Disable permanence
                  • Floating Text - Set the velocity of (Last created floating text) to 64.00 towards 70.00 degrees
                  • Floating Text - Change the fading age of (Last created floating text) to 1.00 seconds
                  • Floating Text - Change the lifespan of (Last created floating text) to 3.00 seconds
                  • Custom script: call RemoveLocation(udg_TIR_TempLoc)
                • Else - Actions
              • -------- It's not up yet; decrease counter --------
              • Set TIR_Counter[TIR_Item_ID] = (TIR_Counter[TIR_Item_ID] - TIR_Interval)
  • TimedItemRemover Reset
    • Events
      • Unit - A unit Acquires an item
    • Conditions
    • Actions
      • Set TIR_Item_ID = 0
      • For each (Integer TIR_LoopInt) from 1 to TIR_ItemCount, do (Actions)
        • Loop - Actions
          • Set TIR_Item_ID = TIR_NodeNext[TIR_Item_ID]
          • -------- - --------
          • -------- Check if the acquired item is in the list --------
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Item being manipulated) Equal to TIR_ItemArr[TIR_Item_ID]
            • Then - Actions
              • -------- Recycle right away --------
              • Set TIR_RecycledStack[TIR_RecycledSize] = TIR_Item_ID
              • Set TIR_RecycledSize = (TIR_RecycledSize + 1)
              • Set TIR_NodeNext[TIR_NodePrev[TIR_Item_ID]] = TIR_NodeNext[TIR_Item_ID]
              • Set TIR_NodePrev[TIR_NodeNext[TIR_Item_ID]] = TIR_NodePrev[TIR_Item_ID]
              • Set TIR_ItemCount = (TIR_ItemCount - 1)
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • TIR_ItemCount Equal to 0
                • Then - Actions
                  • Trigger - Turn off TIR_Loop
                • Else - Actions
                  • -------- there's still an instance running; do not turn off --------
            • Else - Actions

Changelog:
v1.0
- First Public Release
Contents

Timed Item Remover v1.0 (Map)

Reviews
Wrda
Very useful for RPG maps and even some kind of minigame that revolves around items and their expiration timers. I suspect for RPGs there will be a lot of items, thus the loop to find the item in the list will become slower, you may consider the...

Wrda

Spell Reviewer
Level 27
Joined
Nov 18, 2012
Messages
1,951
Very useful for RPG maps and even some kind of minigame that revolves around items and their expiration timers. I suspect for RPGs there will be a lot of items, thus the loop to find the item in the list will become slower, you may consider the hashtable for that.
A small observation: when a hero gets a tome or powerup, after TIR_CleanUp[TIR_Item_ID] becomes true, the floating text goes to the center, which implies the item was already removed. This isn't a problem nor I can see any undesired side effects.

Approved
 
Level 24
Joined
Aug 27, 2013
Messages
4,091
I suspect for RPGs there will be a lot of items, thus the loop to find the item in the list will become slower, you may consider the hashtable for that.
You're absolutely right, I was thinking about that as well but hashtable didn't come to mind. I'll do some adjustments later on.

Thanks for the approval!
 
Top