Tutorial Triggers - Adding a 'Add Event to Trigger' Action

Dave312

Censored for your safe viewing
Reaction score
269
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.

attachment.php




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.
Code:
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.

attachment.php




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.

attachment.php




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.
 

Attachments

  • SC2Tutorial-AddingEventToTrigger-01.jpg
    SC2Tutorial-AddingEventToTrigger-01.jpg
    243.3 KB · Views: 2,692
  • SC2Tutorial-AddingEventToTrigger-02.jpg
    SC2Tutorial-AddingEventToTrigger-02.jpg
    126 KB · Views: 2,676
  • SC2Tutorial-AddingEventToTrigger-03.jpg
    SC2Tutorial-AddingEventToTrigger-03.jpg
    190.6 KB · Views: 2,592

Romek

Super Moderator
Reaction score
963
...And here I was, thinking that GUI is unrestricted (other than forcing you to click 100 times per minute).

The images are broken.
 

Dave312

Censored for your safe viewing
Reaction score
269
The images should work now.

The GUI isn't really that restricted, they just missed a couple things which can be added manually fairly easily.
 

Viper5030

New Member
Reaction score
0
Great tutorial, except you forgot to check "Use Reference" for the Unit parameter in your own example (since you're looking for an object of type <unitref> instead of <unit>);)
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Members online

      No members online now.

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top