My last article detailed how to write a very simple mod for Counter Strike Source servers; here, I plan to go into more detail. I will assume basic knowledge of Python, and an understanding of how to create a simple addon on your source server - essentially I plan to discuss Eventscripts' API and features.
Each player that joins a server is allocated a unique user id. This userid is used as a key to identify users, and a given e player's name, steamid, health — almost any information on that player — will be available using their userid. For example, to find a player's name, one might simply use the 'getplayername' method of the es module:
es.getplayername(userid)
Importing this module is crucial to displaying any kind of output on your server, and registering the events in your addon. Es contains methods which can be used to:
And a whole load more. Detailed documentation for each of the methods of es can be found here.
import es
Events are almost crucial to achieving anything with Valve's source engine. In the majority of cases, events are where you will get your inputs, whether it is:
Events are registered simply by creating a function in your script with the specific name of the event you wish to hook. All of the available events are documented here)
These functions take one argument; traditionally named 'event_var', this is a variable which will store a dictionary containing details about the event when it is called. For example, the key 'player_name' will return the name of the player who the event is called by - if the event is player specific.
def player_spawn(event_var):
..es.tell(event_var['userid'], 'Hello, world')
As an example of a very basic addon, the following script logs the number of times a player says anything in chat, in a given session, and returns this value to them when they type 'stats'.
import es
stats = {}
def player_connect(event_var):
..stats[event_var['userid']] = 0
def player_say(event_var):
..userid = event_var['userid']
..if event_var['text'] == 'stats':
....es.tell(userid, 'You have sent ' + str(stats[userid]) + ' messages during this session'
..else:
....global stats
....stats[userid] += 1
Once you've got to grips with the basics described above, the rest is simple to pick up. All of the documentation you could possibly need can be located in the following places:
http://python.eventscripts.com/
http://addons.eventscripts.com/
Popularity: 3%
Discussion
No comments for “Using Eventscripts to mod CS Source”
Post a comment