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

Spawn units based on limited food supplies

Status
Not open for further replies.
Level 4
Joined
May 1, 2011
Messages
81
Hi there, everyone. I want to spawn a unit (take for instance Siege Engine) for every 15 seconds. Each of this unit takes up 5 foods.

I have 3 Farms, each supplies 10 foods. Therefore, it has 30 foods supplied overall.

How do I stop the spawning function once the food used reaches the food supplied? It doesn't have to be 30. What happens if one or two of the Farm is destroyed and the food supplies reduces to 20 or 10 or 0? Basically I want this function implemented such that it will be almost the same as training normal units under the numbers of food supplied but using the "Unit - Create Units" action instead.

I hope my question has made it clear for you. I will be appreciated if anyone can help me with this. Thank you.
 
Level 13
Joined
Dec 21, 2010
Messages
541
You need a variable integer for the unit ex: Food_Siege then whenever you create 1 Siege engine.. set - Food_Siege + 5
and another variable integer for the food limit ex: Food_Max set it to (10 x how many farms you have)..

Create two triggers that has an event of Unit Dies ex: Farm Dies and Siege Dies
  • Event
    • Unit - Dies
  • Conditions
    • (Unit type of (Dying unit)) Equal to Farm
  • Actions
    • Set - Food_Max = Food_Max - 10
  • Event
    • Unit - Dies
  • Conditions
    • (Unit type of (Dying unit)) Siege Engine
  • Actions
    • Set - Food_Siege = Food_Siege - 5
Create a trigger that checks the food every seconds... so you can check whether your food limit is decreased... Another variable integer for the spawning of the siege engine ex: Time_Spawn
  • Event
    • Time - Every 1.00 seconds of game time
  • Conditions
  • Actions
    • Set - Time_Spawn = Time_Spawn + 1
    • If (All Conditions are True) Then do (Then Actions) else
      • Food_Max Greater than Food_Siege
      • Time_Spawn Equal to 15
    • Then - Actions
      • Set - Temp_Point = (Center of (Playable map area))
      • Unit - Create 1 Siege Engine for Player 1 (Red) at (Temp_Point) facing Default building facing degrees
      • Custom script: call RemoveLocation (udg_Temp_Point)
      • Set - Time_Spawn = 0
      • Set - Food_Siege + 5
      • Else - Actions
 
Last edited:
Level 21
Joined
Mar 27, 2012
Messages
3,232
Try something like this:
  • Multiple FunctionsIf (All Conditions are True) then do (Then Actions) else do (Else Actions)
    • If - Conditions
      • ((Player 1 (Red) Food used) + 5) Less than or equal to (<=) (Player 1 (Red) Food cap)
    • Then - Actions
    • Else - Actions
You might have to replace food cap with food max, I'm not sure.
Essentially this condition checks if after training a unit that takes some food(5) you'd still be within the limit.
 
Level 4
Joined
May 1, 2011
Messages
81
You need a variable integer for the unit ex: Food_Siege then whenever you create 1 Siege engine.. set - Food_Siege + 5
and another variable integer for the food limit ex: Food_Max set it to (10 x how many farms you have)..

Create two triggers that has an event of Unit Dies ex: Farm Dies and Siege Dies
  • Event
    • Unit - Dies
  • Conditions
    • (Unit type of (Dying unit)) Equal to Farm
  • Actions
    • Set - Food_Max = Food_Max - 10
  • Event
    • Unit - Dies
  • Conditions
    • (Unit type of (Dying unit)) Siege Engine
  • Actions
    • Set - Food_Siege = Food_Siege - 5
Create a trigger that checks the food every seconds... so you can check whether your food limit is decreased... Another variable integer for the spawning of the siege engine ex: Time_Spawn
  • Event
    • Time - Every 1.00 seconds of game time
  • Conditions
  • Actions
    • Set - Time_Spawn = Time_Spawn + 1
    • If (All Conditions are True) Then do (Then Actions) else
      • Food_Max Greater than Food_Siege
      • Time_Spawn Equal to 15
    • Then - Actions
      • Set - Temp_Point = (Center of (Playable map area))
      • Unit - Create 1 Siege Engine for Player 1 (Red) at (Temp_Point) facing Default building facing degrees
      • Custom script: call RemoveLocation (udg_Temp_Point)
      • Set - Time_Spawn = 0
      • Set - Food_Siege + 5
      • Else - Actions


I modified some triggers, but thanks a lot! It worked.

Related question, now how should I apply all of these integer variables (Food_Max, Food_Used etc.) to other units that I will be spawning them simultaneously with Siege Engine? Besides Siege Engine, I also want to spawn a Rifleman (cost 3 foods) for every 10 secs and a Footman (cost 2) for every 5 secs under the same condition.
 
Level 4
Joined
May 1, 2011
Messages
81
Try something like this:
  • Multiple FunctionsIf (All Conditions are True) then do (Then Actions) else do (Else Actions)
    • If - Conditions
      • ((Player 1 (Red) Food used) + 5) Less than or equal to (<=) (Player 1 (Red) Food cap)
    • Then - Actions
    • Else - Actions
You might have to replace food cap with food max, I'm not sure.
Essentially this condition checks if after training a unit that takes some food(5) you'd still be within the limit.


It didn't work for food cap tho. It keeps spawning the units even though it exceeds more than 100.
Also I don't think its food max as well because it's actually means the game maximum food limit, which is 100. If replace with food max and if I destroyed several Farms to decrease the total food supply to 88, they will still spawn the Siege Engine until it reaches 100 (or 95).
 
Level 21
Joined
Mar 27, 2012
Messages
3,232
I placed a farm and made this simple trigger:
  • Per
    • Events
      • Time - Every 2.00 seconds of game time
    • Conditions
    • Actions
      • Multiple FunctionsIf (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • ((Player 1 (Red) Food used) + 2) Less than or equal to (<=) (Player 1 (Red) Food cap)
        • Then - Actions
          • Unit - Create 1 Footman for Player 1 (Red) at (Center of (Playable map area)) facing Default building facing (270.0) degrees
        • Else - Actions
The units stopped spawning when the limit was reached.
 
Level 13
Joined
Dec 21, 2010
Messages
541
I modified some triggers, but thanks a lot! It worked.

Related question, now how should I apply all of these integer variables (Food_Max, Food_Used etc.) to other units that I will be spawning them simultaneously with Siege Engine? Besides Siege Engine, I also want to spawn a Rifleman (cost 3 foods) for every 10 secs and a Footman (cost 2) for every 5 secs under the same condition.

If you want this for each player to work... you need all variables in array ,,, Create a Non-Array Variable Integer ex: Temp_Player ..and Time_Loop (you need this to loop the players)

  • Dead Units
  • Events
    • Unit - Dies
  • Conditions
  • Actions
    • Set - Temp_Player = (Player Number of owner of (triggering unit))
    • If (All Conditions are True) Then do (Then Actions) else
      • (Unit type of (Triggering unit)) Equal to Farm
    • Then - Actions
      • Set - Food_Max[Temp_Player] = Food_Max[Temp_Player] - 10
    • Else - Actions
    • -------- Siege Engine --------
    • If (All Conditions are True) Then do (Then Actions) else
      • (Unit type of (Triggering unit)) Equal to Siege Engine
    • Then - Actions
      • Set - Food_Limit[Temp_Player] = Food_Limit[Temp_Player] - 5
    • Else - Actions
    • -------- Rifleman --------
    • If (All Conditions are True) Then do (Then Actions) else
      • (Unit type of (Triggering unit)) Equal to Rifleman
    • Then - Actions
      • Set - Food_Limit[Temp_Player] = Food_Limit[Temp_Player] - 3
    • Else - Actions
    • -------- Footman --------
    • If (All Conditions are True) Then do (Then Actions) else
      • (Unit type of (Triggering unit)) Equal to Footman
    • Then - Actions
      • Set - Food_Limit[Temp_Player] = Food_Limit[Temp_Player] - 2
    • Else - Actions
  • Spawn Loop
  • Events
    • Time - Every 1.00 seconds of game time
  • Conditions
  • Actions
    • For each (Time_Loop) from 1 to 10, do (Actions)
      • Loop - Actions
        • Set - Time_Spawn[Time_Loop] = Time_Spawn[Time_Loop] + 1
        • If (All Conditions are True) Then do (Then Actions) else
          • Food_Max[Time_Loop] Greater than Food_Limit[Time_Loop]
        • Then - Actions
          • -------- Siege Engine --------
          • If (All Conditions are True) Then do (Then Actions) else
            • Time_Spawn[Time_Loop] Equal to 15
          • Then - Actions
            • Set - Temp_Point = (Center of (Playable map area))
            • Unit - Create 1 Siege Engine for (Player(Time_Loop)) at (Temp_Point) facing Default building facing degrees
            • Custom script: call RemoveLocation (udg_Temp_Point)
            • Set - Time_Spawn[Time_Loop] = 0
            • Set - Food_Limit[Time_Loop] + 5
          • Else - Actions
          • -------- Rifleman --------
          • If (All Conditions are True) Then do (Then Actions) else
            • Time_Spawn[Time_Loop] Equal to 10
          • Then - Actions
            • Set - Temp_Point = (Center of (Playable map area))
            • Unit - Create 1 Rifleman for (Player(Time_Loop)) at (Temp_Point) facing Default building facing degrees
            • Custom script: call RemoveLocation (udg_Temp_Point)
            • Set - Food_Limit[Time_Loop] + 3
          • Else - Actions
          • -------- Footman --------
          • If (All Conditions are True) Then do (Then Actions) else
            • Time_Spawn[Time_Loop] Equal to 5
          • Then - Actions
            • Set - Temp_Point = (Center of (Playable map area))
            • Unit - Create 1 Footman for (Player(Time_Loop)) at (Temp_Point) facing Default building facing degrees
            • Custom script: call RemoveLocation (udg_Temp_Point)
            • Set - Food_Limit[Time_Loop] + 2
          • Else - Actions
        • Else - Actions
Don't forget to increase the Food_Max whenever you create a farm..
 
Last edited:
Level 13
Joined
Dec 21, 2010
Messages
541
Once more, the food max variable is useless, because there already is an action that checks the current lumber,gold, food available, food max and food cap.

I think he doesn't want to use THOSE...because of what he said "Basically I want this function implemented such that it will be ALMOST THE SAME AS training normal units under the numbers of food supplied but using the "Unit - Create Units" action instead" meaning the units doesn't really have a FOOD USED..nor farms that supplies FOOD CAP..
 
Level 25
Joined
May 11, 2007
Messages
4,651
I win.
  • Stop Overcomplicating Shit
    • Events
      • Time - Every 15.00 seconds of game time
    • Conditions
    • Actions
      • Set tempPlayer = Player 1 (Red)
      • -------- Set tempPlayer to whichever player you want to spawn the siege engines for --------
      • -------- Copy the trigger and change the tempPoint and tempPlayer if you want it to work for more than 1 player --------
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (tempPlayer Food used) Less than or equal to ((tempPlayer Food cap) - (Supply used by Siege Engine))
        • Then - Actions
          • Set tempPoint1 = (Random point in PLAYER1 SPAWN <gen>)
          • Unit - Create 1 Siege Engine for tempPlayer at tempPoint1 facing 0.00 degrees
          • Custom script: call RemoveLocation (udg_tempPoint1)
        • Else - Actions
 
Status
Not open for further replies.
Top