My Second Addon
|
[edit] Tutorial: My Second AddonRequires: ES 2.x [edit] Tutorial Overview[edit] Table of Contents
[edit] DescriptionIn this Tutorial, we will create a simple addon for EventScripts 2.0 (AKA ESP / ESPy). The addon will simply set the players health when they say /sethealth using Playerlib and the es.regsaycmd function. Please make sure you have a basic knowledge of the Python language, for people that can already program, then I would start off with this tutorial. [edit] Tutorial Content[edit] Start offOpen your favorite Python editor, if you don't have one, I recommend Notepad++ or PSPad; or, if you have enough money ActiveState Komodo. You can also just use Notepad or any text editor you like. Create a new document, and add the 2 following lines: import es import playerlib [edit] Start the main script[edit] load() eventAfter adding the import lines, we will start by adding the load() event. def load(): if not es.exists('saycommand', '/sethealth'): es.regsaycmd('/sethealth', 'healthyaddon/sethealth') In the snippet above, we called es.exists() to see if the say command /sethealth exists, and then if it does not, register the say command. [edit] /sethealth commandJust after the load() event, add this: def sethealth(): health = es.getargv(1) userid = es.getcmduserid() player = playerlib.getPlayer(userid) player.set('health', health) In the sethealth() function, we are getting the first parameter using es.getargv(1) (health), the userid using es.getcmduserid(), getting the player object from playerlib.getPlayer(userid) and then setting the health using the set() method on the player object. [edit] Save the addonNow we have completed the addon, save it as healthyaddon.py under: ../cstrike/addons/eventscripts/healthyaddon/ Load up srcds, and enter: es_load healthyaddon You should get in the console: Loaded: healthyaddon Now, join the server and say: /sethealth 200 Your health should now be set to 200! [edit] ConclusionYou will now (hopefully) have a satisfactory understanding of how EventScripts works with Python, how basic playerlib works and command-based EventScripts programming works. [edit] Thanks for reading |
|
