import es import popuplib import keymenulib import services import MySQLdb #Replace the default values for your MySQL database hlp_host = "localhost" hlp_user = "user" hlp_pass = "password" hlp_db = "database" #Create dictionaries for reasons and triggers reasons = {} triggers = {} #Load block def load(): #Define punishment values values = [10, 25, 50, 75, 100, 150, 200, 300, 500, 1000, 2000] #Creates Punish Menu punish_menu = popuplib.easymenu('punish_menu', None, menu) punish_menu.settitle('Select punishment amount:') for i in range(0, 11): punish_menu.addoption('hl_punish' + str(values[i]), '-' + str(values[i]) + ' points') #Add an option to remove all points from a user (Non-action) punish_menu.addoption('hl_punishALL', 'All points') #Register an auth provider auth = services.use('auth') auth.registerCapability('can_hlp_punish', auth.ADMIN) #Register saycommand !hlpunish es.server.cmd("clientcmd create say !hlpunish \"hlpunish/call_menu\" \"can_hlp_punish\" #admin") #Try making a connection to the MySQL table try: conn = MySQLdb.connect (hlp_host, hlp_user, hlp_pass, hlp_db) except MySQLdb.Error, e: print "Error %d: %s" % (e.args[0], e.args[1]) default_string = "INSERT INTO hlstats_actions" #Obtain cursor from connction object cursor = conn.cursor() #See if action already exists. If not, then add it for i in range(0, 11): cursor.execute("SELECT * FROM hlstats_actions WHERE code = \"hl_punish" + str(values[i]) + "\"") row = cursor.fetchone() if row == None: cursor.execute(default_string + " VALUES (NULL, \"css\", \"hl_punish" + str(values[i]) + "\", -" + str(values[i]) + ", 0, \"\", \"Admin Punishment (-" + str(values[i]) + ")\", \"1\", \"0\", \"0\", \"0\", 0)") cursor.execute("SELECT * FROM hlstats_actions WHERE code = \"hl_punishALL\"") row = cursor.fetchone() if row == None: cursor.execute(default_string + " VALUES (NULL, \"css\", \"hl_punishALL\", 0, 0, \"\", \"Admin Punishment (All points)\", \"1\", \"0\", \"0\", \"0\", 0)") #Close connection to the MySQL database cursor.close() #Call_menu block: Occurs when someone types !hlpunish in chat def call_menu(): #Check to see if they are authorised to punish user = int(es.getcmduserid()) if es.getargs() == None: reasons[user] = 'unknown reasons' else: reasons[user] = es.getargs() popuplib.send('punish_menu', user) #Menu block: Occurs when authorised people choose an amount to punish by def menu(userid, choice, popupname): #Set trigger value (hl_punishXXX) triggers[userid] = choice #Create playerlist, and a keymenu based on the playerlist, and then send to this user es.server.cmd('es_xcreateplayerlist hlp_playerlist') es.set('hlp_menu_choice', 0) p_list = keymenulib.create('playerlist', 'hlp_menu_choice', player_choice, 'hlp_playerlist', '#keyvalue name', '#key', 'Current Players\nSelect a player to punish') p_list.send(userid) p_list.delete es.keygroupdelete('hlp_playerlist') #Player_choice block: Occurs when authorised people choose the player to punish def player_choice(userid, choice, popupname): #Cut the trigger string, and output the punishment to all of the server cut_string = triggers[userid].replace('hl_punish', '') es.msg('#multi', '#green' + es.getplayername(es.server_var['hlp_menu_choice']) + '#default has had#lightgreen ' + cut_string + '#default HLStats rank points removed for#lightgreen ' + reasons[userid] + '#default.') #Send statlog with trigger es.server.cmd('statlog ' + es.server_var['hlp_menu_choice'] + ' ' + triggers[userid]) #If the trigger string is hl_punishALL, then manually remove the points (as the value is not predetermined) if triggers[userid] == "hl_punishALL": #Try making a connection to the MySQL table try: conn = MySQLdb.connect (hlp_host, hlp_user, hlp_pass, hlp_db) except MySQLdb.Error, e: print "Error %d: %s" % (e.args[0], e.args[1]) #Obtain cursor from connction object cursor = conn.cursor() #Get playerId from uniqueId (SteamID) cursor.execute("SELECT * FROM hlstats_playeruniqueids WHERE uniqueId = \"" + es.getplayersteamid(es.server_var['hlp_menu_choice']) + "\"") row = cursor.fetchone() if row == None: es.tell(userid, 'Cannot remove points for chosen player - they do not exist in the HLStatsX database (' + es.getplayersteamid(es.server_var['hlp_menu_choice']) + ')') else: cursor.execute("UPDATE hlstats_players SET skill = 0 WHERE playerId = " + str(row[0])) #Close the database cursor.close() #Delete database entries del reasons[userid] del triggers[userid]