My First Addon

From EventScripts Community Encyclopedia


Tutorial: My First Addon

Requires: ES 2.x
Difficulty: Easy
Author: Saul Rennison
Contributors: ~
Length: 5 mins

Tutorial Overview

Table of Contents

Contents

Description

In this Tutorial, we will create an extremely simple addon for Counter-Strike: Source using EventScripts 2.0 in Python (ESP / ESPy). This tutorial will help you create a simple Hello World . If you do not know the basics of Python, take a look at the Python for Beginners tutorial.

Tutorial Content

Start off

Open 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, import EventScripts:

import es

Start the main script

player_jump event handling

After adding the import lines, we will start by defining the player_jump function, by telling Python we are going to create a function called player_jump:

def player_jump(event_var):

After adding that line, add the following code:

     es.msg('You jumped!')

Note the indentation at the start of the line, this is vital or Python won't know that you want that line of code to execute when player_jump is ran. In python indentations are usually a single tab or 4 spaces per indent - Mattie recommends you use 4 spaces in your scripts (although tabs will work).

Save the addon

Now we have completed the addon, save it as firstaddon.py under:

../cstrike/addons/eventscripts/firstaddon/

Load up srcds, and enter:

es_load firstaddon

You should get in the console:

Loaded: firstaddon

Now, join the server and jump!

Conclusion

You will now hopefully have a vague understanding of how EventScripts works with Python. Take a look at My_Second_Addon for a more sophisticated, purposeful addon tutorial.

Thanks for reading

blog comments powered by Disqus