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

[Trigger] [Leak Check]Unit Respawn Code (respawning mobs)

Status
Not open for further replies.
Level 3
Joined
Dec 31, 2008
Messages
46
I was wanting to check if these triggers leaked at all, I'm not sure on how to check for leaks. And if it doesn't leak anyone is free to use this code for themselves.

  • Unit Respawn Init
    • Events
      • Map initialization
    • Conditions
    • Actions
      • Set i = 0
      • Set HostileUnitGroup = (Units owned by Player 11 (Dark Green))
      • Unit Group - Pick every unit in HostileUnitGroup and do (Actions)
        • Loop - Actions
          • Set i = (i + 1)
          • Set HostileUnit[i] = (Picked unit)
          • Set HostileUnitType[i] = (Unit-type of (Picked unit))
          • Set TempLoc1 = (Position of (Picked unit))
          • Set HostileUnitXY[i] = TempLoc1
          • Set HostileAngle[i] = (Facing of (Picked unit))
      • Custom script: call RemoveLocation(udg_TempLoc1)
      • Set UnitCount = i
  • Unit Death
    • Events
      • Unit - A unit owned by Player 11 (Dark Green) Dies
    • Conditions
    • Actions
      • For each (Integer i) from 1 to UnitCount, do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • HostileUnit[i] Equal to (Triggering unit)
            • Then - Actions
              • Set j = i
              • Set i = UnitCount
            • Else - Actions
      • Unit - Add a 10.00 second Generic expiration timer to (Triggering unit)
      • Countdown Timer - Start HostileRezTimer[j] as a One-shot timer that will expire in 90.00 seconds
      • Trigger - Add to Unit Respawn <gen> the event (Time - HostileRezTimer[j] expires)
  • Unit Respawn
    • Events
    • Conditions
    • Actions
      • For each (Integer i) from 1 to UnitCount, do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Remaining time for HostileRezTimer[i]) Equal to 0.00
            • Then - Actions
              • Countdown Timer - Start HostileRezTimer[i] as a One-shot timer that will expire in 1.00 seconds
              • Countdown Timer - Pause HostileRezTimer[i]
              • Unit - Create 1 HostileUnitType[i] for Player 11 (Dark Green) at HostileUnitXY[i] facing HostileAngle[i] degrees
              • Set HostileUnit[i] = (Last created unit)
            • Else - Actions
 
Last edited:
Level 5
Joined
Jan 27, 2014
Messages
164
No leak.
But for the first trigger, the destroy group script should be outside the unit group loop (you misspelt the variable).
There is no need to remove the point since you're using it in future.

  • Unit Respawn Init
    • Events
      • Map initialization
    • Conditions
    • Actions
      • Set i = 0
      • Set HostileUnitGroup = (Units owned by Player 11 (Dark Green))
      • Unit Group - Pick every unit in HostileUnitGroup and do (Actions)
        • Loop - Actions
          • Set i = (i + 1)
          • Set HostileUnit[i] = (Picked unit)
          • Set HostileUnitType[i] = (Unit-type of (Picked unit))
          • Set TempLoc1 = (Position of (Picked unit))
          • Set HostileUnitXY[i] = TempLoc1
          • Set HostileAngle[i] = (Facing of (Picked unit))
      • Custom script: call DestroyGroup(udg_HostileUnitGroup)
      • Set UnitCount = i
Edit:
I also see quite a few redundant equations, but maybe you know what you're doing better.
 
Level 3
Joined
Dec 31, 2008
Messages
46
No leak.
But for the first trigger, the destroy group script should be outside the unit group loop (you misspelt the variable).
There is no need to remove the point since you're using it in future.

  • Unit Respawn Init
    • Events
      • Map initialization
    • Conditions
    • Actions
      • Set i = 0
      • Set HostileUnitGroup = (Units owned by Player 11 (Dark Green))
      • Unit Group - Pick every unit in HostileUnitGroup and do (Actions)
        • Loop - Actions
          • Set i = (i + 1)
          • Set HostileUnit[i] = (Picked unit)
          • Set HostileUnitType[i] = (Unit-type of (Picked unit))
          • Set TempLoc1 = (Position of (Picked unit))
          • Set HostileUnitXY[i] = TempLoc1
          • Set HostileAngle[i] = (Facing of (Picked unit))
      • Custom script: call DestroyGroup(udg_HostileUnitGroup)
      • Set UnitCount = i

Thank you very much! I've been running this through my head for about 3 hours trying to make it perfect. I made a similar code a few years back that leaked really badly because I wasn't as experienced back then.

Again thank you for your time to look over it.


EDIT: I did find one redundancy from where I changed something, I will remove and re-upload accordingly.

EDIT: It looks like the trigger isn't quite working correctly. I'll have to look into it.
 
Last edited:
Status
Not open for further replies.
Top