Chapter 9
(WIP)
How to "install" [EVENTS]
A basic event looks like the following:
[EVENTS defname] code
Looks just like every other thing we've done so far doesn't it? Well events work the same way. They can be installed either in-game our through a script using the following:
EVENTS +defname EVENTS=defname EVENTS -defname
These are three very different commands. Some people tend to confuse them. Here is what they do:
EVENTS +DEFNAME
Adds the event to the character's list of events. Yes, a character can have more than one event. Both of the following will respond to triggers called on the character:
SRC.EVENTS +e_death_event SRC.EVENTS +e_ctf_event
EVENTS=DEFNAME
This method is should not be used. It will erase all other events on the character in place of this one.
EVENTS -DEFNAME
This will remove the specified event from the character.
THE DEFAULT OBJECT OF AN [EVENTS] SCRIPT IS THE CHARACTER ON WHICH THE SCRIPT IS INSTALLED.
The order of event handling
There are quite a few ways to add events to items or characters. These are:
EVENTS +DEFNAME
Can be set by a function, another event, a player action, or inside a trigger (for example, the @Create trigger).
TEVENTS=DEFNAME
In the body of the ITEMDEF or CHARDEF. There may be as many of TEVENTS lines as you wish.
TYPE=DEFNAME
(Items only) In the body of the ITEMDEF. There can only be ONE base type definition. TYPEs are not only events, they also determine some basic behaviour of the item, and it's capabilities (for example, if an item is not of an equippable type, it cannot be equipped).
DIRECT TRIGGERS
Poor man's events: As events are generally assortments of triggers what can be added to an item or character. You may also "hardcode" some trigger actions in the ITEMDEF/CHARDEF itself.
ORDER OF FIRING
Look at these simple code examples:
[ITEMDEF i_triggertester] ID=i_floor_wood TYPE = t_testtype NAME=TriggerTester TEVENTS=e_tev_test ON=@Create EVENTS +e_ev_test ON=@DClick SERV.LOG item dclick from direct trigger [TYPEDEF e_ev_test] ON=@DClick SERV.LOG dclick from event [TYPEDEF e_tev_test] ON=@DClick SERV.LOG item dclick from tevent [TYPEDEF t_testtype] ON=@DClick SERV.LOG item dclick from base typedef
This gives the following results:
item dclick from event
item dclick from tevent
item dclick from base typedef
item dclick from direct trigger
The same for characters:
[CHARDEF c_testorc] ID=c_orc NAME=TestOrc TEVENTS=e_tev_character ON=@Create STR = 100 ON=@NPCRestock EVENTS +e_ev_character ON=@DClick SERV.LOG char dclick from direct trigger [EVENTS e_tev_character] ON=@DClick SERV.LOG char dclick from tevent [EVENTS e_ev_character] ON=@DClick SERV.LOG char dclick from event
The results:
char dclick from event
char dclick from tevent
char dclick from direct trigger
Item-based events
There are two main types of events:
ITEM EVENT
Triggered when any player interacts in a certain way with a given item.
PLAYER EVENT
Triggered when a given player interacts in a certain way with ANY item or performs certain tasks, such as moving, casting a spell, crafting an item, etc.
In the item script, the item is the default object. In the player script, the player is the default object.
So what are these events? Well here's a short list of some of them:
@itemDClick - Triggered when the player double-clicks any item. The reference object for the item is ACT.
@itemEquip - Triggered when the player equips any item. The reference object for the item is ACT.
@itemUnEquip - Triggered when the player unequips any item. The reference object for the item is ACT.
@itemClick - Triggered when the player double-clicks any item. The reference object for the item is ACT.
@itemStep - Triggered when the player steps on any item. The reference object for the item is ACT.
Notice anything similar between those descriptions? If you don't, I think you need to go back and take reading lessons. That's right. In ANY script beginning with @item, ACT is the item acted upon. How about that. Why do you suppose they called it ACT?
In any case, for @item scripts, the following is true:
ACT = the item acted upon
SRC = the character doing the acting (the player with the event)
[] = the character doing the acting (the player with the event)
Notice that in this case, SRC and the default object both refer to the character. THIS IS NOT ALWAYS THE CASE. If you want to refer to the character, get in the habit of using the default object rather than SRC in an event. Now, let's take a look at a rather useless event:
[EVENTS e_test_events] ON=@itemStep SYSMESSAGE You have stepped on <ACT.NAME>! RETURN 0
Put this script in one of your files and resync your server. Now, go in-game and type: .xevents +e_test_events Target yourself. Congratulations, you just installed an event on yourself. From this point forward, until you remove the event, any time you walk on an item, you'll get an irritating message. Try it. Go around walking on things! Make an item called "a bug" and walk around stepping on them.
Ok stop walking on things and continue reading now. :)
Here's a little secret I bet you've already guessed: ALL ITEM EVENTS (except @Timer) HAVE AN @item COUNTERPART. This means that @itemPickUp_Pack, @itemTargOn_Char, @itemTargOn_Item, and all others should all (in theory) work.