A frustration when making scenario is repeating the same series of calls several times in different triggers. It would be a lot nicer if you define the set of effects in one place and get everywhere to use it. It also means that if you want to change what the effects do you only have to change a single place.
Bring on the Delegation trigger effects! This essentially allows you to use the contents of another trigger as a single effect for one or more other triggers. i.e. it essentially allows you to define your own trigger effects dynamically in the Scenario. Even more so you can also pass through parameters such as a player number so the same effect can be used with different data - e.g. using a player number.
Scripters may recognise this as a method declaration and method calls but now brought to standard triggers.
<Effect name="Delegate">
<Param name="Method" dispName="Name" varType="string"> method< /Param>
<Param name="Parameters" dispName="Parameters" varType="string"> < /Param>
<Param name="Info" dispName="Info" varType="string"> Delegate code should be created in trigger before this one, if not copy this to make this more recent.< /Param>
<Param name="Info2" dispName="Info2" varType="string"> Delegate trigger should be inactive with Delegate Code first.< /Param>
<Command> /**/%Method%(%Parameters%);< /Command>
</Effect>
<Effect name="Delegate Code">
<Param name="Method" dispName="UniqueName" varType="string"> method< /Param>
<Param name="Parameters" dispName="Parameters" varType="string"> < /Param>
<Command> }< /Command>
<Command> }< /Command>
<Command> void %Method%(%Parameters%){< /Command>
<Command> if(true){< /Command>
</Effect>
Create an inactive trigger and add the method "Delegate Code" with a unique name. Afterwards add in as many trigger effects as you want. Then create another trigger and add the effect "Delegate" with the same name as the Delegate Code". For this put a simple condition such as a timer. Now whenever Delegate method occurs the trigger effect Delegate Code will run - i.e. Delegate Code is your custom trigger effect.
Create an inactive trigger and add the method "Delegate Code" with a unique name and for parameter put: int p = 0 Next add a simple effect using the parameter such using xs user code: trTechGodPower(p, "Bronze", 1); which will grant bronze to player p. Next create another trigger and add the effect "Delegate" with the same name as the Delegate Code" and put the parameter of 1. This will first the Delegate Code effect with p being the value 1. Now change 2 to 2 and you will find that Bronze instead gets granted to player 2.
The parameters on Delegate Code are parameter declarations in the following form:
type name = defaultValue
type: data type of the value such as int (2, -5), float (4.5, -37), string ("Hello" "This is amazing!"), or bool (true, false)
name: parameter name to hold the value being passed
defaultValue: when the parameter is not provided when the method is called this is the value that will be used
If you wish to pass multiple values separate them with a comma.
Many triggers are already rigged up to use QVs as parameters so if the parameters stuff is inconvenient you could alternatively set a Quest Var to a value and then in the Delegate Code trigger use the current value of the Quest Var that was set rather than passing parameters.
Due to the nature of the way things work, the the trigger containing Delegate Code must exist before the trigger calling it otherwise a trigger lock will occur (This is because the declaration in the underlying generated script from triggers must exist before anything calling it). If it doesn't make a copy the trigger making the call and delete the original (Just note that you need to update any triggers firing the original called as it won't exist any longer)
I appreciate the parameters part is a little advanced but the basic form is hopefully still useful for most designers - I hope this will prove useful for saving lots of time when designing maps!
[This message has been edited by nottud (edited 08-18-2018 @ 03:36 AM).]