Create custom unit abilities with triggers
By Yeebaagooon · retold
A scenario-design guide to constructing custom ability behavior through Retold triggers and an XS helper.
By Yeebaagooon
created 15/9/24
A common question asked by designers is: How do I give my unit custom abilities?
Sadly, transferring abilities from one unit to another is impossible without modding. But with triggers we can come very close and even add profound new special effects and powers.
This guide is in text and video format – please go here if you wish to watch the video.
The Setup:
Our concept revolves around the Protounit: Add Train effect. No, this doesn’t bring the Eurostar into AoM – but what it does do is allow a ‘parent’ unit to train a ‘child’ unit. This already happens ingame with a Set Pharaoh training animals. But we could have a medusa training villagers, or even villagers training medusae!
Choose a unit you don’t use in the game, it can be almost anything, even a grass or bush unit. We can then force this unit to have a new name, icon and stats so it reflects a single train button – an ability.
Please view the setup list below for the exact trigger effects you need to accomplish this. If we think through what is needed in our head:
- The unit must be allowed and trainable, then assigned to the parent.
- The child unit must be free.
- The child unit must have a build limit of one to prevent multiple use.
- The child unit must have a custom defined name, description and icon.
Setup list:
Protounit: Unforbid and enable – Unforbids the unit so the player can train it
Protounit: Add train – Allows training
Protounit: Modify resource data – Makes the unit free (do for all resources)
Protounit: Modify data – Set build limit, train points (recharge time) and population count (0)
Rate modify global: Train speed – Allows instant training so you can use the recharge time
Protounit: Set flag – Makes the unit invisible ingame (OnlyInEditor = on)
Protounit: Change name – Specify your ability name and desciprtion
Protounit: Set icon – Specify the icon of your ability
Now what?
Now we have our ability – we need to trigger it. This part is over to you and is completely dependent on your skill level and what you want your abilities to do. Naturally, the highest level of customisation is exclusive to XS code.
In the video above I did a speed boost and lightning storm ability. I talk through the effects in the video, but in essence we want:
Ability_On_Trigger
Active, no loop
Condition:
Player unit count (child unit) > 0
Effects:
Area: Change unit type – (child to sfx)
Protounit: Modify data – Modify child unit build limit -1 absolute or assign to 0
Desired effect (eg. +5 speed with protounit: modify data)
Trigger: Activate – Ability_Off_Trigger
Ability_Off_Trigger
Inactive, no loop
Condition:
Timer seconds: 10
Effects:
Protounit: Modify data – Modify child unit build limit +1 absolute or assign to 1
Desired effect opposite (eg. -5 speed with protounit: modify data)
Trigger: Activate – Ability_On_Trigger
XS Code
For advanced XS users – I have written a custom function that does all of this for you. It requires my Proto() function which is also listed since I find it easier to use constants for unit types rather than strings.
string Proto(int a = 0)
{
return(kbProtoUnitGetName(a));
}
void addTrain(string parent = "lol", string child = "lol", int row = 0, int col = 0, int traintime = 1, int player = 1){
int p = player;
trUnforbidProtounit(p, child);
trProtoUnitSetFlag(p, child, "OnlyInEditor", true);
trProtounitAddTrain(parent, p, child, row, col);
trModifyProtounitData(child, p, cXSProtoEffectBuildLimit, 1, cXSRelativityAssign);
trModifyProtounitData(child, p, cXSProtoEffectPopulationCount, 0, cXSRelativityAssign);
trModifyProtounitData(child, p, cXSProtoEffectTrainPoints, traintime, cXSRelativityAssign);
trModifyProtounitResource(child, "Food", p, 0, 0.0, cXSRelativityAssign);
trModifyProtounitResource(child, "Gold", p, 0, 0.0, cXSRelativityAssign);
trModifyProtounitResource(child, "Wood", p, 0, 0.0, cXSRelativityAssign);
trModifyProtounitResource(child, "Favor", p, 0, 0.0, cXSRelativityAssign);
}
Simply call the function as below and then change icon/despription as needed:
addTrain(Proto(cUnitTypeHoplite),Proto(cUnitTypeHippopotamusOfSet),0,0,15,1);
trProtoUnitChangeName(Proto(cUnitTypeHippopotamusOfSet), 1, "<color=1,0.5,0>SPEED BOOST</color>", "Gives you +5 speed for 10 seconds", "Gives you +5 speed for 10 seconds");
trProtoUnitSetIcon(Proto(cUnitTypeHippopotamusOfSet), 1, "resources\greek\static_color\technologies\winged_messenger_icon.png", "");
Back to the Advanced Section
Source: Yeebaagooon · HeavenGames