Difference between revisions of "EVENTS"
MrSugarCube (talk | contribs) (Created page with 'An EVENTS definition contains a set of trigger scripts which can be attached to characters. There are different properties that can be used to attach an event block to a characte...') |
MrSugarCube (talk | contribs) |
||
Line 1: | Line 1: | ||
+ | __FORCETOC__ | ||
An EVENTS definition contains a set of trigger scripts which can be attached to characters. There are different properties that can be used to attach an event block to a character or set of characters: | An EVENTS definition contains a set of trigger scripts which can be attached to characters. There are different properties that can be used to attach an event block to a character or set of characters: | ||
* [[CHARDEF|character definitions]] via their [[TEVENTS]] property | * [[CHARDEF|character definitions]] via their [[TEVENTS]] property | ||
Line 6: | Line 7: | ||
+ | ==Syntax== | ||
The syntax for defining an event is: | The syntax for defining an event is: | ||
Line 23: | Line 25: | ||
The trigger name can be the name of any [[Characters#Triggers|character trigger]]. The return value from the script can affect Sphere's hardcoded behaviour in different ways. See the documentation for the trigger to discover what parameters are passed in to each trigger and what the return values do. | The trigger name can be the name of any [[Characters#Triggers|character trigger]]. The return value from the script can affect Sphere's hardcoded behaviour in different ways. See the documentation for the trigger to discover what parameters are passed in to each trigger and what the return values do. | ||
+ | |||
+ | |||
+ | ==Examples== | ||
+ | <spherescript> | ||
+ | // | ||
+ | // When attached to a character, character speaks when double-clicked | ||
+ | // | ||
+ | [EVENTS e_exampleevent] | ||
+ | ON=@DClick | ||
+ | SAY I have been double clicked! | ||
+ | RETURN 2 | ||
+ | </spherescript> | ||
+ | |||
+ | <spherescript> | ||
+ | // | ||
+ | // e_Human_Environ from default script pack | ||
+ | // Attached to NPCs to make them light a torch during the night | ||
+ | // | ||
+ | [EVENTS e_Human_Environ] | ||
+ | ON=@EnvironChange | ||
+ | IF (<FLAGS> & statf_war) | ||
+ | RETURN 0 | ||
+ | ENDIF | ||
+ | IF !(<SECTOR.ISDARK>) || (<FLAGS> & statf_nightsight) | ||
+ | IF (<FINDLAYER.layer_hand2>) | ||
+ | IF (<FINDLAYER.layer_hand2.TYPE> == t_light_lit) | ||
+ | FINDLAYER.layer_hand2.BOUNCE | ||
+ | ENDIF | ||
+ | ENDIF | ||
+ | RETURN 0 | ||
+ | ENDIF | ||
+ | // already have a lit light ? | ||
+ | IF (<FINDLAYER.layer_hand2>) | ||
+ | IF (<FINDLAYER.layer_hand2.TYPE> == t_light_lit) | ||
+ | RETURN 0 | ||
+ | ENDIF | ||
+ | ENDIF | ||
+ | // try to use a torch or light source if i have one. (and it's dark) | ||
+ | IF (<FINDTYPE.t_light_out>) | ||
+ | FINDTYPE.t_light_out.EQUIP | ||
+ | FINDTYPE.t_light_out.USE | ||
+ | ENDIF | ||
+ | RETURN 0 | ||
+ | </spherescript> | ||
+ | |||
+ | [[Category: Reference Compendium]] | ||
+ | [[Category: Definitions]] |
Revision as of 19:51, 11 June 2009
An EVENTS definition contains a set of trigger scripts which can be attached to characters. There are different properties that can be used to attach an event block to a character or set of characters:
- character definitions via their TEVENTS property
- characters via their EVENTS property,
- All players via the EVENTSPLAYER setting in Sphere.ini.
- All NPCs via the EVENTSPET setting in Sphere.ini
Contents
Syntax
The syntax for defining an event is:
[EVENTS defname]
ON=trigger_name
script
ON=trigger_name
script
Any number of triggers can be handled by one EVENTS definition, however it is not possible to handle the same trigger twice without using multiple definitions.
The trigger name can be the name of any character trigger. The return value from the script can affect Sphere's hardcoded behaviour in different ways. See the documentation for the trigger to discover what parameters are passed in to each trigger and what the return values do.
Examples
// // When attached to a character, character speaks when double-clicked // [EVENTS e_exampleevent] ON=@DClick SAY I have been double clicked! RETURN 2
// // e_Human_Environ from default script pack // Attached to NPCs to make them light a torch during the night // [EVENTS e_Human_Environ] ON=@EnvironChange IF (<FLAGS> & statf_war) RETURN 0 ENDIF IF !(<SECTOR.ISDARK>) || (<FLAGS> & statf_nightsight) IF (<FINDLAYER.layer_hand2>) IF (<FINDLAYER.layer_hand2.TYPE> == t_light_lit) FINDLAYER.layer_hand2.BOUNCE ENDIF ENDIF RETURN 0 ENDIF // already have a lit light ? IF (<FINDLAYER.layer_hand2>) IF (<FINDLAYER.layer_hand2.TYPE> == t_light_lit) RETURN 0 ENDIF ENDIF // try to use a torch or light source if i have one. (and it's dark) IF (<FINDTYPE.t_light_out>) FINDTYPE.t_light_out.EQUIP FINDTYPE.t_light_out.USE ENDIF RETURN 0