Triggers in RMS
From AgeofWiki
Triggers can be used to make your script more than a standard Supremacy/Death Match game and add events and interactivity to it. They are mainly used in scenarios, but can also be used in random maps. If you haven't tried using triggers before, you should open the scenario editor and make a couple of them before trying to use them in a random map script. Visit the Scenario Editor FAQ for information on how triggers work in scenarios. The various RMS guides list the different RMS functions to do with triggers but do not really explain all aspects of using triggers in RMS, so this section will cover some common questions on triggers.
A trigger is essentially a "rule" that has several conditions and several effects. If the trigger is active and all its conditions are true, then it will fire and perform its effects. If the trigger is looping, it will be able to fire again when the conditions become true again; if not, it will only fire once during the course of the game, and then be deactivated (it may be activated again later by another trigger, however). Triggers can be marked as run immediately to fire their events before the game even begins (for example, a trigger that grants or disables technologies for players should do this); such triggers should not be looping and should not have any conditions. Triggers that run in-game can have a priority between 1 and 5, which dictates how often the game checks their conditions (it should only be higher for triggers that need precise timing; the default value of 3 works fine otherwise).
Note that all of your triggers need a name, and each trigger should have a unique name. If two triggers have the same name, you'll get an error. Usually it is simple to come up with a unique name for each trigger, but if you have a variable number of triggers you might want to keep a global "uniqueID" integer variable; then name each new trigger "trigger_"+uniqueID, and increase uniqueID by 1 after you use it, or even create a makeUniqueID() function that increases the variable by 1 and returns it. This can also be a useful technique when placing areas or object definitions, since they must also have unique names.
A few Questions
Q: I get weird text when trying to use "%" characters in in-game messages. Why? A: Use a double percent sign (%%) if you want to print a percent sign. Percent signs in strings have a special meaning in C++, the language in which AoEIII was written, so you shouldn't have single percent signs in an in-game message string.
Q: What is the last (bool) parameter in rmAddTriggerConditionParam and rmAddTriggerEffectParam? A: This value should always be false. It's used internally by AoEIII.
Q: Trigger code in RMS is so long and messy! How can I make it quicker to develop? A: Use functions, lots and lots of them. For example, I made a grantTech function which simply adds a trigger effect for enabling a certain tech (it will be added to whatever trigger is active when the function is called), and a sendChat function which adds a send chat effect. In general, anything repetitive and time-consuming should be put in a function. It saves a lot of typing!
Variables | Control Statements | Functions | Triggers in RMS | Arrays | Math Functions
