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

[Solved] How to get the full food cost of a Squad ?

Level 3
Joined
Feb 2, 2025
Messages
11
I'm currently working on a map that tries to mimic some mechanics from Battle for Middle Earth 2 (mainly the squad-based units and the income at regular intervals from main base and supply buildings). While the squad system i use works flawlessly when my defined squads are on the field, i have an issue : when recruiting the squads I only get the food cost of a single individual that is part of it (In a squad of 8 footmen that cost 1 food each, i only get the food cost of 1 on the squad's recruitment button in the barracks).

What should I do for the recruitment button to account for the food cost of the entire squad ?

here's the link to the squad system i'm using : Squad System v0.9.8
 

Uncle

Warcraft Moderator
Level 73
Joined
Aug 10, 2018
Messages
7,876
Let's say that:
1) An individual Footman costs 1 food.
2) Training a single Footman from a Barracks will actually produce 5 and form a squad.

Assuming the system doesn't provide this already, here's my solution:

Go into the Object Editor and change the Footman's Food Cost to 5. Then manage the Food Used by an individual Footman using triggers:
  • Disable Food Used
    • Events
      • Unit - A unit enters (Playable map area)
    • Conditions
      • (Unit-type of (Triggering unit)) Equal to Footman
    • Actions
      • Set VariableSet Food_Unit = (Triggering unit)
      • Unit - Disable supply usage for Food_Unit.
  • Add Food Used
    • Events
      • Unit - A unit Finishes training a unit
    • Conditions
      • (Trained unit-type) Equal to Footman
    • Actions
      • Set VariableSet Food_Unit = (Trained unit)
      • Set VariableSet Food_Player = (Owner of Food_Unit)
      • Unit - Disable supply usage for Food_Unit.
      • Player - Set Food_Player.Food used to ((Food_Player Food used) + 5)
  • Remove Food Used
    • Events
      • Unit - A unit Dies
    • Conditions
      • (Unit-type of (Triggering unit)) Equal to Footman
    • Actions
      • Set VariableSet Food_Unit = (Triggering unit)
      • Set VariableSet Food_Player = (Owner of Food_Unit)
      • Player - Set Food_Player.Food used to ((Food_Player Food used) - 1)
This doesn't account for pre-placed units but that can be done with a simple "Elapsed time is 0.00 seconds -> Pick every unit -> Disable supply usage for (Picked unit)" trigger.

Also, this would ideally be setup to use a database, for example a Hashtable, where you save each Unit-Types:
1: Individual food cost (how much food a single Unit should use, so 1 for an individual Footman).
2: Squad food cost (the Object Editor value, so 5 when training a Footman from a Barracks).
3: Any other data you wish to track about that Unit-Type (optional).
  • Events
    • Time - Elapsed game time is 0.00 seconds
  • Conditions
  • Actions
    • -------- First and foremost, create the Hashtable: --------
    • Hashtable - Create a hashtable
    • Set Variable Food_Hashtable = (Last created hashtable)
    • -------- --------
    • -------- Now proceed to store each Unit-Type that uses this system: --------
    • -------- --------
    • -------- FOOTMAN (assuming 5 in a squad and each costs 1) --------
    • Set Variable Food_Unit_Type = Footman
    • Set Variable Food_Individual_Cost = 1
    • Set Variable Food_Squad_Cost = 5
    • Custom script: set udg_Food_ID = udg_Food_Unit_Type
    • Hashtable - Save Food_Invidual_Cost as 1 of Food_ID in Food_Hashtable
    • Hashtable - Save Food_Squad_Cost as 2 of Food_ID in Food_Hashtable
    • -------- --------
    • -------- RIFLEMAN (assuming 3 in a squad and each costs 2) --------
    • Set Variable Food_Unit_Type = Rifleman
    • Set Variable Food_Individual_Cost = 2
    • Set Variable Food_Squad_Cost = 6
    • Custom script: set udg_Food_ID = udg_Food_Unit_Type
    • Hashtable - Save Food_Invidual_Cost as 1 of Food_ID in Food_Hashtable
    • Hashtable - Save Food_Squad_Cost as 2 of Food_ID in Food_Hashtable
  • Events
    • Unit - A unit Finishes training a unit
  • Conditions
  • Actions
    • Set Variable Food_Unit = (Trained unit)
    • Custom script: set udg_Food_ID = GetUnitTypeId(udg_Food_Unit)
    • Set Variable Food_Individual_Cost = (Load 1 of Food_ID from Food_Hashtable)
    • If (Food_Individual_Cost Equal to 0) Then (Skip remaining actions) Else (Do nothing)
    • Set Variable Food_Squad_Cost = (Load 2 of Food_ID from Food_Hashtable)
^ This requires an Integer variable called Food_ID, which I use in the Custom Script to get the Integer form of a Unit-Type.

Lastly, there's likely a way to use information provided by the squad system to improve this whole process.
 
Last edited:
Level 3
Joined
Feb 2, 2025
Messages
11
ok, I should have mentionned that i'm a complete noob when it comes to triggers and scripts. The first 3 triggers you showed worked fine. But i'm now having trouble with how to use the hashtable.
 

Uncle

Warcraft Moderator
Level 73
Joined
Aug 10, 2018
Messages
7,876
Here's a working setup you can use.

All you have to worry about is continuing to Register the Squads in the system like you have been doing.

Then Registering their Unit-Types to my "extension" using this Trigger:
  • Squad Extension Setup
    • Events
      • Time - Elapsed game time is 0.00 seconds
    • Conditions
    • Actions
      • Hashtable - Create a hashtable
      • Set VariableSet Squad_Hash = (Last created hashtable)
      • -------- --------
      • -------- ====================================================== --------
      • -------- Register all of the Unit-Types to the system: --------
      • -------- ====================================================== --------
      • -------- --------
      • Set VariableSet Squad_Unit_Type = Footman
      • Set VariableSet Squad_Individual_Food_Cost = 1
      • Set VariableSet Squad_Group_Food_Cost = 5
      • Trigger - Run Squad Register New Unit Type <gen> (ignoring conditions)
      • -------- --------
      • Set VariableSet Squad_Unit_Type = Rifleman
      • Set VariableSet Squad_Individual_Food_Cost = 2
      • Set VariableSet Squad_Group_Food_Cost = 6
      • Trigger - Run Squad Register New Unit Type <gen> (ignoring conditions)
      • -------- --------
      • -------- Add more as needed... --------
      • -------- --------
      • -------- RUN THIS LAST! --------
      • Trigger - Run Squad Add Preplaced Units <gen> (ignoring conditions)
Read the --- Comments --- in the triggers to get a better understanding of what to do and how it all works.

If the Trigger ends up getting too full you can break it up into multiple triggers, for example:
  • Squad Extension Setup
    • Events
      • Time - Elapsed game time is 0.00 seconds
    • Conditions
    • Actions
      • Hashtable - Create a hashtable
      • Set VariableSet Squad_Hash = (Last created hashtable)
      • -------- --------
      • -------- ====================================================== --------
      • -------- Register all of the Unit-Types to the system: --------
      • -------- ====================================================== --------
      • -------- --------
      • Trigger - Run Register Human Unit Types <gen> (ignoring conditions)
      • Trigger - Run Register Orc Unit Types <gen> (ignoring conditions)
      • Trigger - Run Register Undead Unit Types <gen> (ignoring conditions)
      • Trigger - Run Register Night Elf Unit Types <gen> (ignoring conditions)
      • -------- --------
      • -------- Add more as needed... --------
      • -------- --------
      • -------- RUN THIS LAST! --------
      • Trigger - Run Squad Add Preplaced Units <gen> (ignoring conditions)
In each of those Race triggers you would use the pattern from the previous trigger to Register a bunch of different Unit Types at once. Just make sure that you maintain the order of the Actions so that the Hashtable is created at the very beginning and RUN THIS LAST happens at the very end of this trigger.
 

Attachments

  • SquadSystem v0.9.8 uncle ext.w3m
    49.2 KB · Views: 2
Last edited:
Top