Triggers - Adding a 'Add Event to Trigger' Action

Tutorial by Dave312

Adding a 'Add Event to Trigger' Action
By Dave312
v1.0



The aim behind this tutorial is to teach you make use of the hidden native actions that are not available by default for use in GUI triggering. The example I will be demonstrating will be for making an Add Event to Trigger Action.

The first step is to decide which event this action will handle. I will be using the Unit Enters/Leaves Region Event, however these same steps can be applied and used for other events as well as any other native actions not available in the GUI.

Ok so open up your map, and then open up the console (Window -> Console). Type in browse to bring up the Archive Browser (you can type help into the console to bring up a list of available commands). You now need to navigate down to the natives.galaxy file which is located under the TriggerLibs folder.

(Image)



Now you need to find the action you want to create. This file is split up into various sections which should help you find your action. Mine is of the type Unit so I'll will want to look under the unit section. It is not always easy to find what you want so you may want to try using the find function (crtl+f). I have found my action and it is shown below. Note that all Add Event to Trigger Actions start with TriggerAddEvent.
native void     TriggerAddEventUnitRegion (trigger t, unitref u, region r, bool state);

What you need to pay attention of here is the name of the action and the parameters specified.

Now open up the Triggers Window (don't close the Archive Browser as you will need to reference it later). Click on the New Action Definition icon on the toolbar (or Ctrl+Alt+R) to add your new action and name it whatever you want. I'm calling mine Add Event Unit Enters Region to Trigger. Now select the name of your trigger in the right-hand pane and uncheck the Based On Name property. You need to change the script identifier to the name of the action in the natives.galaxy file. For me, this becomes TriggerAddEventUnitRegion.

(Image)



Now you need to modify the Options property and check Native as we are referencing a native action. Leave the rest unchecked. Now here is the tricky bit. For every parameter listed the natives.galaxy file, you need to add a corresponding parameter to your action. You can call the parameters whatever you want but you will need to change the script identifier to the name given in the natives.galaxy file. So for my first parameter, it says trigger t. The first word represents the type (Trigger), and the second word represents the script identifier (t). If your not sure of some of the types, just take a look at the Event you are trying to add and you should be able to work it out. Also note that for my last parameter, it is listed as bool (boolean) with a script identifier of state. If you look at the actual event, the boolean parameter represents the option Enters/Leaves. Because there are only 2 options to choose from (Enters or Leaves), the Region Enter/Leave State is marked as a boolean in the natives.galaxy file. If there were more options, it would be marked as an int (integer). For this reason, I have not chosen to use a type boolean parameter but the preset Region Enter/Leave State.

(Image)



Finally, if say I wanted to not have to choose a specific unit for the unit parameter of my action, but rather use the preset Any Unit, I can allow this by selecting the parameter, then going to the bottom right-hand corner where it says Allowed Presets. I can then add my desired preset (right-click -> Add Preset...) here.

Now you can test your action to see if it works (the action can be found under the - General section of the action selection window). If it fails for any reason, you may want to check that you have correctly specified the script identifiers as these will prevent the action from working properly.

The now that brings us to the end of this tutorial. If you have any problems, please leave a post below and I'll do what I can to assist you.
Click here to comment on this tutorial.
Tutorials submitted by users are copyright of the original author. All other content on this site is copyright TheHelper.net.
Copyright is secured automatically upon creation, and does not require registration