def sendSecondMenu(userid, choice, popupid): oldChoice, target = choice if oldChoice == 2: steamid = playerlib.uniqueid(userid, False) lang = playerlib.getPlayer(userid).get("lang") if steamid not in locations: es.tell(userid, "#green", xalanguage("no locations", {}, lang) ) return currentMap = str(es.ServerVar('eventscripts_currentmap')) if currentMap not in locations[steamid]: es.tell(userid, "#green", xalanguage("no map locations", {}, lang) ) return if es.getplayerprop(target, 'CBasePlayer.pl.deadflag'): es.tell(userid, xalanguage('one player died', {}, playerlib.getPlayer(userid).get("lang") ) ) return x, y, z = locations[steamid][currentMap] es.server.queuecmd('es_xsetpos %s %s %s %s' % (target, x, y, z + 10) ) if not int(xa_anonymous): args = {} args["player"] = es.getplayername(target) args["admin"] = es.getplayername(userid) for player in playerlib.getPlayerList("#all"): es.tell(int(player), xalanguage("teleport to location", args, player.get("lang") ) ) xateleport.logging.log("has teleported user %s [%s] to their saved location" % (es.getplayername(target), es.getplayersteamid(target)), userid) else: lang = playerlib.getPlayer(userid).get("lang") popupMenu = popuplib.easymenu("xa_teleport_players", "_popup_choice", teleportPlayerToPlayer) popupMenu.settitle(xalanguage["player select to send to"]) for player in filter(lambda x: not es.getplayerprop(x, "CBasePlayer.pl.deadflag"), es.getUseridList()): popupMenu.addoption([target, player], es.getplayername(player), lang=lang) popupMenu.send(userid)
def player_activate(event_var): userid = int(event_var['userid']) steamid = playerlib.uniqueid(userid, True) for setting in gSettings: if not steamid in gSettings[setting].keyvalues['users']: gSettings[setting].initUser(userid) gSettings[setting].updateTime(userid)
def set(self, key, userid=None): option = self.isValidOption(key) if option: if userid: steamid = playerlib.uniqueid(userid, True) if steamid: if not steamid in self.keyvalues['users']: self.initUser(int(userid)) for thisoption in list( self.keyvalues['users'][steamid]['data'].keys()): if thisoption == option: self.keyvalues['users'][steamid]['data'][ thisoption]['state'] = 1 else: self.keyvalues['users'][steamid]['data'][ thisoption]['state'] = 0 else: raise IndexError( f'Settinglib: Cannot find userid {userid}') else: for thisoption in list(self.keyvalues['options'].keys()): if thisoption == option: self.keyvalues['options'][thisoption]['globstate'] = 1 else: self.keyvalues['options'][thisoption]['globstate'] = 0 else: raise IndexError( f'Settinglib: Cannot set option {key}, it does not exists')
def send(self, pUsers, prio=False, locked=False): try: # try if pUsers is just a single userid userid = int(pUsers) pUsers = [userid] except TypeError: pass if locked: optionstate = 0 else: optionstate = 1 for userid in pUsers: player = playerlib.getPlayer(userid) if player: steamid = playerlib.uniqueid(userid, True) helpline = self.languages('setting '+self.keyvalues['config']['type']+' help', (), player.get('lang')) self.popup[userid] = popuplib.easymenu('_setting_%s_user%s' % (self.name, userid), '_setting_choice', settinglib._submit) self.popup[userid].settingid = self.name self.popup[userid].c_titleformat = self.keyvalues['config']['descr'] + (' '*(30-len(self.keyvalues['config']['descr']))) + ' (%p/%t)\n' + helpline if not steamid in self.keyvalues['users']: self.initUser(userid) for option in self.keyvalues['options']: display = self.keyvalues['options'][option]['display'] userdata = self.keyvalues['users'][steamid]['data'] if option in userdata: if userdata[option]['state']: active = self.languages('setting list active', (), player.get('lang')) self.popup[userid].addoption(int(option), display + ' ('+active+')', optionstate) continue self.popup[userid].addoption(int(option), display, optionstate) if self.backmenuvar: self.popup[userid].submenu(10, self.backmenuvar) self.popup[userid].send(userid, prio)
def sendFirstPlayer(userid, choice, popupid): if 3 < choice < 10: xateleportmenu.send(userid) if choice == 1: steamid = playerlib.uniqueid(userid, False) if steamid not in locations: locations[steamid] = {} locations[steamid][str(es.ServerVar( 'eventscripts_currentmap'))] = es.getplayerlocation(userid) lang = playerlib.getPlayer(userid).get("lang") saveDatabase() es.tell(userid, "#green", xalanguage("location saved", {}, lang)) xateleport.logging.log( "has updated their saved teleport location for map %s" % str(es.ServerVar('eventscripts_currentmap')), userid, True) elif 4 > choice > 1: lang = playerlib.getPlayer(userid).get("lang") popupMenu = popuplib.easymenu("xa_teleport_players", "_popup_choice", sendSecondMenu) popupMenu.settitle(xalanguage["player select"]) for player in filter( lambda x: not es.getplayerprop(x, "CBasePlayer.pl.deadflag"), es.getUseridList()): popupMenu.addoption([choice, player], es.getplayername(player), lang=lang) popupMenu.send(userid)
def updateTime(self, userid): if es.exists('userid',userid): steamid = playerlib.uniqueid(userid, True) if steamid in self.keyvalues['users']: self.keyvalues['users'][steamid]['time'] = int(time.time()) else: self.initUser(userid)
def send(self, pUsers, prio=False, locked=False): try: # try if pUsers is just a single userid userid = int(pUsers) pUsers = [userid] except TypeError: pass if locked: optionstate = 0 else: optionstate = 1 for userid in pUsers: player = playerlib.getPlayer(userid) if player: steamid = playerlib.uniqueid(userid, True) menuname = '_setting_%s_user%s' % (self.name, userid) helpline = self.languages('setting '+self.keyvalues['config']['type']+' help', (), player.get('lang')) if not popuplib.active(userid)['name'] == menuname and not popuplib.isqueued(menuname, userid) or prio: self.popup[userid] = popuplib.easymenu(menuname, '_setting_choice', settinglib._submit) self.popup[userid].settingid = self.name self.popup[userid].c_titleformat = self.keyvalues['config']['descr'] + (' '*(30-len(self.keyvalues['config']['descr']))) + ' (%p/%t)\n' + helpline if not steamid in self.keyvalues['users']: self.initUser(userid) for option in list(self.keyvalues['options'].keys()): display = self.keyvalues['options'][option]['display'] userdata = self.keyvalues['users'][steamid]['data'] if option in userdata: if userdata[option]['state']: active = self.languages('setting list active', (), player.get('lang')) self.popup[userid].addoption(option, display + ' ('+active+')', optionstate) continue self.popup[userid].addoption(option, display, optionstate) if self.backmenuvar: self.popup[userid].submenu(10, self.backmenuvar) self.popup[userid].send(userid, prio)
def updateTime(self, userid): if es.exists('userid', userid): steamid = playerlib.uniqueid(userid, True) if steamid in self.keyvalues['users']: self.keyvalues['users'][steamid]['time'] = int(time.time()) else: self.initUser(userid)
def set(self, option, state=None, userid=None): arg = option option = self.isValidOption(option) if option: if userid: steamid = playerlib.uniqueid(userid, True) if steamid: if not steamid in self.keyvalues['users']: self.initUser(int(userid)) if state: self.keyvalues['users'][steamid]['data'][option][ 'state'] = 1 else: self.keyvalues['users'][steamid]['data'][option][ 'state'] = 0 else: raise IndexError('Settinglib: Cannot find userid %s' % userid) else: if state: self.keyvalues['options'][option]['globstate'] = 1 else: self.keyvalues['options'][option]['globstate'] = 0 else: raise IndexError( 'Settinglib: Cannot set option #%s, it does not exists' % arg)
def initUser(self, userid): if es.exists('userid',userid): steamid = playerlib.uniqueid(userid, True) self.keyvalues['users'][steamid] = self.createKey(steamid) self.keyvalues['users'][steamid]['time'] = int(time.time()) self.keyvalues['users'][steamid]['data'] = self.createKey('data') for option in self.keyvalues['options']: self.keyvalues['users'][steamid]['data'][option] = self.createKey(option) self.keyvalues['users'][steamid]['data'][option]['state'] = self.keyvalues['options'][option]['state']
def get(self, userid): if es.exists("userid", userid): steamid = playerlib.uniqueid(userid, True) if steamid in gKeyValues[self.module][self.name]: return gKeyValues[self.module][self.name][steamid] else: return False else: return False
def set(self, userid, value): if es.exists("userid", userid): steamid = playerlib.uniqueid(userid, True) gKeyValues[self.module][self.name][steamid] = value if gKeyValues[self.module][self.name][steamid] == value: return True else: return False else: return False
def uniqueid_cmd(args): ''' Console command to return the uniqueid for a player or a bot. If you want the bot's actual name, provide the final optional parameter. uniqueid <var> <userid> [add botname]''' if len(args) in (2, 3): returnvar = es.ServerVar(args[0]) # get the uniqueid, telling it to append botname if the final arg is given id = playerlib.uniqueid(userid=args[1], botname=(args[2] if len(args) == 3 else None)) returnvar.set(id) else: es.dbgmsg(0, 'Syntax: uniqueid <var> <userid> [add botname]')
def initUser(self, userid): if es.exists('userid', userid): steamid = playerlib.uniqueid(userid, True) self.keyvalues['users'][steamid] = self.createKey(steamid) self.keyvalues['users'][steamid]['time'] = int(time.time()) self.keyvalues['users'][steamid]['data'] = self.createKey('data') for option in self.keyvalues['options']: self.keyvalues['users'][steamid]['data'][ option] = self.createKey(option) self.keyvalues['users'][steamid]['data'][option][ 'state'] = self.keyvalues['options'][option]['state']
def getvar(self, variable, userid=None): if userid: if es.exists('userid',userid): steamid = playerlib.uniqueid(userid, True) if not steamid in self.keyvalues['users']: self.initUser(int(userid)) else: raise IndexError('Settinglib: Cannot find userid %s, it does not exists'%userid) else: steamid = 'global' return self.keyvalues['variables'][steamid][variable]
def get(self, userid): """ Get the set value for an individual player """ # Check if our user's setting has a value if self.exists(userid): # Get the userid's uniqueid steamid = playerlib.uniqueid(userid, True) # Return the user's setting value return gPlayerData[self.module][self.name][steamid] return None
def set(self, userid, value): """ Set the setting value for an individual player """ # Get the userid's uniqueid steamid = playerlib.uniqueid(userid, True) # Set the user's setting to the new value gPlayerData[self.module][self.name][steamid] = value # Return if our user's setting has the new value return gPlayerData[self.module][self.name][steamid] == value
def getvar(self, variable, userid=None): if userid: if es.exists('userid', userid): steamid = playerlib.uniqueid(userid, True) if not steamid in self.keyvalues['users']: self.initUser(int(userid)) else: raise IndexError( 'Settinglib: Cannot find userid %s, it does not exists' % userid) else: steamid = 'global' return self.keyvalues['variables'][steamid][variable]
def get(self, userid=None): if userid: steamid = playerlib.uniqueid(userid, True) if steamid: if not steamid in self.keyvalues["users"]: self.initUser(userid) for thisoption in self.keyvalues["users"][steamid]["data"]: if self.keyvalues["users"][steamid]["data"][thisoption]["state"]: return self.keyvalues["options"][thisoption]["keyname"] else: raise IndexError("Settinglib: Cannot find userid %s" % option) else: for thisoption in self.keyvalues["options"]: if self.keyvalues["options"][thisoption]["globstate"]: return self.keyvalues["options"][thisoption]["keyname"]
def get(self, userid=None): if userid: steamid = playerlib.uniqueid(userid, True) if steamid: if not steamid in self.keyvalues['users']: self.initUser(userid) for thisoption in self.keyvalues['users'][steamid]['data']: if self.keyvalues['users'][steamid]['data'][thisoption]['state']: return self.keyvalues['options'][thisoption]['keyname'] else: raise IndexError('Settinglib: Cannot find userid %s'%option) else: for thisoption in self.keyvalues['options']: if self.keyvalues['options'][thisoption]['globstate']: return self.keyvalues['options'][thisoption]['keyname']
def get(self, userid=None): if userid: steamid = playerlib.uniqueid(userid, True) if steamid: if not steamid in self.keyvalues['users']: self.initUser(userid) for thisoption in list(self.keyvalues['users'][steamid]['data'].keys()): if self.keyvalues['users'][steamid]['data'][thisoption]['state']: return self.keyvalues['options'][thisoption]['keyname'] else: raise IndexError(f'Settinglib: Cannot find userid {option}') else: for thisoption in list(self.keyvalues['options'].keys()): if self.keyvalues['options'][thisoption]['globstate']: return self.keyvalues['options'][thisoption]['keyname']
def set(self, key, state=None, userid=None): option = self.isValidOption(key) if option: if userid: steamid = playerlib.uniqueid(userid, True) if steamid: if not steamid in self.keyvalues['users']: self.initUser(int(userid)) self.keyvalues['users'][steamid]['data'][option]['state'] = 1 if state else 0 else: raise IndexError('Settinglib: Cannot find userid %s'%userid) else: self.keyvalues['options'][option]['globstate'] = 1 if state else 0 else: raise IndexError('Settinglib: Cannot set option %s, it does not exists'%key)
def get(self, key, userid=None): option = self.isValidOption(key) if option: if userid: steamid = playerlib.uniqueid(userid, True) if steamid: if not steamid in self.keyvalues['users']: self.initUser(int(userid)) try: return bool(self.keyvalues['users'][steamid]['data'][option]['state']) except KeyError: return bool(self.keyvalues['options'][option]['state']) else: raise IndexError(f'Settinglib: Cannot find userid {userid}') else: return bool(self.keyvalues['options'][option]['globstate']) else: raise IndexError(f'Settinglib: Cannot get option {key}, it does not exists')
def sendFirstPlayer(userid, choice, popupid): if 3 < choice < 10: xateleportmenu.send(userid) if choice == 1: steamid = playerlib.uniqueid(userid, False) if steamid not in locations: locations[steamid] = {} locations[steamid][str(es.ServerVar('eventscripts_currentmap'))] = es.getplayerlocation(userid) lang = playerlib.getPlayer(userid).get("lang") saveDatabase() es.tell(userid, "#green", xalanguage("location saved", {}, lang) ) elif 4 > choice > 1: lang = playerlib.getPlayer(userid).get("lang") popupMenu = popuplib.easymenu("xa_teleport_players", "_popup_choice", sendSecondMenu) popupMenu.settitle(xalanguage["player select"]) for player in filter(lambda x: not es.getplayerprop(x, "CBasePlayer.pl.deadflag"), es.getUseridList()): popupMenu.addoption([choice, player], es.getplayername(player), lang=lang) popupMenu.send(userid)
def clearUsersSettings(module, value = None): """ Clear all user settings for a specific player """ if value == None: value = module if es.exists('userid', value): steamid = playerlib.uniqueid(value, True) else: steamid = value modulesToRemove = {} for module in gPlayerData: for name in gPlayerData[module]: if steamid in gPlayerData[module][name]: modulesToRemove[module] = name for module, name in modulesToRemove.iteritems(): del gPlayerData[module][name][steamid] saveUserSetting()
def send(self, pUsers, prio=False, locked=False): try: # try if pUsers is just a single userid userid = int(pUsers) pUsers = [userid] except TypeError: pass if locked: optionstate = 0 else: optionstate = 1 for userid in pUsers: player = playerlib.getPlayer(userid) if player: steamid = playerlib.uniqueid(userid, True) helpline = self.languages( "setting " + self.keyvalues["config"]["type"] + " help", (), player.get("lang") ) self.popup[userid] = popuplib.easymenu( "_setting_%s_user%s" % (self.name, userid), "_setting_choice", settinglib._submit ) self.popup[userid].settingid = self.name self.popup[userid].c_titleformat = ( self.keyvalues["config"]["descr"] + (" " * (30 - len(self.keyvalues["config"]["descr"]))) + " (%p/%t)\n" + helpline ) if not steamid in self.keyvalues["users"]: self.initUser(userid) for option in self.keyvalues["options"]: display = self.keyvalues["options"][option]["display"] userdata = self.keyvalues["users"][steamid]["data"] if option in userdata: if userdata[option]["state"]: active = self.languages("setting toggle on", (), player.get("lang")) self.popup[userid].addoption(int(option), display + " (" + active + ")", optionstate) continue active = self.languages("setting toggle off", (), player.get("lang")) self.popup[userid].addoption(int(option), display + " (" + active + ")", optionstate) if self.backmenuvar: self.popup[userid].submenu(10, self.backmenuvar) self.popup[userid].send(userid, prio)
def get(self, option=None, userid=None): arg = option option = self.isValidOption(option) if option: if userid: steamid = playerlib.uniqueid(userid, True) if steamid: if not steamid in self.keyvalues["users"]: self.initUser(int(userid)) try: result = bool(self.keyvalues["users"][steamid]["data"][option]["state"]) except KeyError: result = bool(self.keyvalues["options"][option]["state"]) return result else: raise IndexError("Settinglib: Cannot find userid %s" % userid) else: return bool(self.keyvalues["options"][option]["globstate"]) else: raise IndexError("Settinglib: Cannot get option #%s, it does not exists" % arg)
def get(self, key, userid=None): option = self.isValidOption(key) if option: if userid: steamid = playerlib.uniqueid(userid, True) if steamid: if not steamid in self.keyvalues['users']: self.initUser(int(userid)) try: return bool(self.keyvalues['users'][steamid]['data'] [option]['state']) except KeyError: return bool(self.keyvalues['options'][option]['state']) else: raise IndexError( f'Settinglib: Cannot find userid {userid}') else: return bool(self.keyvalues['options'][option]['globstate']) else: raise IndexError( f'Settinglib: Cannot get option {key}, it does not exists')
def set(self, option, state=None, userid=None): arg = option option = self.isValidOption(option) if option: if userid: steamid = playerlib.uniqueid(userid, True) if steamid: if not steamid in self.keyvalues["users"]: self.initUser(int(userid)) if state: self.keyvalues["users"][steamid]["data"][option]["state"] = 1 else: self.keyvalues["users"][steamid]["data"][option]["state"] = 0 else: raise IndexError("Settinglib: Cannot find userid %s" % userid) else: if state: self.keyvalues["options"][option]["globstate"] = 1 else: self.keyvalues["options"][option]["globstate"] = 0 else: raise IndexError("Settinglib: Cannot set option #%s, it does not exists" % arg)
def set(self, key, userid=None): option = self.isValidOption(key) if option: if userid: steamid = playerlib.uniqueid(userid, True) if steamid: if not steamid in self.keyvalues['users']: self.initUser(int(userid)) for thisoption in list(self.keyvalues['users'][steamid]['data'].keys()): if thisoption == option: self.keyvalues['users'][steamid]['data'][thisoption]['state'] = 1 else: self.keyvalues['users'][steamid]['data'][thisoption]['state'] = 0 else: raise IndexError(f'Settinglib: Cannot find userid {userid}') else: for thisoption in list(self.keyvalues['options'].keys()): if thisoption == option: self.keyvalues['options'][thisoption]['globstate'] = 1 else: self.keyvalues['options'][thisoption]['globstate'] = 0 else: raise IndexError(f'Settinglib: Cannot set option {key}, it does not exists')
def get(self, option=None, userid=None): arg = option option = self.isValidOption(option) if option: if userid: steamid = playerlib.uniqueid(userid, True) if steamid: if not steamid in self.keyvalues['users']: self.initUser(int(userid)) try: result = bool(self.keyvalues['users'][steamid]['data'] [option]['state']) except KeyError: result = bool( self.keyvalues['options'][option]['state']) return result else: raise IndexError('Settinglib: Cannot find userid %s' % userid) else: return bool(self.keyvalues['options'][option]['globstate']) else: raise IndexError( 'Settinglib: Cannot get option #%s, it does not exists' % arg)
def exists(self, userid): # Get the userid's uniqueid steamid = playerlib.uniqueid(userid, True) # Return if our user's setting has a value return steamid in gPlayerData[self.module][self.name]