You must be logged in to post messages.
Please login or register

Scenario Design
Moderated by Yeebaagooon, TAG

Hop to:    
Welcome! You are not logged in. Please Login or Register.9 replies
Age of Mythology Heaven » Forums » Scenario Design » Delegation Triggers (Immediate Fire Event)
Bottom
Topic Subject:Delegation Triggers (Immediate Fire Event)
nottud
Mortal
posted 18 August 2018 03:30 AM EDT (US)         
Introduction
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.

Trigger Code

<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>

Basic Use Example: Simple Delegation
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.

Advanced Use: Delegation with Parameters
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.

More on parameters
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.

Parameter Emulation using QVs
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.

Other notes
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).]

AuthorReplies:
PhatFish
Mr. Beta
posted 20 August 2018 08:30 AM EDT (US)     1 / 9       
Keep up the great work.



nottud
Mortal
posted 20 August 2018 04:17 PM EDT (US)     2 / 9       
Thanks - probably more difficult but will look into being able to delegate conditions too for further savings but hacking it in I suspect will be more difficult.
nottud
Mortal
posted 26 August 2018 03:16 PM EDT (US)     3 / 9       
Ok sort of got a condition version working but does not work for timer condition and is is more complicated as you got to insert a Delegate Conditions Return as a trigger effect.

<Effect name="Delegate Conditions Return">
<Param name="Method" dispName="Name" varType="string">method</Param>
<Command>} return (tempExp);}void _othercon%Method%(){if(false){</Command>
</Effect>

<Condition 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 Conditions 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 conditions trigger should be inactive with Delegate Conditions first and Delegate Conditions Return as effect.</Param>
<Expression>/**/_con%Method%(%Parameters%)</Expression>
</Condition>

<Condition name="Delegate Conditions">
<Param name="Method" dispName="Name" varType="string">method</Param>
<Param name="Parameters" dispName="Parameters" varType="string"></Param>
<Param name="Info" dispName="Info" varType="string">Does not work for timer condition!</Param>
<Param name="Info2" dispName="Info" varType="string">Must have matching Delegate Conditions Return as trigger effect</Param>
<Expression>false);}bool _con%Method%(%Parameters%){bool bVar0 = true;//</Expression>
</Condition>

Any ideas to simplify and include timer working is welcome. Thought of passing the activation value constant through but didn't seem to work - must be internal implementation goings on...
Hammerhands
Mortal
posted 26 August 2018 09:13 PM EDT (US)     4 / 9       
Okay, this sounds FREAKY awesome... but I don't understand how it works. I'll have to try it out.
nottud
Mortal
posted 27 August 2018 07:53 AM EDT (US)     5 / 9       
I've got a new map "Lost Treasure RPG" that makes extensive use of this delegate trigger and is pretty good for showing its capabilities. I can give it you sometime if I see you around online - probably will put it here for download when I am happy it is completely stable but keep finding minor issues to solve.

[This message has been edited by nottud (edited 08-27-2018 @ 08:16 AM).]

nottud
Mortal
posted 02 September 2018 11:06 AM EDT (US)     6 / 9       
Effective Use
When using parameters it is useful to parameterise the player number putting a variable name. However player parameters you select from a dropdown rather than typing it. You can easily convert all triggers to use typing instead by opening your typetest and doing the following find and replace:

VarType="player"
to
VarType="string"

This will make it so you can type in player numbers as a variable freely.
Hammerhands
Mortal
posted 12 September 2018 09:47 PM EDT (US)     7 / 9       
nottud
Mortal
posted 15 September 2018 08:19 AM EDT (US)     8 / 9       
The main areas that time can be saved are as follows:
(1)Making a set of effects that is the same but the player number changes. Basically use the player number as a parameter and then you can call if from each trigger you want. When you do stuff for each player there is a risk you forget to change some of the player numbers leading to some effects not working properly for some of the players. This will mitigate that.
(2)If you create a series of triggers for each player and you want to make a change - e.g. change the message for each player you only have to change one place rather n places (where n is the number of players)
(3)It allows you to define a consistent engine for your game. An example is I made an RPG where I want all cinematics to do the same set up stuff: turn cinematic mode on, remove fog and black map, halt combat by altering the diplomancy of the players. I can now apply this consistently to all places where a cinematic starts without worrying about missing something else out. Why not you Fire Event you say - well this fires immediately meaning that after calling the delegate you know it has been done - this allows you to immediately do things like call Sound Play Paused or whatever to display cinematic text whereas fire event means the stuff called would happen slightly later causing the cinematic text to not appear properly.

I admit that some of the useful areas especially involving players are now done better using For Player Triggers although this still has its uses. I encourage you to get hold of my recent RPG maps where I make good use of these.
Nickonhawk
The Narrator
posted 30 September 2018 08:00 AM EDT (US)     9 / 9       
I know it's never too late but damn...

Youtube Channel
Skyrim... the greatest game ever... without considering Age of Mythology, of course!
Ctrl...Alt...Q...
and Brisingr-know these three things and your task here is accomplished...
You must be logged in to post messages.
Please login or register

Hop to:    

Age of Mythology Heaven | HeavenGames