Creating a New Player Punishment
From EventScripts Community Encyclopedia
|
[edit] Tutorial: Creating a New Player PunishmentRequires: ES 2.x [edit] Tutorial Overview[edit] Table of Contents
[edit] DescriptionThis article discusses all of the things you need to do in order to create a new player punishment for Extensible Admin. [edit] Tutorial Content[edit] Starting UpOkay, we need to import that xapunishments module, alongside XA which will allow us to register a new punishment on the menu. To do this, go ahead and use the import command. import es # Import XA import xa from xa import xa # Import punishments from xa.modules.xapunishments import xapunishments Okay, that was simple. Now, we have to register a punishment with the main menu. To do this, you will use the method xapunishments.registerPunishment xapunishments.registerPunishment(<"short punishment name">, <"Full Punishment Name">, <callback function>, <say command (1/0)>)
[edit] Your first punishmentOkay, here is an example of how to do the following:
# Import es modules import es import playerlib import gamethread # Import XA import xa from xa import xa # Import xapunishments from xa.modules.xapunishments import xapunishments burn = xa.register('burn') language = burn.language.getLanguage() # Make short cuts so that burn will be used for all the xa commands. language now contains the ability to do multi lingual support. adminburn_anonymous = burn.setting.createVariable("adminburn_anonymous", 0 , "When an admin burns a player, will a message be sent? 1 = no, 0 = yes") adminburn_time = burn.setting.createVariable("adminburn_time" , 20, "This is the length of time (in seconds) that the player will be burnt for") ''' Register 2 variables. Each variable is saved to a python global variable (adminburn_anonymous and adminburn_time). Because these global variables are global, they can be accessed from anywhere within the script. ''' def load(): burn.registerPunishment("burn", xalanguage["burn"], _burn, 1) # Register the punishment with short name 'burn', and the display text as a multi lingual text. Register the callback function to _burn, and allow for a say command def _burn(adminid, victimid, args): # Okay, the admin burned the victim if str(xa_adminburn_anonymous) == "0": # If the setting is set to 0, then it is not anonymous. tokens = {} tokens['admin'] = es.getplayername(adminid) tokens['victim'] = es.getplayername(victimid) # register some tokens so that the strings.ini can recognise what the admin's and victim's name are. for player in playerlib.getPlayerList(): es.tell(int(player), xalanguage("admin burn", tokens, player.get("lang"))) # For each player on the server, send the "admin burn" message to them, and send the tokens along with it. es.server.cmd("es_xfire %s !self Ignite"%victimid) # set the player on fire gamethread.delayed(adminburn_time, _extinguish, victimid) # Make a delay for adminburn_time, and call the _extinguish block. Pass the victimid as a parameter. def _extinguish(userid): # Okay, the userid was the person who was burnt X seconds ago if not es.getplayerprop(userid, 'CBasePlayer.pl.deadflag'): # The player is not dead, so extinguish him napalmlist = es.createentitylist("entityflame") # Get a list of all the flame entities currently on the server handle = es.getplayerhandle(userid) # Get the players handle. This is the userid's custom code that the server recognises and attaches it to certain entities, such as the flame entity for entity in napalmlist: # for every entity in the napalmlist, do the following code... string = es.getindexprop(a,'CEntityFlame.m_hEntAttached') # Get who the flame is attached to if string == handle: # If the flame attachment is equal to the players handle, then that entity is the one burning the player. es.setindexprop(a,'CEntityFlame.m_flLifetime',0) # We set the entity index's lifetime to 0. This puts out the flame break # We no longer have any need to carry on the 'for' loop, so we 'break' it, which stops the current iteration and saves resources. [edit] ConclusionHopefully you now have a better idea on how to create your own punishments. It is a really simple way to add new punishments onto the main menu. Hope you have fun with this, the sky is now the limit! [edit] Thanks for reading |
|
