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

[General] how to limit a unit properly

Status
Not open for further replies.
Level 18
Joined
Jan 12, 2011
Messages
1,513
ok so i've been using this trigger to limit units easily:
Air Unit Limits
Acontecimientos
Tiempo - Elapsed game time is 0.01 seconds
Condiciones
Acciones
Grupo de jugadores - Pick every player in (All players) and do (Actions)
Bucle: Acciones
Jugador - Limit training of Nerubian Bombardero to 10 for (Picked player)
Jugador - Limit training of Flying Machine to 10 for (Picked player)
Jugador - Limit training of Gryphon Rider to 10 for (Picked player)
Jugador - Limit training of Dragonhawk Rider to 10 for (Picked player)
Jugador - Limit training of Wind Rider to 10 for (Picked player)
Jugador - Limit training of Troll Batrider to 10 for (Picked player)
Jugador - Limit training of Gargoyle to 10 for (Picked player)
Jugador - Limit training of Frost Wyrm to 7 for (Picked player)
Jugador - Limit training of Destroyer to 7 for (Picked player)



as an example but i have the problem that the units that do upgrade can be bugged by making lot of the unit which is before then click in upgrade and they got a lot of them, surpacing the limit..

i want to do a trigger that is like:
player gets more than X of that unit, kill Z units for that player, until they return to X units.
 
Level 9
Joined
Apr 19, 2011
Messages
447
You can use this:

  • Limit Units
    • Events
      • Unit - A unit owned by Player 1 (red) Finish the training of a unit
    • Conditions
      • And - All (Conditions) are true
        • Conditions
          • (Unit-type of (Triggering unit)) Igual a [YOUR BUILDING]
          • (Unit-type of (Trained unit)) Igual a [YOUR UNIT]
          • (Number of units in (Units owned by Player 1 (red) of type [YOUR UNIT])) Igual a [UNIT LIMIT]
    • Actions
      • Unit - Remove (Trained unit) from the game
      • Player - Add [GOLD COST OF YOUR UNIT] to Player 1 (red) Current gold
      • Player - Add [LUMBER COST OF YOUR UNIT] to Player 1 (red) Current lumber
This should work. It'll prevent any unit trained over the limit to appear in the map, and it'll also prevent losing gold or lumber because of it.
Just make a trigger like this for each unit you want to limit.

And one more thing: you should post your triggers with
  • tags. That way, they will be easier to read.
  • Regards
 
Level 23
Joined
Apr 16, 2012
Messages
4,041
if you have on map initialization trigger, just add this to it:
  • Actions
    • For each (Integer A) from 1 to 12, do (Actions)
      • Loop - Actions
        • Trigger - Add to !Name of your trigger! the event (Unit - A unit owned by (Player((Integer A))) Finishes training a unit)
or if you don't then
  • Init
    • Events
      • Map initialization
    • Conditions
    • Actions
      • For each (Integer A) from 1 to 12, do (Actions)
        • Loop - Actions
          • Trigger - Add to !Name of your trigger! the event (Unit - A unit owned by (Player((Integer A))) Finishes training a unit)
but if you don't want to create another trigger you can just copy it and change the Players as well
 
Level 33
Joined
Mar 27, 2008
Messages
8,035
You can use this:

  • Limit Units
    • Events
      • Unit - A unit owned by Player 1 (red) Finish the training of a unit
    • Conditions
      • And - All (Conditions) are true
        • Conditions
          • (Unit-type of (Triggering unit)) Igual a [YOUR BUILDING]
          • (Unit-type of (Trained unit)) Igual a [YOUR UNIT]
          • (Number of units in (Units owned by Player 1 (red) of type [YOUR UNIT])) Igual a [UNIT LIMIT]
    • Actions
      • Unit - Remove (Trained unit) from the game
      • Player - Add [GOLD COST OF YOUR UNIT] to Player 1 (red) Current gold
      • Player - Add [LUMBER COST OF YOUR UNIT] to Player 1 (red) Current lumber
This should work. It'll prevent any unit trained over the limit to appear in the map, and it'll also prevent losing gold or lumber because of it.
Just make a trigger like this for each unit you want to limit.

And one more thing: you should post your triggers with
  • tags. That way, they will be easier to read.
  • Regards[/QUOTE]
  • [trigger](Number of units in (Units owned by Player 1 (red) of type [YOUR UNIT])) Igual a [UNIT LIMIT]
Unit Group leak.

  • Unit - Remove (Trained unit) from the game
I heard RemoveUnit leaks, that's why I hide the unit and kills it afterwards.

Don't use that, use this instead;
  • Untitled Trigger 001
    • Events
      • Unit - A unit Finishes training a unit
    • Conditions
      • (Unit-type of (Trained unit)) Equal to [YOUR UNIT-TYPE]
    • Actions
      • Set TempGroup = (Units owned by (Triggering player) of type [YOUR UNIT-TYPE])
      • Unit Group - Pick every unit in TempGroup and do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Number of units in TempGroup) Greater than [YOUR UNIT LIMIT]
            • Then - Actions
              • Unit - Hide (Trained unit)
              • Unit - Kill (Trained unit)
              • Player - Add [YOUR UNIT GOLD COST] to (Triggering player) Current gold
              • Player - Add [YOUR UNIT LUMBER COST] to (Triggering player) Current lumber
            • Else - Actions
      • Custom script: call DestroyGroup(udg_TempGroup)
Event is Unit - Generic Unit Event

By using this way, you won't have to add the additional looping trigger 12 times and such, this works for all players automatically.
Also, you need only 1 trigger.
 
Status
Not open for further replies.
Top