• 🏆 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!
  • 🏆 Hive's 6th HD Modeling Contest: Mechanical is now open! Design and model a mechanical creature, mechanized animal, a futuristic robotic being, or anything else your imagination can tinker with! 📅 Submissions close on June 30, 2024. Don't miss this opportunity to let your creativity shine! Enter now and show us your mechanical masterpiece! 🔗 Click here to enter!

Help to make a trigger that counts living units!

Status
Not open for further replies.
Level 4
Joined
Feb 13, 2015
Messages
60
Hi, I need a trigger to count a type of unit that are in the playable map. After that it need to stop further units from be created. Exampel is that i spawn a wave with cretures every second but want to keep it limited. And when x dies then x spawn again.
 
Level 12
Joined
May 22, 2015
Messages
1,051
I have a similar setup in my own map. The function that counts the number of units in a group is actually painfully slow (it loops through them adding 1 each time to a counter and then gives back the counter). It also can get null units in it that aren't counted properly.

The way I set it up was:
  • Events
    • Unit - A unit enters (<Playable map area>)
  • Conditions
    • Unit type of (Triggering unit) equal to UnitTypeToCount
  • Actions
    • set count = count + 1
  • Events
    • Unit - A unit dies
  • Conditions
    • Unit type of (Triggering unit) equal to UnitTypeToCount
  • Actions
    • set count = count - 1
Then you can check if the count is equal or greater than your limit and only spawn the units if it is below.

Alternatively, the first trigger could be done by having the trigger that spawns the units increase the counter. It is more efficient this way.
 
Level 4
Joined
Feb 13, 2015
Messages
60
Thanks, could you also show how to make a condition when it counts to x so i can use actions after that to stop more units from spawing?
 
Level 4
Joined
Feb 13, 2015
Messages
60
Ok, what i need is some triggers to put like a barrier (easy turn trigger off) that stops minions (neutral hostile) from spawing, when there are 40+ in the playable map, then turn it on when its below 40.
 
Level 12
Joined
May 22, 2015
Messages
1,051
SAUS your trigger doesn't work for units removed.

Good catch. Units don't get removed in my map so it's not an issue for me. I did have an issue with units that get reanimated though, lol. I needed to only count them dying once.
 
Level 4
Joined
Feb 13, 2015
Messages
60
So this works, but i have one like this but the condition counts less then 10, also it says turn off instead on on and that does not work. So it turns a trigger on but not off even when there are less then 10 minions on the battlefield.

Help, plz.
 

Attachments

  • not more.png
    not more.png
    7.4 KB · Views: 131
Level 12
Joined
May 22, 2015
Messages
1,051
So this works, but i have one like this but the condition counts less then 10, also it says turn off instead on on and that does not work. So it turns a trigger on but not off even when there are less then 10 minions on the battlefield.

Help, plz.

Does the trigger "more 2" spawn the units?

It sounds like those triggers may be a bit backwards. You want it to stop spawning when there are 10 or more units and start again where there are less.

You can also condense those triggers into 1.

You could also just put the check in the trigger "more 2".

Try disabling those two triggers and then in the trigger "more 2", add at the top:
  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
    • If - Conditions
      • count Greater than or equal to 10
    • Then - Actions
      • Skip remaining actions
    • Else - Actions
 
Level 4
Joined
Feb 13, 2015
Messages
60
Does the trigger "more 2" spawn the units?

It sounds like those triggers may be a bit backwards. You want it to stop spawning when there are 10 or more units and start again where there are less.

You can also condense those triggers into 1.

You could also just put the check in the trigger "more 2".

Try disabling those two triggers and then in the trigger "more 2", add at the top:
  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
    • If - Conditions
      • count Greater than or equal to 10
    • Then - Actions
      • Skip remaining actions
    • Else - Actions

It was a wave spawner, and when i put what you showed, it gave the same result as before, it turned them off, but not on again.

As tho my count does not go - only +, i have the same but i have "(count-1)" and (count+1).
 
Level 11
Joined
Jan 23, 2015
Messages
788
Why not this trigger:

  • every 1 second of gametime
  • set TempGroup = units in playable map area matching (matching unit is alive equal to true)
  • set NumOfLivingUnits = Number of units in TempGroup
  • custom script = call DestroyGroup(udg_TempGroup)
trigger 2 (for the spawn limit):

  • every 1 second of game time
    • if/then/else
      • if conditions
      • NumOfLivingUnits lesser than UnitsLimit
      • then actions
      • if/then/else
        • if conditions
        • (UnitsLimit - NumOfLivingUnits) lesser than or equal to <Number of creep spawns in your map>
        • then actions
        • for each integer A (1 to <Number of creep spawns in your map>) do multiple actions
          • set TempPoint = center of Spawn[(Integer A)]
          • spawn 1 creature at TempPoint
          • custom script: call RemoveLocation(udg_TempPoint)
        • else actions
        • for each integer A (1 to (UnitsLimit - NumOfLivingUnits)) do multiple actions
          • set TempPoint = center of Spawn[(Integer A)]
          • spawn 1 creature at TempPoint
          • custom script: call RemoveLocation(udg_TempPoint)
      • else actions
trigger 2 spawns more creeps if there is a gap (the number of creeps is lesser than the limit) and will always keep the number of units to the limit.. sorry, I had a problem with WE so I couldn't open it and show you a real trigger.. if you dont understand what i sad above, just say it -_-

I assume that you need this trigger for a TD map, and that you already know that when you kill a unit, another one spawns, so the creeps will never stop spawning..
 
Level 4
Joined
Feb 13, 2015
Messages
60
Thanks, SAUS and Arad, now i can keep working! RobertMKD, your way seems great for my map but way to complex for me xD If what i get now fails maybe i come back here to take a look again with maybe more experiance.
 
Status
Not open for further replies.
Top