• 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.

Creep Respawn Trigger

Status
Not open for further replies.
Level 3
Joined
Feb 1, 2013
Messages
43
I'm trying to make a trigger that respawns a random set of creeps inside a region when the region has no units in it (other than neutral passive, because there are animals). This is what I came up with:
  • Bottom Spawn
    • Events
      • Time - Every 10.00 seconds of game time
    • Conditions
    • Actions
      • Unit Group - Pick every unit in (Units in Region 022 <gen> matching (((Triggering unit) is alive) Equal to True)) and do (If ((Owner of (Picked unit)) Equal to Neutral Passive) then do (Unit - Create 5 Bandit for Neutral Hostile at (Center of Region 022 <gen>) facing Default building facing degrees) else do (Do nothing))
I haven't make it so that it spawns a set of creeps, so just for testing purpose, I made it spawn 5 Bandits. However nothing respawns after one whole minute after I killed all creeps in that region and moved my units out.
Can anyone tell me how to make a trigger that does that?
 
Level 3
Joined
Feb 1, 2013
Messages
43
Great, I did as you told and this is what I came up with:
  • Bottom Spawn
    • Events
      • Time - Every 10.00 seconds of game time
    • Conditions
      • (Number of units in (Units in Region 022 <gen>)) Equal to 0
    • Actions
      • Unit - Create 5 Bandit for Neutral Hostile at (Center of Region 022 <gen>) facing Default building facing degrees
and it works! Thanks.

By the way, how do I make it so that the trigger works even if there is corpse or neutral passive inside? Just asking.
 
Level 28
Joined
Sep 26, 2009
Messages
2,520
  • Triggers
    • Events
      • Time - Every 10.00 seconds of game time
    • Conditions
      • (Number of units in (Units in Region 022 <gen> matching ((((Matching unit) is alive) Equal to True) and ((Owner of (Matching unit)) Not equal to Neutral Passive)))) Equal to 0
    • Actions
      • Unit - Create 5 Guardsman for Neutral Hostile at (Center of Region 022 <gen>) facing Default building facing degrees
(Matching unit) is alive condition is a boolean and the other condition is under Player comparison.


Although I am not sure if the trigger above doesn't leak. If it does, change the trigger into
  • Triggers
    • Events
      • Time - Every 10.00 seconds of game time
    • Conditions
    • Actions
      • Set Temp_Group = (Units in Region 022 <gen> matching ((((Matching unit) is alive) Equal to True) and ((Owner of (Matching unit)) Not equal to Neutral Passive)))
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Number of units in Temp_Group) Equal to 0
        • Then - Actions
          • Unit - Create 5 Guardsman for Neutral Hostile at (Center of Region 022 <gen>) facing Default building facing degrees
        • Else - Actions
      • Custom script: call DestroyGroup(udg_Temp_Group)
      • Custom script: set udg_Temp_Group = null
 
Level 7
Joined
Jan 22, 2013
Messages
293
  • Triggers
    • Events
      • Time - Every 10.00 seconds of game time
    • Conditions
      • (Number of units in (Units in Region 022 <gen> matching ((((Matching unit) is alive) Equal to True) and ((Owner of (Matching unit)) Not equal to Neutral Passive)))) Equal to 0
    • Actions
      • Unit - Create 5 Guardsman for Neutral Hostile at (Center of Region 022 <gen>) facing Default building facing degrees
(Matching unit) is alive condition is a boolean and the other condition is under Player comparison.


Although I am not sure if the trigger above doesn't leak. If it does, change the trigger into
  • Triggers
    • Events
      • Time - Every 10.00 seconds of game time
    • Conditions
    • Actions
      • Set Temp_Group = (Units in Region 022 <gen> matching ((((Matching unit) is alive) Equal to True) and ((Owner of (Matching unit)) Not equal to Neutral Passive)))
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Number of units in Temp_Group) Equal to 0
        • Then - Actions
          • Unit - Create 5 Guardsman for Neutral Hostile at (Center of Region 022 <gen>) facing Default building facing degrees
        • Else - Actions
      • Custom script: call DestroyGroup(udg_Temp_Group)
      • Custom script: set udg_Temp_Group = null

A good fix. You missed the Location Leak from him creating units.

Here is it complete.

  • Triggers
    • Events
      • Time - Every 10.00 seconds of game time
    • Conditions
    • Actions
      • Set Temp_Group = (Units in Region 022 <gen> matching ((((Matching unit) is alive) Equal to True) and ((Owner of (Matching unit)) Not equal to Neutral Passive)))
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Number of units in Temp_Group) Equal to 0
        • Then - Actions
          • Set Temp_Location = (Center of Region 022 <gen>)
          • Unit - Create 5 Guardsman for Neutral Hostile at Temp_Location facing Default building facing degrees
          • Custom script: call RemoveLocation(udg_Temp_Location)
        • Else - Actions
      • Custom script: call DestroyGroup(udg_Temp_Group)
      • Custom script: set udg_Temp_Group = null
Enjoy :)
 
Level 3
Joined
Feb 1, 2013
Messages
43
So I learned from all your replies and this is what I came out with:
  • Bottom Spawn
    • Events
      • Time - Every 10.00 seconds of game time
    • Conditions
    • Actions
      • Set Creeps = (Units in Region 022 <gen> matching ((((Matching unit) is alive) Equal to True) and ((Owner of (Matching unit)) Not equal to Neutral Passive)))
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Number of units in Creeps) Equal to 0
        • Then - Actions
          • Set Creep_Camp = (Center of Region 022 <gen>)
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Random integer number between 1 and 2) Equal to 1
            • Then - Actions
              • Unit - Create 2 Brigand for Neutral Hostile at Creep_Camp facing Default building facing degrees
              • Unit - Create 2 Rogue for Neutral Hostile at Creep_Camp facing Default building facing degrees
              • Custom script: call RemoveLocation(udg_Creep_Camp)
              • Custom script: set udg_Creep_Camp = null
            • Else - Actions
              • Unit - Create 2 Assassin for Neutral Hostile at Creep_Camp facing Default building facing degrees
              • Unit - Create 1 Enforcer for Neutral Hostile at Creep_Camp facing Default building facing degrees
              • Custom script: call RemoveLocation(udg_Creep_Camp)
              • Custom script: set udg_Creep_Camp = null
        • Else - Actions
      • Custom script: call DestroyGroup(udg_Creeps)
      • Custom script: set udg_Creeps = null
Is this correct and leak-free?
Also, since I have multiple locations, do I need to repeat this trigger for every region or is there an easier way with one trigger?
 
Level 28
Joined
Sep 26, 2009
Messages
2,520
It is without leaks. The only thing you can change there is putting
  • Custom script: call RemoveLocation(udg_Creep_Camp)
  • Custom script: set udg_Creep_Camp = null
after the If/Then/Else action, since you remove that location anyway. But the way you have it is correct too.

As for your question with multiple creep camps. Personally, I wouldn't do it through regions, but through points.
I would place a dummy unit in center of each creep camp. Then run a map initialization trigger that picks all these dummy units and saves their location into point array, then remove the dummy unit (but you wouldn't destroy those points). Finally, you would use your trigger that would loop through all these points and pick up units in ~500 range (may be bigger/smaller, just to be about the same size as are currently your regions) and spawn units if no unit is picked.
 
Level 9
Joined
Nov 19, 2011
Messages
516
Jeez.... You don't need to destroy anything. You are using constant value only: Region 022 <gen>. Destroy is needed for variables (like 'my_array_of_units[1]') or pointers (like 'attacked unit') only.

FYI pointers some pointers are destroyed at end of trigger automatically. For e.g. 'Triggering Unit'. Each trigger has it's own 'triggering unit' pointer, so if you will call one trigger from another, you cannot refer to same 'triggering unit'.

To learn more about pointers see 'Java' in Wikipedia.org as Java is using most similar rules for pointers.
 
Jeez.... You don't need to destroy anything. You are using constant value only: Region 022 <gen>. Destroy is needed for variables (like 'my_array_of_units[1]') or pointers (like 'attacked unit') only.

FYI pointers some pointers are destroyed at end of trigger automatically. For e.g. 'Triggering Unit'. Each trigger has it's own 'triggering unit' pointer, so if you will call one trigger from another, you cannot refer to same 'triggering unit'.

To learn more about pointers see 'Java' in Wikipedia.org as Java is using most similar rules for pointers.

he puts center of Region 022 <gen> into a point variable. so what nichilus said is correct. it is just to shorten his trigger a little. as he already cleans it up
 
Level 3
Joined
Feb 1, 2013
Messages
43
As for your question with multiple creep camps. Personally, I wouldn't do it through regions, but through points.
I would place a dummy unit in center of each creep camp. Then run a map initialization trigger that picks all these dummy units and saves their location into point array, then remove the dummy unit (but you wouldn't destroy those points). Finally, you would use your trigger that would loop through all these points and pick up units in ~500 range (may be bigger/smaller, just to be about the same size as are currently your regions) and spawn units if no unit is picked.
This is what I came up with:
  • Set Camp
    • Events
      • Map initialization
    • Conditions
    • Actions
      • Set Creep_Camp[0] = (Position of Scout 0041 <gen>)
      • Set Creep_Camp[1] = (Position of Scout 0042 <gen>)
      • Set Creep_Camp[2] = (Position of Scout 0043 <gen>)
      • Set Creep_Camp[3] = (Position of Scout 0044 <gen>)
      • Set Ancient_Camp[0] = (Position of Scout 0046 <gen>)
      • Set Ancient_Camp[1] = (Position of Scout 0045 <gen>)
      • Wait 30.00 seconds
      • Unit Group - Pick every unit in (Units in (Playable map area) matching ((Unit-type of (Matching unit)) Equal to Scout)) and do (Unit - Kill (Matching unit))
And for the creeps spawn:
  • Spawn Creeps
    • Events
      • Time - Every 10.00 seconds of game time
    • Conditions
    • Actions
      • Set Creeps[0] = (Units within 500.00 of Creep_Camp[0] matching ((((Matching unit) is alive) Equal to True) and ((Owner of (Matching unit)) Not equal to Neutral Passive)))
      • Set Creeps[1] = (Units within 500.00 of Creep_Camp[1] matching ((((Matching unit) is alive) Equal to True) and ((Owner of (Matching unit)) Not equal to Neutral Passive)))
      • Set Creeps[2] = (Units within 500.00 of Creep_Camp[2] matching ((((Matching unit) is alive) Equal to True) and ((Owner of (Matching unit)) Not equal to Neutral Passive)))
      • Set Creeps[3] = (Units within 500.00 of Creep_Camp[3] matching ((((Matching unit) is alive) Equal to True) and ((Owner of (Matching unit)) Not equal to Neutral Passive)))
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Number of units in Creeps[0]) Equal to 0
        • Then - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Random integer number between 1 and 2) Equal to 1
            • Then - Actions
              • Unit - Create 2 Brigand for Neutral Hostile at Creep_Camp[0] facing Default building facing degrees
              • Unit - Create 2 Rogue for Neutral Hostile at Creep_Camp[0] facing Default building facing degrees
            • Else - Actions
              • Unit - Create 2 Assassin for Neutral Hostile at Creep_Camp[0] facing Default building facing degrees
              • Unit - Create 1 Enforcer for Neutral Hostile at Creep_Camp[0] facing Default building facing degrees
        • Else - Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Number of units in Creeps[1]) Equal to 0
        • Then - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Random integer number between 1 and 2) Equal to 1
            • Then - Actions
              • Unit - Create 2 Brigand for Neutral Hostile at Creep_Camp[1] facing Default building facing degrees
              • Unit - Create 2 Rogue for Neutral Hostile at Creep_Camp[1] facing Default building facing degrees
            • Else - Actions
              • Unit - Create 2 Assassin for Neutral Hostile at Creep_Camp[1] facing Default building facing degrees
              • Unit - Create 1 Enforcer for Neutral Hostile at Creep_Camp[1] facing Default building facing degrees
        • Else - Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Number of units in Creeps[2]) Equal to 0
        • Then - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Random integer number between 1 and 2) Equal to 1
            • Then - Actions
              • Unit - Create 2 Brigand for Neutral Hostile at Creep_Camp[2] facing Default building facing degrees
              • Unit - Create 2 Rogue for Neutral Hostile at Creep_Camp[2] facing Default building facing degrees
            • Else - Actions
              • Unit - Create 2 Assassin for Neutral Hostile at Creep_Camp[2] facing Default building facing degrees
              • Unit - Create 1 Enforcer for Neutral Hostile at Creep_Camp[2] facing Default building facing degrees
        • Else - Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Number of units in Creeps[3]) Equal to 0
        • Then - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Random integer number between 1 and 2) Equal to 1
            • Then - Actions
              • Unit - Create 2 Brigand for Neutral Hostile at Creep_Camp[3] facing Default building facing degrees
              • Unit - Create 2 Rogue for Neutral Hostile at Creep_Camp[3] facing Default building facing degrees
            • Else - Actions
              • Unit - Create 2 Assassin for Neutral Hostile at Creep_Camp[3] facing Default building facing degrees
              • Unit - Create 1 Enforcer for Neutral Hostile at Creep_Camp[3] facing Default building facing degrees
        • Else - Actions
      • Custom script: call DestroyGroup(udg_Creeps[0])
      • Custom script: call DestroyGroup(udg_Creeps[1])
      • Custom script: call DestroyGroup(udg_Creeps[2])
      • Custom script: call DestroyGroup(udg_Creeps[3])
      • Custom script: set udg_Creeps[0] = null
      • Custom script: set udg_Creeps[1] = null
      • Custom script: set udg_Creeps[2] = null
      • Custom script: set udg_Creeps[3] = null
The Ancient spawn:
  • Spawn Ancients
    • Events
      • Time - Every 10.00 seconds of game time
    • Conditions
    • Actions
      • Set Ancients[0] = (Units within 500.00 of Ancient_Camp[0] matching ((((Matching unit) is alive) Equal to True) and ((Owner of (Matching unit)) Not equal to Neutral Passive)))
      • Set Ancients[1] = (Units within 500.00 of Ancient_Camp[1] matching ((((Matching unit) is alive) Equal to True) and ((Owner of (Matching unit)) Not equal to Neutral Passive)))
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Number of units in Ancients[0]) Equal to 0
        • Then - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Random integer number between 1 and 2) Equal to 1
            • Then - Actions
              • Unit - Create 2 Renegade Wizard for Neutral Hostile at Ancient_Camp[0] facing Default building facing degrees
              • Unit - Create 1 Dark Wizard for Neutral Hostile at Ancient_Camp[0] facing Default building facing degrees
            • Else - Actions
              • Unit - Create 3 Enforcer for Neutral Hostile at Ancient_Camp[0] facing Default building facing degrees
              • Unit - Create 1 Bandit Lord for Neutral Hostile at Ancient_Camp[0] facing Default building facing degrees
        • Else - Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Number of units in Ancients[1]) Equal to 0
        • Then - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Random integer number between 1 and 2) Equal to 1
            • Then - Actions
              • Unit - Create 2 Renegade Wizard for Neutral Hostile at Ancient_Camp[1] facing Default building facing degrees
              • Unit - Create 1 Dark Wizard for Neutral Hostile at Ancient_Camp[1] facing Default building facing degrees
            • Else - Actions
              • Unit - Create 3 Enforcer for Neutral Hostile at Ancient_Camp[1] facing Default building facing degrees
              • Unit - Create 1 Bandit Lord for Neutral Hostile at Ancient_Camp[1] facing Default building facing degrees
        • Else - Actions
      • Custom script: call DestroyGroup(udg_Ancients[0])
      • Custom script: call DestroyGroup(udg_Ancients[1])
      • Custom script: set udg_Ancients[0] = null
      • Custom script: set udg_Ancients[1] = null
Strange, the scouts don't die...anyway, is the leak fix correct?
 
Last edited:
first here is a link to the things that link guide. http://www.hiveworkshop.com/forums/triggers-scripts-269/things-leak-35124/

on there is this one. never use these.
Things That Always Leak

Never use these functions:

  • Unit Group - Pick all units of type Footman and do...
  • Camera - Pan Camera as needed...

u also have a problem u set the positions in map init and then delete them 10 seconds later. this would only let the trigger run once and then every time after it would not work.
u should only use a location variable once then delete it immediately after use or it leaks. also when posting long triggers plz use the hidden tags so everyone doesnt have to scroll down so far.
 
Level 28
Joined
Sep 26, 2009
Messages
2,520
Overly complicated. The reason why I would do it with point arrays is because you can easily name them and then easily call them.

This is initialization trigger
  • Set Camp
    • Events
      • Map initialization
    • Conditions
    • Actions
      • Set Index = 1
      • Set NumberOfCamps = 0
      • Custom script: set bj_wantDestroyGroup = true
      • Unit Group - Pick every unit in (Units in (Playable map area) matching ((Unit-type of (Matching unit)) Equal to Scout)) and do (Actions)
        • Loop - Actions
          • Set Creep_Camp[Index] = (Position of (Picked unit))
          • Set Index = (Index + 1)
          • Set NumberOfCamps = (NumberOfCamps + 1)
          • Unit - Remove (Picked unit) from the game
"Index" and "NumberOfCamps" are integer variables.
Also if you know you will always have for example 5 camps of Bandit units, then you don't need to save "NumberOfCamps"


Now for the trigger that loops every 10 seconds
  • Triggers
    • Events
      • Time - Every 10.00 seconds of game time
    • Conditions
    • Actions
      • For each (Integer LoopInteger) from 1 to NumberOfCamps, do (Actions)
        • Loop - Actions
          • Set Creeps = (Units within 500.00 of Creep_Camp[LoopInteger] matching ((((Matching unit) is alive) Equal to True) and ((Owner of (Matching unit)) Not equal to Neutral Passive)))
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Number of units in Creeps) Equal to 0
            • Then - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • (Random integer number between 1 and 2) Equal to 1
                • Then - Actions
                  • Unit - Create 2 Brigand for Neutral Hostile at Creep_Camp[LoopInteger] facing Default building facing degrees
                  • Unit - Create 2 Rogue for Neutral Hostile at Creep_Camp[LoopInteger] facing Default building facing degrees
                • Else - Actions
                  • Unit - Create 2 Assassin for Neutral Hostile at Creep_Camp[LoopInteger] facing Default building facing degrees
                  • Unit - Create 1 Enforcer for Neutral Hostile at Creep_Camp[LoopInteger] facing Default building facing degrees
            • Else - Actions
          • Custom script: call DestroyGroup(udg_Creeps)
          • Custom script: set udg_Creeps = null
Note, that NumberOfCamps is an integer you set in your initial trigger. LoopInteger is an integer used for loops since Integer A seems to be buggy.
The ancient trigger should done the same way.

The only leak I currently see is in the initial trigger where you create a group (by picking scouts) and don't destroy it.

Also, those scouts don't die because your actions is "Kill (matching unit)". They should be called (matching unit) only in conditions, in actions they are (picked unit)

Edit: Also, note that in my initial trigger I pick all "Scouts" and set them as spawn place for bandits, not for Ancients. However it could be done by placing different unit for Ancient spawn points and then pick those units as well.
 
Level 3
Joined
Feb 1, 2013
Messages
43
So this is what I did:
  • Set Camp
    • Events
      • Map initialization
    • Conditions
    • Actions
      • Set Index = 1
      • Custom script: set bj_wantDestroyGroup = true
      • Unit Group - Pick every unit in (Units in (Playable map area) matching ((Unit-type of (Matching unit)) Equal to Scout)) and do (Actions)
        • Loop - Actions
          • Set Creep_Camp[Index] = (Position of (Picked unit))
          • Set Index = (Index + 1)
          • Unit - Remove (Picked unit) from the game
  • Spawn Creeps
    • Events
      • Time - Every 10.00 seconds of game time
    • Conditions
    • Actions
      • For each (Integer LoopInteger) from 1 to 4, do (Actions)
        • Loop - Actions
          • Set Creeps = (Units within 500.00 of Creep_Camp[LoopInteger] matching ((((Triggering unit) is alive) Equal to True) and ((Owner of (Matching unit)) Not equal to Neutral Passive)))
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Number of units in Creeps) Equal to 0
            • Then - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • (Random integer number between 1 and 2) Equal to 1
                • Then - Actions
                  • Unit - Create 2 Brigand for Neutral Hostile at Creep_Camp[LoopInteger] facing Default building facing degrees
                  • Unit - Create 2 Rogue for Neutral Hostile at Creep_Camp[LoopInteger] facing Default building facing degrees
                • Else - Actions
                  • Unit - Create 2 Assassin for Neutral Hostile at Creep_Camp[LoopInteger] facing Default building facing degrees
                  • Unit - Create 1 Enforcer for Neutral Hostile at Creep_Camp[LoopInteger] facing Default building facing degrees
            • Else - Actions
      • Custom script: call DestroyGroup(udg_Creeps)
      • Custom script: set udg_Creeps = null
It is working finally...although I didn't understand it exactly.
 
Level 28
Joined
Sep 26, 2009
Messages
2,520
The Spawn Creeps trigger works like this:
Loop from 1 to X means all actions in the loop will fire X times (in your case 4 times). LoopInteger is number of the current loop. So for the first loop it will be 1, for 3rd loop it will be 3.

Names of your points are Creep_Camp[1/2/...]. The loop calls for Creep_Camp[LoopInteger], so the first time it fires, LoopInteger will be 1, thus it will pick all units around Creep_Camp[1]; the second time it will be Creep_Camp[2] and so on.
 
Status
Not open for further replies.
Top