| 107 | |
| 108 | When you have your actions made, you need to bind them to a certain event. This is done via the predefined RegisterTrigger function. Triggers can be enabled in any method, but you usually need to enable some at the start of the game. You can use the following schema: |
| 109 | |
| 110 | {{{ |
| 111 | #!js |
| 112 | Trigger.prototype.InitGame = function(data) |
| 113 | { |
| 114 | var myData = {"enabled": true}; |
| 115 | this.RegisterTrigger("OnPlayerCommand", "MyAction", myData); |
| 116 | }; |
| 117 | }}} |
| 118 | |
| 119 | The first parameter of the trigger is the event on which it will be executed. In the example, the trigger will be executed for every player command. See the table below for a list of all possible events (TODO ''we do need that table''). The second parameter is the name of the action, which has to be defined under the Trigger prototype. And the third part is a data object. For most triggers, this data will be just enabled = true or false. But for more complicated triggers (range triggers, time triggers, ...) this data can contain other elements, such as the the distance of the range trigger, or the interval of the timer. Again, see the data in the table below. |
| 120 | |
| 121 | The combination of event and action name must be unique. This combination can be used to enable and disable triggers. Registering a trigger twice isn't possible, and tou will be warned when you do that. |
| 122 | |
| 123 | Enabling and disabling triggers happens as shown: |
| 124 | |
| 125 | {{{ |
| 126 | #!js |
| 127 | this.EnableTrigger("OnPlayerCommand", "MyAction"); |
| 128 | this.DisableTrigger("OnPlayerCommand", "MyAction"); |
| 129 | }}} |
| 130 | |
| 131 | You can enable and disable triggers as often as you want. |