Admin Menu
The admin script allwos you to add new options to the admin menu. There is only one real command which allows you to do all the rest, and a lot of it actually comes down to creating your own functions to do the rest. This is a modification for more advanced coders. If you feel confident enough, this is a very powerful script which allows you to modify huge things, and do some excellent administration options. Default, there are 2 commands as of time of writing this: Give XP and Give Level. I will show you how I made the command Give Level.
First you will need to know how to work the registerMenu command:
This is the correct syntax:
wcs.Admin().registerMenu('Menu text',function callback when menu selected)
- Menu text - This is the text that will appear on the main menu
- Function callback - Whenever your option is selected, it'll run the function you define. Note: The call-back function takes 1 paramater - userid.. e.g. def yourfunction(userid):
'''
This is the admin module where you can edit the main menu of the
admin popup. This is for advanced coders, who know exactly what
theyre doing.
'''
import es
import popuplib
import wcs
from wcs import wcs, wcsconfig
wcs_admins = wcsconfig.wcs_admins
players = {}
def load():
admin_menu = wcs.Admin()
admin_menu.registerMenu('Give XP',GiveXp)
# This creates a new option on the main menu, and calls the function GiveXp
admin_menu.registerMenu('Give Levels',GiveLevel)
if not es.exists('clientcommand','WCSADDXP'):
es.regclientcmd('WCSADDXP','wcs/admin/GiveTheXp')
# Makes a command so we can use an escinputbox later
if not es.exists('clientcommand','WCSADDLEVEL'):
es.regclientcmd('WCSADDLEVEL','wcs/admin/GiveTheLevel')
def player_disconnect(ev):
'''
Deletes a player from the dictionary if he has a key, as to save memory and CPU power
'''
global players
if players.has_key(ev['userid']):
del players[ev['userid']]
def IsAdmin(userid):
if es.getplayersteamid(userid) in wcs_admins: return True
return False
def UpdateTargetList(userid):
'''
Deletes the old player menu, updates it with the newer people
on the server.
'''
players = popuplib.construct('TargetMenu', 'players', '#all')
players.settitle('Chose a player')
players.menuselectfb = TargetChosen
players.send(userid)
def TargetChosen(userid, choice, popupid):
'''
Saves the targets ID to the users dict. This makes it so we
can call the users ID at a later stage
'''
players[userid]['target'] = choice
function = players[userid]['function']
if callable(function):
function(userid)
######################################################################
################### CUSTOM COMMANDS START ############################
######################################################################
def GiveXp(userid):
players[userid] = {'function':SelectXpAmount}
UpdateTargetList(userid) # Sends an updated version of the playerlist
def SelectXpAmount(userid):
es.escinputbox(30, userid, '=== WarCraft: Source Give Xp ===', 'Enter the XP Value', 'WCSADDXP')
# This creates an escape box option, where the user will input the amount of xp he wants to
# give to the user... After he has selected the amount, it'll run the command WCSADDXP, and
# the value will be passed as an extra argument.. e.g. if the admin inputed 50 for the value,
# it'd run the command WCSADDXP 50.
es.tell(userid,'#green','Press escape on your keyboard to input a value for the XP.')
def GiveTheXp():
userid = es.getcmduserid()
# Gets the userid of the user
if IsAdmin(userid):
# If the user is an admin
amount = int(es.getargv(1)) # Gets the amount of XP the user inputted
if amount > 0: # I.E, neither negative nor 0
target = players[userid]['target'] # retrieves the target's info
player = wcs.Command(target)
player.GiveXp(amount,' being liked by an administrator.') # Finalizes the command, and adds the xp
else:
es.tell(userid,'#green','You must input a value greater than 0!'
Comments (0)
You don't have permission to comment on this page.