Addon Details

Watch - Add Favorite


Does this version work for you?
2
w00ts
w00t!2

Synergy Event Manager - Version 1.0

posted on 2008-03-14 18:47:00
by GODJonez



Description

This package is mostly designed for Synergy mod, but can be used for any source game. Note that this is not a script addon like others, you [b]do not[/b] es_load this script, it will only be used by other Python scripts. [size=18]For end-users[/size] Just download and extract to your game folder on the server. Any script requiring syn_events will then automatically use it, the only requirement is that all the files from the ZIP file are present in correct location. [size=18]For scripters[/size] To make a script use syn_events, this script needs to be imported as any Python module: [syntax="python"]import syn_events[/syntax](to be clear, just import it, do not use from ... import) [b][u]Methods[/u][/b] [b]syn_events.register[/b] (EventName, EventDef) [list][*]Registers function [i]EventDef[/i] to be called on event [i]EventName[/i][/list] [b]syn_events.unregister[/b] (EventName, EventDef) [list][*]Removes function [i]EventDef[/i] to be called on event [i]EventName[/i][/list] [b][u]Example[/u][/b] [syntax="python"]import es import syn_events def load(): syn_events.register('syn_player_death', syn_player_death) def unload(): syn_events.unregister('syn_player_death', syn_player_death) def syn_player_death(ev): uid = int(ev['userid']) aid = int(ev['attacker']) weapon = ev['weapon'] if uid: playername = es.getplayername(uid) es.msg('Player %s died from %s'%(playername,weapon)) elif aid: playername = es.getplayername(aid) es.msg('Player %s killed an npc with %s'%(playername,weapon)) else: es.msg('An NPC killed another NPC with %s!'%weapon) [/syntax] [size=18]Synergy Event writers[/size] If you want to create an event for syn_events to be handled that can be used by other scripts, you need to also import another module: [syntax="python"]import syn_events from syn_events import syn_events_classes[/syntax] If your custom event is to be a replacement/supplement for a single other event (real event as seen by EventScripts), then name your class as that event itself. The custom event name is set when you register your custom event to syn_events. [syntax="python"]class es_player_chat(syn_events_classes.base_event): # some stuff will come here pass syn_events.EventManager.registerEvent('syn_player_chat', es_player_chat) [/syntax] That would create a (non-working) custom event named syn_player_chat that will get fired whenever es_player_chat event is fired. To make the event a working one, you need to supply it at least two special methods: [b]createEventInfo[/b] and [b]createEventVars[/b]. createEventInfo(self) is used like a .res file, to specify which event variables your event will supply. The order you put the variable names in this method is significant, you need to use the same order in createEventVars to assign the values properly. createEventVars(self, new_ev, old_ev) sets the event variables to be given to scripts listening for this event. The dict new_ev should contain all the event variables after this method is completed. The parameter old_ev contains the original event variable class instance from EventScripts, if this custom event was used as a supplemental/replacement event for a real event. See the player_death class in the zip file for a working example. For more special events, you need to override some more of the events from base_event class, at least activateListener and deactivateListener.

Installation

Download the file and extract to your game folder (like synergy or cstrike), wherever the addons folder with EventScripts is in.

Version Notes For 1.0

Updated on: 2008-03-14 18:47:00 EST by GODJonez (View Zip Contents)
Contains one event, 'syn_player_death', designed for Synergy mod, adding two additional event variables to the player_death event of the game, userid and attacker. If the victim or killer were connected players, their userids are stored in those event variables. If the victim or killer was not a connected player, then the representative variable will be 0 to signify it is no valid userid.

( Previous Versions )