events¶
This page contains tutorials about theevents package.
Creating a custom event¶
When creating a custom event, you will also want to look at theevents.resource andevents.variable modules.
The first thing you want to do is create your class. The lower-case name ofthe class will be used as the name of the event. Inside the class, you willneed to declare the event variables by the type they are (using classes fromtheevents.variable module).
fromevents.customimportCustomEventfromevents.variableimportFloatVariablefromevents.variableimportShortVariablefromevents.variableimportStringVariable# Create the event's classclassMy_New_Event(CustomEvent):# Declare the variables with their typeuserid=ShortVariable('The userid of the player involved in the event.')pos_x=FloatVariable('The x value of some location in the event.')pos_y=FloatVariable('The y value of some location in the event.')pos_z=FloatVariable('The z value of some location in the event.')weapon=StringVariable('The weapon used in the event.')
The next step is to create the resource file and load the events. For moreinformation, look to theevents.resource module.
fromevents.resourceimportResourceFileresource_file=ResourceFile('my_custom_events',My_New_Event)resource_file.write()resource_file.load_events()
The last step is actually using your custom event class to fire the event. Youcan do this one of two ways. First, just create an instance, set thevariables, then fire the event.
# Create the eventevent_instance=My_New_Event()# Set the variable valuesevent_instance.userid=2event_instance.pos_x=1.111event_instance.pos_y=2.222event_instance.pos_z=3.333event_instance.weapon='weapon_knife'# Fire the eventevent_instance.fire()
The other way, is to set the variables on instantiation.
# Create the event and define the variable values on instantiationevent_instance=My_New_Event(userid=2,pos_x=1.111,pos_y=2.222,pos_z=3.333,weapon='weapon_knife')# Fire the eventevent_instance.fire()
You can also use context management to automatically fire the event on exit.
# Create the event and fire on exitwithMy_New_Event()asevent_instance:# Define the event variable valuesevent_instance.userid=2event_instance.pos_x=1.111event_instance.pos_y=2.222event_instance.pos_z=3.333event_instance.weapon='weapon_knife'
