• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

[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