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

Countdown Loops, Hashtables, and Unit Handles

Status
Not open for further replies.
Level 6
Joined
May 15, 2009
Messages
191
Hello Hive!

I'm trying to create a trigger for my Boss fight, where occasionally a "Warp Hole" will spawn at a random position near the boss (which is refered to as "PotF" or "BossUMini").
These Warp Holes are dummy units that will, after 5 seconds, explode and deal damage to all nearby Heroes from the Player Team (allied to Player 1).

Seeing as multiple Warp Holes should be counting down at once, I decided to save the units and their respective countdown integers in a hashtable. The units are also saved in a unit group, to pick through them later.
The saving seemingly works alright, but I am having trouble loading the Tempi in the loop trigger, it simply returns null.

  • PotF WarpHole Initiate
    • Events
      • Time - Elapsed game time is 5.00 seconds
    • Conditions
      • (Dragonknight 0014 <gen> is alive) Equal to True
    • Actions
      • -------- Saves the current location of the PotF (BossUMini is set in the "Portal Decay" trigger) --------
      • Set WarpHole_Tempp1 = (Position of Dragonknight 0014 <gen>)
      • -------- Creates a random point in the vicinity of the PotF (random offset towards random angle) --------
      • Set WarpHole_Tempp2 = (WarpHole_Tempp1 offset by (Random real number between 200.00 and 625.00) towards (Random angle) degrees)
      • -------- Creates a Warp Hole (Warning) dummy unit to indicate where the detonation will occur (and gives the Players a chance to flee) --------
      • Unit - Create 1 Warp Hole (Warning) for Neutral Passive at WarpHole_Tempp2 facing Default building facing degrees
      • -------- Saves the Warp Hole (warning) as WarpHole_Tempu1 --------
      • Set WarpHole_Tempu1 = (Last created unit)
      • -------- Saves the units Handle ID in an integer - this is a number unique to any unit in the map. It puts a number on every Warp Hole, a number that we can use --------
      • Set Portal_Tempi = (Key (Last created unit))
      • Game - Display to (All players) the text: (Saved handleID: + (String(WarpHole_handle)))
      • -------- Saves the countdown duration (how long it takes for the Warp Hole to detonate as WarpHole_Tempi = 5 --------
      • Set WarpHole_Tempi = 5
      • -------- Saves the WarpHole_Tempi in the hashtable, where it is connected to the unit id (WarpHole_handle) of the Warp Hole (Warning) unit, meaning each created Warp Hole has a number Tempi attacted to it --------
      • Hashtable - Save WarpHole_Tempi as 0 of WarpHole_handle in WarpHole_hash
      • Game - Display to (All players) the text: (Saved value: + (String(WarpHole_Tempi)))
      • -------- Adds the Warp Hole unit to the WarpHole_ActiveGroup unit group, this is used to cycle through all active Warp Holes in "PotF WarpHole Loop" --------
      • Unit Group - Add WarpHole_Tempu1 to WarpHole_ActiveGroup
      • -------- Cleans up the trigger by removing the point variables, NOT THE UNIT GROUP --------
      • Custom script: call RemoveLocation(udg_WarpHole_Tempp1)
      • Custom script: call RemoveLocation(udg_WarpHole_Tempp2)

(The hashtable in question is created at map initialization)
(Do not mind the "Elapsed time equal to 5", that is merely for testing purposes")
(Do not mind this "Dragonknight", it is also merely for testing purposes, it is usually "BossUMini")


  • PotF WarpHole Loop
    • Events
      • Time - Every 1.00 seconds of game time
    • Conditions
    • Actions
      • Unit Group - Pick every unit in WarpHole_ActiveGroup and do (Actions)
        • Loop - Actions
          • -------- Saves the picked unit in a unit variable --------
          • Set WarpHole_Tempu1 = (Picked unit)
          • -------- Saves the Handle ID of the picked unit as WarpHole_handle --------
          • Set WarpHole_handle = (Key (Picked unit))
          • Game - Display to (All players) the text: (Retrieved handleID: + (String(WarpHole_handle)))
          • -------- Sets WarpHole_Tempi = loaded value for the specific Handle ID, meaning the timer saved in "PotF WarpHole Initiate" --------
          • Set WarpHole_Tempi = (Load 0 of WarpHole_handle from WarpHole_hash)
          • Game - Display to (All players) the text: (Retrieved value: + (String(WarpHole_Tempi)))
          • -------- Saves the position of the picked unit as WarpHole_Tempp3 --------
          • Set WarpHole_Tempp3 = (Position of WarpHole_Tempu1)
          • -------- Floating Text --------
          • -------- Checks if the Tempi value has reached 0 (meaning the Warp Hole detonates), if not, proceeds to count down (by reducing Tempi1 by 1, and saving it anew) --------
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • WarpHole_Tempi Equal to 0
            • Then - Actions
              • -------- If the countdown has reached 0, the Warp Hole blows up. First the Warning unit is removed from the ActiveGroup and the game --------
              • Unit Group - Remove WarpHole_Tempu1 from WarpHole_ActiveGroup
              • Unit - Remove WarpHole_Tempu1 from the game
              • -------- Creates a special effect unit, saves it as WarpHole_Tempu2, and adds an expiration timer to it. --------
              • Unit - Create 1 Warp Hole (Detonation) for Neutral Passive at WarpHole_Tempp1 facing Default building facing degrees
              • Set WarpHole_Tempu2 = (Last created unit)
              • Unit - Add a 0.98 second Generic expiration timer to WarpHole_Tempu2
              • -------- Deals damage to all enemies of the PotF (meaning the Heroes) within a small radius. The Heroes are saved in a Unit Group, and damaged by the BossUMini --------
              • Set WarpHole_Tempug = (Units within 250.00 of WarpHole_Tempp3 matching ((((Matching unit) is alive) Equal to True) and ((((Matching unit) is A Hero) Equal to True) and (((Matching unit) belongs to an ally of Player 1 (Red)) Equal to True))))
              • Unit Group - Pick every unit in WarpHole_Tempug and do (Actions)
                • Loop - Actions
                  • Unit - Cause BossUmini to damage (Picked unit), dealing 300.00 damage of attack type Spells and damage type Normal
              • -------- Destroys the Tempug to avoid leaks --------
              • Custom script: call DestroyGroup(udg_WarpHole_Tempug)
            • Else - Actions
              • -------- If the Warp Hole did not go off yet, saves Tempi - 1 as the new value so that it continues counting downwards --------
              • Set WarpHole_Tempi = (WarpHole_Tempi - 1)
              • Hashtable - Save WarpHole_Tempi as (Key CD) of WarpHole_handle in WarpHole_hash
          • -------- Cleans up the created point variable --------
          • Custom script: call RemoveLocation(udg_WarpHole_Tempp3)

(I left the floating text empty for now, to avoid confusion. It will eventually display the Tempi above the unit, to let people know when the Warp Hole will blow)

So, can anyone see any faults in the loop trigger? Or perhaps enlighten me on the mystery of hashtables and handles? I simply cannot seem to retrive the proper Tempi value for my picked unit, nor can I seem to find out what the problem is.

Thank you for your time
-Battlehound/Woodenplank

P.S. Also, sorry about all the comments. I am making the map as a sort of tutorial for some mates, and I'm using the comments to explain underway.
 

Bribe

Code Moderator
Level 50
Joined
Sep 26, 2009
Messages
9,464
Game - Display to (All players) the text: (Saved handleID: + (String(WarpHole_handle)))

-> Change the last part to (String(Portal_Tempi)) as you didn't set WarpHole_handle anywhere I can see

Hashtable - Save WarpHole_Tempi as 0 of WarpHole_handle in WarpHole_hash

-> There it is again. You never set WarpHole_handle, you want Portal_Tempi. That's probably the issue.
 
Level 6
Joined
May 15, 2009
Messages
191
Oh! Thanks for pointing that out Bribe. Portal_Tempi is actually used in an entirely different trigger, I just missed that part. Thought it had been properly set to WarpHole_handle.
Any way, the count down now works, even for multiple Warp Holes.

Thanks Bribe
+rep
 
Status
Not open for further replies.
Top