def _action_remove(userid, popupid): """ Removes one bot, trying to conserve team balance """ if int(es.ServerVar("bot_quota")): if int(es.getplayercount(2)) > int(es.getplayercount(3)): prefteam = 2 else: prefteam = 3 botlist = playerlib.getPlayerList("#bot") currentbot = None currentlevel = 0 for botid in botlist: level = 1 if int(botid.get("teamid")) == prefteam: level += 4 if int(botid.get("isdead")) == 1: level += 2 if level == 7: # max level, we found our bot >:) es.server.queuecmd("bot_kick " + botid.get("name")) return True if level > currentlevel: currentbot = botid currentlevel = level if currentbot: # we found at least one bot... es.server.queuecmd("bot_kick " + currentbot.get("name")) xabotmanagement.logging.log("kicked bot %s" % currentbot.get("name"), userid, True) return True # TODO: Insert a message here telling that no bots on server # message string: remove_no_bots return True
def _action_remove(userid, popupid): ''' Removes one bot, trying to conserve team balance ''' if int(es.ServerVar('bot_quota')): if int(es.getplayercount(2)) > int(es.getplayercount(3)): prefteam = 2 else: prefteam = 3 botlist = playerlib.getPlayerList('#bot') currentbot = None currentlevel = 0 for botid in botlist: level = 1 if int(botid.get('teamid')) == prefteam: level += 4 if int(botid.get('isdead')) == 1: level += 2 if level == 7: # max level, we found our bot >:) es.server.queuecmd('bot_kick '+botid.get('name')) return True if level > currentlevel: currentbot = botid currentlevel = level if currentbot: # we found at least one bot... es.server.queuecmd('bot_kick '+currentbot.get('name')) return True # TODO: Insert a message here telling that no bots on server # message string: remove_no_bots return True
def _action_remove(userid, popupid): ''' Removes one bot, trying to conserve team balance ''' if int(es.ServerVar('bot_quota')): if int(es.getplayercount(2)) > int(es.getplayercount(3)): prefteam = 2 else: prefteam = 3 botlist = playerlib.getPlayerList('#bot') currentbot = None currentlevel = 0 for botid in botlist: level = 1 if int(botid.get('teamid')) == prefteam: level += 4 if int(botid.get('isdead')) == 1: level += 2 if level == 7: # max level, we found our bot >:) es.server.queuecmd('bot_kick '+botid.get('name')) return True if level > currentlevel: currentbot = botid currentlevel = level if currentbot: # we found at least one bot... es.server.queuecmd('bot_kick '+currentbot.get('name')) xabotmanagement.logging.log("kicked bot %s" % currentbot.get('name'), userid, True ) return True # TODO: Insert a message here telling that no bots on server # message string: remove_no_bots return True
def Request_RoundType_Update(): global Grace,LastMan Infect = es.getplayercount(2) Surv = es.getplayercount(3) if not Grace and not LastMan: if not (Infect == 1 and Surv == 1): if Infect == 1: LastMan_Enable(2) if Surv == 1: LastMan_Enable(3) gamethread.delayedname(5,"Request_RoundType_Update",Request_RoundType_Update,())
def player_spawn(EV): Userid = int(EV['userid']) Team = EV['team'] Class = EV['class'] global Zombies,Survivors,Spec Request_WeaponKill_Update() if Userid in Zombies: Kill_InfectedClip(Userid) es.setplayerprop(Userid,"CTFPlayer.baseclass.m_iHealth",(4000/es.getplayercount(2))+1000) Request_SetPlayerMaxHealth(Userid,(4000/es.getplayercount(2))+1000) Request_TeamUpdate()
def Zombify_Cheap(Userid): global Zombies,Survivors,Grace es.changeteam(Userid,3) Needed = int(round(int(es.getplayercount(3))*.3))-int(es.getplayercount(2)) if Grace: if int(Needed) > 0: Zombies.append(Userid) es.changeteam(Userid,2) else: Survivors.append(Userid) es.changeteam(Userid,3) else: Request_Spectate(Userid)
def player_activate(event_var): """Calls send_prompt if the player count is at the requisite number""" int_count_option = int(var_count) if int_count_option: if int_count_option <= es.getplayercount(): send_prompt(int(event_var['userid']), str(var_ip), int(var_kick), float(var_delay))
def voteBan(): """ Executed when a player types 'voteban' in either console or chat. Build a popup of all the valid players they can ban. """ userid = str(es.getcmduserid()) if es.getplayercount() >= minBanPlayers: """ There are enough players to run the command """ myPopupInstance = popuplib.easymenu("xa_voteban_%s" % userid, "_popup_choice", voteBanCheck) myPopupInstance.settitle("Select a player to ban") for player in es.getUseridList(): """ Loop through all the players in the server """ if str(player) != userid: """ The current iteration is not equal to the user who executed the command """ myPopupInstance.addoption( player, es.getplayername(player), bool(player not in userids[userid]["bans"])) myPopupInstance.send(userid) else: """ There are not enough players, notify the user """ es.tell( userid, '#green', xalanguage("not enough players", {}, playerlib.getPlayer(userid).get("lang")))
def Request_TeamUpdate(): #Lets move the players to their respecive teams. #1 = Spectator, 2 = Infected, 3 = Survivors global Zombies,Survivors,Spec,Grace for Userid in Zombies: if es.exists('userid',Userid): if es.getplayerteam(Userid) != 2: es.changeteam(Userid,2) else: Zombies.remove(Userid) for Userid in Survivors: if es.exists('userid',Userid): if es.getplayerteam(Userid) != 3: es.changeteam(Userid,3) else: Survivors.remove(Userid) for Userid in Spec: if es.exists('userid',Userid): if es.getplayerteam(Userid) != 1: es.changeteam(Userid,1) else: Spec.remove(Userid) if es.getplayercount() > 1 and not Grace: if int(es.getplayercount(2)) == 0: es.server.queuecmd("sv_cheats 1") es.server.queuecmd("mp_forcewin 3") gamethread.delayed(.2,es.server.queuecmd,("sv_cheats 0")) if int(es.getplayercount(3)) == 0: es.server.queuecmd("sv_cheats 1") es.server.queuecmd("mp_forcewin 2") gamethread.delayed(.2,es.server.queuecmd,("sv_cheats 0")) elif es.getplayercount() == 1: if not es.isbot(es.getUseridList()[0]): es.server.queuecmd("tf_bot_add") es.server.queuecmd("tf_bot_add") Msg("Well this looks boring, lets throw some bots in.")
def Grace_Off(): global Grace Msg("Grace Period Is Over.") Grace = 0 gamethread.cancelDelayed("Grace") if es.getplayercount() > 0: Userid = es.getUseridList()[0] es.fire(Userid,"func_regenerate","setteam",1) es.fire(Userid,"func_regenerate","TeamNum",1) es.fire(Userid,"func_respawnroomvisualizer","solid_to_enemies",0) Msg("Survivor Ammo Lockers Disabled, Spawnroom Guards Disabled")
def Zombify_Random(): global Zombies,Survivors,Spec for Userid in es.getUseridList(): es.changeteam(Userid,3) Needed = abs(int(round(int(es.getplayercount())*.3))) if Needed > 1: Msg("Infecting %s Players:"%Needed) elif Needed < 0: Msg("Infecting 1 Player:") Needed = 1 if Needed > 0: Total = 0 while(Needed > Total): Userid = es.getUseridList()[random.randint(0,es.getplayercount()-1)] if es.getplayerteam(Userid) == 3 and Userid not in Zombies: Zombies.append(Userid) Total += 1 for Userid in es.getUseridList(): if Userid not in Zombies: Survivors.append(Userid) Request_TeamUpdate() list = "" size = int(len(Zombies)) if size > 1: for id in Zombies: size -= 1 list += es.getplayername(id) if size == 1: list += ", and " if int(size) > 1: list += ", " else: list += " " Msg("%s have been zombified!"%list) elif size != 0: list = es.getplayername(int(Zombies[0])) Msg("%s has been zombified!"%list) Msg("Infected will Spawn with %s health. (Based on total Infected)"%(4000/int(es.getplayercount(2))+1500))
def teamplay_round_active(EV): RM.SetRound("SD") gamethread.delayed(1.5,Overlay,("BlueZM/synergized_Disinfection.vtf",4)) if es.getplayercount() > 0: Userid = es.getUseridList()[0] es.fire(Userid,"func_regenerate","setteam",3) es.fire(Userid,"func_regenerate","TeamNum",3) es.fire(Userid,"func_respawnroomvisualizer","solid_to_enemies",1) es.fire(Userid,"trigger_capture_area","area_time_to_cap",500) Reset() Zombify_Random() gamethread.delayedname(50, "Grace", Grace_Off) Request_TeamUpdate()
def getKicksRemaining(steamid): """ Returns the amount of votes needed till a player is kicked @PARAM steamid - the steamid of the user wishing to check if we should kick them @RETURN integer - amount of votes needed to kick """ players = es.getplayercount() if steamid not in targets: return None if players >= minKickPlayers: kickAmount = targets[steamid]["kicks"] amountNeeded = players * kickPercentage / 100. if kickAmount >= amountNeeded: return 0 return ceil(amountNeeded - kickAmount) return None
def getBansRemaining(steamid): """ Returns the amount of votes needed till a player is banned @PARAM steamid - the steamid of the user wishing to check if we should ban them @RETURN integer - amount of votes needed to ban """ players = es.getplayercount() if steamid not in targets: return None if players >= minBanPlayers: banAmount = targets[steamid]["bans"] amountNeeded = players * banPercentage / 100. if banAmount >= amountNeeded: return 0 return ceil(amountNeeded - banAmount) return None
def check_player(userid): ''' If there are too many players it checks if this new one has a reserved slot ''' maxplayers = es.getmaxplayercount() pdiff = maxplayers - es.getplayercount() if pdiff <= int(xareserveslots.setting.getVariable("reserve_slots_number_of_slots")): # ok so there we are into the reserved slots... if returnReservedStatus(userid): # remember that ^^ returns true IF they do not have a reserve slot # The player is NOT allowed in a reserved slot so we kick them kickPlayer(playerlib.getPlayer(userid)) else: # they are on the res list - so kick someone else?? if int(xareserveslots.setting.getVariable("reserve_slots_allow_slot_fill")) == 0: # we are not allowing the slots to fill so lets kick someone kickPlayer(chooseKick())
def voteKick(): """ Executed when a player types 'votekick' in either console or chat. Build a popup of all the valid players they can kick. """ userid = str(es.getcmduserid()) if es.getplayercount() >= minKickPlayers: """ There are enough players to run the command """ myPopupInstance = popuplib.easymenu("xa_votekick_%s" % userid, "_popup_choice", voteKickCheck) myPopupInstance.settitle("Select a player to kick") for player in es.getUseridList(): """ Loop through all the players in the server """ if str(player) != userid: """ The current iteration is not equal to the user who executed the command """ myPopupInstance.addoption(player, es.getplayername(player), bool( player not in userids[userid]["kicks"] ) ) myPopupInstance.send(userid) else: """ There are not enough players, notify the user """ es.tell(userid, '#green', xalanguage("not enough players", {}, playerlib.getPlayer(userid).get("lang") ) )
def CC_PREP(path): if es.getplayercount() > 0: userid = es.getUseridList()[0] es.fire(userid,"BLUEZM_COLOR_CORRECT",'kill') gamethread.delayed(1,color_correct,(path,userid))
def damage(users, _damage, attacker=None, armor=False, weapon=None): '''Damage a player...''' # Is there no player on the server? if not es.getplayercount(): # Don't go further... return # Create a 'point_hurt' entity... index = es.createentity('point_hurt') # Set the entity name... es.setentityname(index, index) # Does we need to apply damage on the player's armor? if armor: # Set the damage type to fall... es.entitysetvalue(index, 'damagetype', 32) # Is any weapon specified? if weapon: # Set the classname to the given weapon... es.entitysetvalue(index, 'classname', weapon) # Set the given damage... es.entitysetvalue(index, 'damage', _damage) # Loop through all matching players... for userid in _get_matching_players(users): # Is the player dead? if es.getplayerprop(userid, 'CBasePlayer.pl.deadflag'): # Don't go further... continue # Is the given damage need to be the player health? if _damage == '#health': # Set the damage to the player health... es.entitysetvalue(index, 'damage', es.getplayerprop(userid, 'CBasePlayer.m_iHealth')) # Get the player index... player_index = es.getindexfromhandle(es.getplayerhandle(userid)) # Store the actual player name... targetname = es.entitygetvalue(index, 'targetname') # Set the player name to his index... es.setentityname(player_index, player_index) # Set the damage target... es.entitysetvalue(index, 'damagetarget', player_index) # Is there's no attacker? if not attacker: # Damage the player... es.fire(userid, index, 'Hurt') # Otherwise... else: # Damage the player... es.fire(attacker, index, 'Hurt') # Set back the player name... es.fire(userid, player_index, 'AddOutput', 'targetname %s' % targetname) # Remove the entity later... gamethread.delayedname(0.5, '_wcs_delay', _remove_entity, index)
def getplayercount(argv): result = es.getplayercount(*argv[1:]) if result is not None: sv[argv[0]] = result
def Prep(self): if es.getplayercount() > 0: es.fire(es.getUseridList()[0],"BLUEZM_OVERLAY",'kill') gamethread.delayed(.5,self.Overlay,())