AgentPaper
From the depths, I come.
- Reaction score
- 107
This is a system I made to allow large amounts of units to be moved around with relative ease. The triggers will work with any units, with any abilities, though triggered stuff about them might cause bugs depending on what they do. With the max unit size of 12, you can select 12 squads of 12, allowing you to order 144 units at once. The triggers are heavily commented, to allow easy understanding of what does what.
This map is tested to work in single player with no problems found, but if you find any bugs or think it could be improved in any way, please post here. If you find a strange bug you think is related to this, it would help me greatly if you sent me a replay of the game. Remember I will need the map you played on as well to view the replay.
Readme from map:
Squad System v1.1b by AgentPaper
This system is meant to work with any units. No changes are needed with any of the triggers to allow new units to be used with this system, nor are changes needed in the units themselves. Feel free to change this system to suit your needs. If you want help with this system, or any triggers, contact me or anyone else at www.TheHelper.net. My username is AgentPaper.
The system works by creating more units of any unit created, except for heroes. These units are then organized into a "Squad", which will move, fight, and die together for the rest of the game. The number of units left in the squad is reflected by the health of the "Squad Leader". Any order given to one unit from the squad will make the whole squad obey that order. If any unit in the squad is selected, the squad leader will be selected instead.
Heroes can join squads by using the "Join Squad" ability on any unit in the desired squad. The hero will replace the squad leader, and act as the squad leader until the squad is destroyed, or the hero leaves with the "Leave Squad" ability. Note that in the current version, if the hero joins the squad, that squad can no longer use its special abilities, unless the hero has the same ability. Autocast and passive abilities will work as normal, though.
Special Thanks:
-Uberplayer (Memory Leaks)
To fix/add:
-Allow units commanded by a hero to use targetted abilities.
-Fix Siege Engine
Triggers:
Updates:
1.1b
-Fixed memory leaks
1.1
-Heroes can now join and leave units
-You can control how many units a squad of a certain unit type will spawn, by changing that unit's level to be the number of units to spawn, from 2 to 12. A level 1 unit will not make a squad.
1.0
-Basic system.
This map is tested to work in single player with no problems found, but if you find any bugs or think it could be improved in any way, please post here. If you find a strange bug you think is related to this, it would help me greatly if you sent me a replay of the game. Remember I will need the map you played on as well to view the replay.
Readme from map:
Squad System v1.1b by AgentPaper
This system is meant to work with any units. No changes are needed with any of the triggers to allow new units to be used with this system, nor are changes needed in the units themselves. Feel free to change this system to suit your needs. If you want help with this system, or any triggers, contact me or anyone else at www.TheHelper.net. My username is AgentPaper.
The system works by creating more units of any unit created, except for heroes. These units are then organized into a "Squad", which will move, fight, and die together for the rest of the game. The number of units left in the squad is reflected by the health of the "Squad Leader". Any order given to one unit from the squad will make the whole squad obey that order. If any unit in the squad is selected, the squad leader will be selected instead.
Heroes can join squads by using the "Join Squad" ability on any unit in the desired squad. The hero will replace the squad leader, and act as the squad leader until the squad is destroyed, or the hero leaves with the "Leave Squad" ability. Note that in the current version, if the hero joins the squad, that squad can no longer use its special abilities, unless the hero has the same ability. Autocast and passive abilities will work as normal, though.
Special Thanks:
-Uberplayer (Memory Leaks)
To fix/add:
-Allow units commanded by a hero to use targetted abilities.
-Fix Siege Engine
Triggers:
Trigger:
- Squad Initialization
- Events
- Time - Elapsed game time is 0.01 seconds
- Conditions
- Actions
- Game - Pause the game
- Game - Display to (All players) the text: Initializing Units
- Set Group = (Units in (Playable map area))
- Unit Group - Pick every unit in Group and do (Actions)
- Loop - Actions
- If (All Conditions are True) then do (Then Actions) else do (Else Actions)
- If - Conditions
- ((Picked unit) is A structure) Equal to False
- Or - Any (Conditions) are true
- Conditions
- (Level of (Picked unit)) Greater than 1
- ((Picked unit) is A Hero) Equal to True
- Conditions
- Then - Actions
- Set Unit = (Picked unit)
- Trigger - Run Create Squad <gen> (ignoring conditions)
- Wait 0.10 game-time seconds
- Else - Actions
- If - Conditions
- If (All Conditions are True) then do (Then Actions) else do (Else Actions)
- Loop - Actions
- Custom script: call DestroyGroup (udg_Group)
- Game - Unpause the game
- Custom script: call DestroyTrigger( GetTriggeringTrigger() )
- Events
Trigger:
- Create Squad
- Events
- Unit - A unit Finishes training a unit
- Conditions
- (Level of (Trained unit)) Greater than 1
- Actions
- If (All Conditions are True) then do (Then Actions) else do (Else Actions)
- If - Conditions
- Unit Equal to No unit
- Then - Actions
- -------- This is required to allow the Squad Initialization trigger to work. --------
- Set Unit = (Trained unit)
- -------- Stores the trained unit into the generic Unit variable, to make the rest of the trigger easier --------
- Else - Actions
- If - Conditions
- If (All Conditions are True) then do (Then Actions) else do (Else Actions)
- If - Conditions
- (Unit is A Hero) Equal to True
- Then - Actions
- Unit - Add Join Squad to Unit
- -------- Gives any heroes the "Join Squad" ability, which allows them to join units. --------
- Else - Actions
- -------- This loop checks through the Squad Leader array to find the first empty slot --------
- For each (Integer B) from 1 to 300, do (Actions)
- Loop - Actions
- If (All Conditions are True) then do (Then Actions) else do (Else Actions)
- If - Conditions
- SquadLeader[(Integer B)] Equal to No unit
- Then - Actions
- Set Num = (Integer B)
- -------- Stores the first unused squad number for use in the rest of the trigger --------
- Set SquadLeader[Num] = Unit
- -------- Makes the unit the squad leader --------
- Unit - Set the custom value of Unit to Num
- -------- Sets the squad leader's custom value to that of what the squad will be. --------
- Unit - Add Invulnerable (Neutral) to Unit
- -------- Makes the squad leader immune to all attacks. His health will represent the health of the squad, so he isn't actually invincible. --------
- Special Effect - Create a special effect attached to the overhead of Unit using Objects\InventoryItems\BattleStandard\BattleStandard.mdl
- -------- Puts a flag above the Squad Leader, to make him easier to spot. --------
- Set SquadSize[Num] = (Level of Unit)
- Set Point = (Position of Unit)
- Unit - Create (SquadSize[Num] - 1) (Unit-type of Unit) for (Owner of Unit) at Point facing Default building facing degrees
- -------- Creates the rest of the squad. The squad will be the same type of unit as the leader. --------
- Custom script: call RemoveLocation (udg_Point)
- Set Squad[Num] = (Last created unit group)
- -------- Sets the created units to the Squad variable, using Num as the index. --------
- Unit Group - Pick every unit in Squad[Num] and do (Actions)
- Loop - Actions
- Unit - Disable supply usage for (Picked unit)
- -------- Makes it so the sub-units in the squad do not use food. This can be disabled, but then the unit will use much more food. --------
- Unit - Set the custom value of (Picked unit) to Num
- -------- Sets the custom value of each of the sub-units, to keep track of what units are in what squads. --------
- Unit - Add classification of Summoned to (Picked unit)
- -------- All sub-units are classified as "Summoned" to seperate them from the squad leaders and non-squad units. --------
- Loop - Actions
- Unit Group - Add SquadLeader[Num] to Squad[Num]
- -------- Makes the squad leader to be part of the unit he leads. --------
- Trigger - Turn off Order Squad Point <gen>
- Trigger - Turn off Order Squad Object <gen>
- Set Point = (Rally-Point of (Triggering unit) as a point)
- -------- This is to ensure there can be no infinite loop. --------
- Unit Group - Order Squad[Num] to Attack-Move To Point
- -------- Makes the squad move to the rally point of the building the unit was trained in if it is set on the ground. --------
- Custom script: call RemoveLocation (udg_Point)
- Unit Group - Order Squad[Num] to Right-Click (Rally-Point of (Triggering unit) as a unit)
- -------- Makes the squad move to the rally point of the building the unit was trained in if the rally point is on a unit. --------
- Trigger - Turn on Order Squad Point <gen>
- Trigger - Turn on Order Squad Object <gen>
- -------- Turns the movement triggers back on. --------
- Set Unit = No unit
- Set Num = 0
- -------- Resets the variables used to prevent errors. --------
- Skip remaining actions
- -------- Prevents the trigger from running 300 times. Do not remove. --------
- Else - Actions
- If - Conditions
- If (All Conditions are True) then do (Then Actions) else do (Else Actions)
- Loop - Actions
- If - Conditions
- If (All Conditions are True) then do (Then Actions) else do (Else Actions)
- Events
Trigger:
- Death
- Events
- Unit - A unit Dies
- Conditions
- Actions
- Set Num = (Custom value of (Dying unit))
- -------- Num is an integer, set to the value of the squad we are dealing with. --------
- If (All Conditions are True) then do (Then Actions) else do (Else Actions)
- If - Conditions
- ((Dying unit) is Summoned) Equal to True
- Then - Actions
- -------- Checks if the unit dying is a sub-unit in a squad by checking it's classification. --------
- Unit Group - Remove (Dying unit) from Squad[Num]
- -------- Removes the unit from the squad, preventing him from counting as in the squad for the rest of the trigger. --------
- If (All Conditions are True) then do (Then Actions) else do (Else Actions)
- If - Conditions
- (Number of units in Squad[Num]) Less than or equal to 1
- Then - Actions
- -------- Checks if the squad is empty. --------
- If (All Conditions are True) then do (Then Actions) else do (Else Actions)
- If - Conditions
- (SquadLeader[Num] is A Hero) Equal to True
- Then - Actions
- -------- Checks if the squad leader is a hero. --------
- Unit - Set life of SquadLeader[Num] to 100.00%
- -------- Sets the hero's health to 100%, as his health is no longer meant to represent that of his squad. --------
- Unit Group - Remove SquadLeader[Num] from Squad[Num]
- -------- Removes the hero from the squad. --------
- Unit - Remove Invulnerable (Neutral) from SquadLeader[Num]
- -------- Removes the invulnerablility from being the leader of a squad. --------
- Unit - Remove Leave Squad from SquadLeader[Num]
- -------- Removes the Leave Squad ability from the hero, since he is no longer in a squad. --------
- Unit - Add Join Squad to SquadLeader[Num]
- -------- Gives the Join Squad ability to the hero, so he can join another squad. --------
- Unit - Set the custom value of SquadLeader[Num] to 0
- -------- Sets the hero's custom value to 0, to reflect his no longer being a squad. --------
- Else - Actions
- Unit - Explode SquadLeader[Num]
- -------- If the Squad Leader isn't a hero, he's useless, and so killed. (and in a gruesome matter, to boot!) --------
- If - Conditions
- Set SquadLeader[Num] = No unit
- Unit Group - Remove all units from Squad[Num]
- Set SquadSize[Num] = 0
- -------- Clears the squad variables. --------
- Else - Actions
- -------- If hero unit joining is disabled, move the below action out of the If/Then/Else statement, and the remove/disable the If/Then/Else statement. --------
- Unit - Set life of SquadLeader[Num] to (((Real((Number of units in Squad[Num]))) / (Real(SquadSize[Num]))) x 100.00)%
- -------- Set's the squad leader's health to reflect how many units remain in the squad. --------
- If - Conditions
- Else - Actions
- If - Conditions
- Set Num = 0
- -------- Resets the variables used to prevent errors. --------
- Events
Trigger:
- Selection
- Events
- Player - Player 1 (Red) Selects a unit
- Player - Player 2 (Blue) Selects a unit
- Player - Player 3 (Teal) Selects a unit
- Player - Player 4 (Purple) Selects a unit
- Player - Player 5 (Yellow) Selects a unit
- Player - Player 6 (Orange) Selects a unit
- Player - Player 7 (Green) Selects a unit
- Player - Player 8 (Pink) Selects a unit
- Player - Player 9 (Gray) Selects a unit
- Player - Player 10 (Light Blue) Selects a unit
- Player - Player 11 (Dark Green) Selects a unit
- Player - Player 12 (Brown) Selects a unit
- Conditions
- Actions
- Set Group = (Units currently selected by (Triggering player))
- Unit Group - Pick every unit in Group and do (Actions)
- Loop - Actions
- If (All Conditions are True) then do (Then Actions) else do (Else Actions)
- If - Conditions
- ((Picked unit) is Summoned) Equal to True
- Then - Actions
- -------- Checks if the selcted unit is a sub-unit, by checking it's classification. --------
- Selection - Remove (Picked unit) from selection for (Triggering player)
- -------- Removes the unit from selection. --------
- Selection - Add SquadLeader[(Custom value of (Picked unit))] to selection for (Triggering player)
- -------- Adds the squad leader of the unit to the selection. --------
- Else - Actions
- If - Conditions
- If (All Conditions are True) then do (Then Actions) else do (Else Actions)
- Loop - Actions
- Custom script: call DestroyGroup (udg_Group)
- Events
Trigger:
- Hero Join Squad
- Events
- Unit - A unit Begins casting an ability
- Conditions
- (Ability being cast) Equal to Join Squad
- (SquadLeader[(Custom value of (Target unit of ability being cast))] is A Hero) Equal to False
- ((Target unit of ability being cast) is A flying unit) Equal to False
- ((Target unit of ability being cast) is Mechanical) Equal to False
- Actions
- -------- Checks if the ability is the Join Unit ability, to prevent errors. --------
- -------- Checks if the squad is already led by a hero. This ensures that there are no units led by 2 heros. --------
- -------- The last 2 check to make sure the target squad isn't of fliers or mechanical units, including ships. --------
- Set Num = (Custom value of (Target unit of ability being cast))
- -------- Num is an integer, set to the value of the squad we are dealing with. --------
- Set Hero = (Casting unit)
- -------- Hero is a unit variable, set to be the hero joining the unit. --------
- Unit - Set life of Hero to (Percentage life of SquadLeader[Num])%
- -------- Sets the hero's life to what the old squad leader's life was. --------
- Unit - Set Hero movement speed to (Default movement speed of SquadLeader[Num])
- -------- Sets the hero's movement speed to be the same as his unit, so he can keep up. --------
- Set Point = (Position of SquadLeader[Num])
- Unit Group - Remove SquadLeader[Num] from Squad[Num]
- Unit - Remove SquadLeader[Num] from the game
- -------- Removes the normal squad leader from the game. --------
- Unit - Move Hero instantly to Point
- -------- Moves the hero into the squad he is joining. --------
- Custom script: call RemoveLocation (udg_Point)
- Unit - Set the custom value of Hero to Num
- -------- Sets the custom value of the hero to reflect the squad he has joined. --------
- Unit - Add Invulnerable (Neutral) to Hero
- -------- Makes the hero invulnerable, as his health will now reflect that of his squad. --------
- Unit - Remove Join Squad from Hero
- -------- Removes the "Join Squad" ability from the hero, since he is now in a squad. --------
- Unit - Add Leave Squad to Hero
- -------- Adds the "Leave Squad" ability to the hero, so that he can leave his squad. --------
- Set SquadLeader[Num] = Hero
- -------- Sets the hero as the squad leader of the unit he is joining. --------
- Unit Group - Add Hero to Squad[Num]
- -------- Adds the hero to the squad he's joining. --------
- Set Num = 0
- Set Hero = No unit
- -------- Resets the variables used to prevent errors. --------
- Events
Trigger:
- Hero Leave Squad
- Events
- Unit - A unit Begins casting an ability
- Conditions
- (Ability being cast) Equal to Leave Squad
- Actions
- Set Hero = (Casting unit)
- -------- Hero is a unit variable, set to be the hero joining the unit. --------
- Set Num = (Custom value of Hero)
- -------- Num is an integer, set to the value of the squad we are dealing with. --------
- -------- --------
- Unit Group - Remove Hero from Squad[Num]
- -------- Removes the hero from the squad. --------
- Unit - Remove Invulnerable (Neutral) from Hero
- -------- Removes the invulnerablility from being the leader of a squad. --------
- Unit - Set the custom value of Hero to 0
- -------- Sets the hero's custom value to 0, to reflect his no longer being a squad. --------
- -------- --------
- Set Point = (Position of (Random unit from Squad[Num]))
- Unit - Create 1 (Unit-type of (Random unit from Squad[Num])) for (Owner of Hero) at Point facing Default building facing degrees
- -------- Creates a new Squad Leader. --------
- Custom script: call RemoveLocation (udg_Point)
- Set Unit = (Last created unit)
- -------- Stores the trained unit into the generic Unit variable, to make the rest of the trigger easier --------
- Set SquadLeader[Num] = Unit
- -------- Makes the unit the squad leader --------
- Unit - Set the custom value of Unit to Num
- -------- Sets the squad leader's custom value to that of what the squad will be. --------
- Unit - Add Invulnerable (Neutral) to Unit
- -------- Makes the squad leader immune to all attacks. His health will represent the health of the squad, so he isn't actually invincible. --------
- Special Effect - Create a special effect attached to the overhead of Unit using Objects\InventoryItems\BattleStandard\BattleStandard.mdl
- -------- Puts a flag above the Squad Leader, to make him easier to spot. --------
- Unit Group - Add Unit to Squad[Num]
- -------- Makes the squad leader to be part of the unit he leads. --------
- Unit - Set life of Unit to (Percentage life of Hero)%
- -------- Sets the new squad leader's life to what the hero's life was. --------
- -------- --------
- Unit - Set life of Hero to 100.00%
- -------- Sets the hero's health to 100%, as his health is no longer meant to represent that of his squad. --------
- Unit - Remove Leave Squad from Hero
- -------- Removes the Leave Squad ability from the hero, since he is no longer in a squad. --------
- Unit - Add Join Squad to Hero
- -------- Gives the Join Squad ability to the hero, so he can join another squad. --------
- -------- --------
- Set Unit = No unit
- Set Hero = No unit
- Set Num = 0
- -------- Resets the variables used to prevent errors. --------
- Events
Trigger:
- Order Squad None
- Events
- Unit - A unit Is issued an order with no target
- Conditions
- (Custom value of (Ordered unit)) Not equal to 0
- Actions
- Set Num = (Custom value of (Ordered unit))
- -------- Num is an integer, set to the value of the squad we are dealing with. --------
- Set Order = (String((Issued order)))
- -------- Order is a string, used to hold the order we will give to the squad later. --------
- Trigger - Turn off (This trigger)
- -------- This is to ensure there can be no infinite loop. --------
- Custom script: call GroupImmediateOrder( udg_Squad[udg_Num], udg_Order )
- -------- This custom text orders the squad to do the order specified earlier. --------
- Trigger - Turn on (This trigger)
- -------- Turns the movement triggers back on. --------
- Set Order = <Empty String>
- Set Num = 0
- -------- Resets the variables used to prevent errors. --------
- Events
Trigger:
- Order Squad Point
- Events
- Unit - A unit Is issued an order targeting a point
- Conditions
- (Custom value of (Ordered unit)) Not equal to 0
- Actions
- Set Num = (Custom value of (Ordered unit))
- -------- Num is an integer, set to the value of the squad we are dealing with. --------
- Set Order = (String((Issued order)))
- -------- Order is a string, used to hold the order we will give to the squad later. --------
- Trigger - Turn off (This trigger)
- -------- This is to ensure there can be no infinite loop. --------
- Custom script: set udg_Point = GetOrderPointLoc()
- Custom script: call GroupPointOrderLoc( udg_Squad[udg_Num], udg_Order, udg_Point )
- Custom script: call RemoveLocation(udg_Point)
- -------- This custom text orders the squad to do the order specified earlier at the same point as the ordered unit. --------
- Trigger - Turn on (This trigger)
- -------- Turns the movement triggers back on. --------
- Set Order = <Empty String>
- Set Num = 0
- -------- Resets the variables used to prevent errors. --------
- Events
Trigger:
- Order Squad Object
- Events
- Unit - A unit Is issued an order targeting an object
- Conditions
- (Custom value of (Ordered unit)) Not equal to 0
- Actions
- Set Num = (Custom value of (Ordered unit))
- -------- Num is an integer, set to the value of the squad we are dealing with. --------
- Set Order = (String((Issued order)))
- -------- Order is a string, used to hold the order we will give to the squad later. --------
- Trigger - Turn off (This trigger)
- -------- This is to ensure there can be no infinite loop. --------
- Custom script: call GroupTargetOrder( udg_Squad[udg_Num], udg_Order, GetOrderTargetUnit() )
- -------- This custom text orders the squad to do the order specified earlier on the same object as the ordered unit. --------
- Trigger - Turn on (This trigger)
- -------- Turns the movement triggers back on. --------
- Set Order = <Empty String>
- Set Num = 0
- -------- Resets the variables used to prevent errors. --------
- Events
Updates:
1.1b
-Fixed memory leaks
1.1
-Heroes can now join and leave units
-You can control how many units a squad of a certain unit type will spawn, by changing that unit's level to be the number of units to spawn, from 2 to 12. A level 1 unit will not make a squad.
1.0
-Basic system.