Intermediate Tutorial: Using Event Trigger - Execute GPDL function
Trap Detection
General:
- A GPDL trigger causes an event to execute if it returns a 1.
- Functions in the script are applied regardless of whether the event executes.
- Valid actors are $Myself() for the active character, and $Name( String ).
- Character special abilities may be set and fetched.
- Character, party, and global ASLs may be set and fetched.
- Quest stages may be set and fetched.
- Most non-combat functions are valid.
GPDL scripts offer great flexibility in determining whether an event should fire. Many parameters can be tested in a single script, which may eliminate the need for multiple chained events. It can also improve the game flow by performing tasks without player input.
For example, here is a trap detection script for use with a Chain event.
$VAR index; $VAR name; $VAR rnd; index = 0; $WHILE (index <# $PARTYSIZE()) { name = $GET_CHAR_NAME(index); //Find Traps spell active $IF ($IS_AFFECTED_BY_SPELL($Name(name),"Find Traps")) { $SET_PARTY_ACTIVECHAR(index); $RETURN 1; }; //Thief - Find Traps $IF ($GET_CHAR_FINDTRAPS(index) ># 0) { rnd = $RANDOM(100) +# 1; $IF (rnd <=# $GET_CHAR_FINDTRAPS(index)) { $SET_PARTY_ACTIVECHAR(index); $RETURN 1; }; }; //Dwarf - Detect traps in stonework $IF ($GET_CHAR_RACE(index) == "Dwarf") { rnd = $RANDOM(100) +# 1; $IF (rnd <= 50) { $SET_PARTY_ACTIVECHAR(index); $RETURN 1; }; }; //Gnome - Detect unsafe walls, ceilings, or floors $IF ($GET_CHAR_RACE(index) == "Gnome") { rnd = $RANDOM(100) +# 1; $IF (rnd <=# 70) { $SET_PARTY_ACTIVECHAR(index); $RETURN 1; }; }; index = index +# 1; };
Script notes:
- If a Find Traps spell is in effect, detection is automatic.
- All characters with the Find Traps ability will have their chance checked.
- Dwarf and gnome abilities are included, but are easily removed if not applicable.
- The random number is generated separately for each comparison.
- The character discovering the trap is set to 'active' in each instance, so a caret ( ^ ) in the text block of the chained event will insert the name of the one who found it.