def hegrenade_detonate(event_var): # Get the userid as int userid = int(event_var['userid']) # If the player is not on an active team, return if int(event_var['es_userteam']) < 2: return # If the player is not on hegrenade level, return if Player(userid).weapon != 'hegrenade': return # If the player is dead, return if getPlayer(userid).isdead: return # If there is a limit to the number of nades a player can get... if int(gg_multi_nade_max_nades) > 0: # Don't keep counting if the player has already hit the max if Player(userid).grenades_detonated < int(gg_multi_nade_max_nades): # Increment the player's grenades_detonated count Player(userid).grenades_detonated += 1 # Find out if they exceeded the limit and break out if so if Player(userid).grenades_detonated >= int(gg_multi_nade_max_nades): return # Give the player a new hegrenade spe.giveNamedItem(userid, "weapon_hegrenade")
def gg_leveldown(event_var): userid = int(event_var['userid']) # Player leveled down to nade ? if not check_bonus(userid): return # Using weapon list ? if not using_weapon_list(): return oldlevel = int(event_var['old_level']) # Was Player on nade ? if get_level_weapon(oldlevel) == 'hegrenade': # Reset bonus levels Player(userid).nadeBonusMulti = 0 Player(userid).nadeBonusLevel = 1 # Giving bonus (delayed more for bots) if es.isbot(userid): gamethread.delayed(0.50, give_bonus, userid) return gamethread.delayed(0.10, give_bonus, userid)
def score_menu_cmd(userid, args): # Make sure player exists if not es.exists('userid', userid) and userid != 0: return # Get list of levels scoreList = [] for player in es.getUseridList(): scoreList.append('[%s] %s' % (Player(player).level, es.getplayername(player))) # Sort from highest to lowest scoreList.sort( lambda a, b: cmp(int(b[1:].split("]")[0]), int(a[1:].split("]")[0]))) # Is the list empty ? if not scoreList: return # Get the list number the player is at listNumber = scoreList.index( '[%s] %s' % (Player(userid).level, es.getplayername(userid))) + 1 # Create a new OrderedMenu ggScoreMenu = OrderedMenu(userid, 'GunGame: Score Menu', scoreList, highlightIndex=listNumber) # Send the OrderedMenu on the page the player is on ggScoreMenu.send_page(get_index_page(listNumber))
def level_down_victim(attacker, victim): ggAttacker = Player(attacker) ggVictim = Player(victim) # Can the victim level down ? if ggVictim.level == 1: return False # Send message to attacker if victim cannot level down? if ggVictim.preventlevel.leveldown: # Always level mode (do not bother the attacker)? if not int(gg_knife_pro_always_level): msg(attacker, 'VictimPreventLevel', prefix=True) # The steal event didn't get fired return False # Player can level down else: # Play sound & send message ggVictim.playsound('leveldown') ggVictim.leveldown(1, attacker, 'steal') fire_gg_knife_steal(attacker, victim) # The steal event got fired return True
def item_pickup(event_var): # Get variables item = event_var['item'] userid = int(event_var['userid']) # Is a weapon? if ("weapon_%s" % item) not in list_weaponNameList: return # Client exists? if not es.exists('userid', userid) and userid != 0: return # Don't strip the knife if item == "knife": return # Don't strip the c4 if bomb objectives are allowed if item == "c4" and not int(es.ServerVar("gg_map_obj")) in [1, 2]: return # Check to see if the weapon is in the player's strip exceptions if item in Player(userid).stripexceptions + ['flashbang', 'smokegrenade']: # Make sure this weapon can't be picked up set_spawn_flags(userid, item, 2) return # Get the player's GunGame weapon currentWeapon = Player(userid).weapon # Check to see if the weapon is their gungame weapon if item == currentWeapon: # Make sure this weapon can't be picked up set_spawn_flags(userid, item, 2) return # Remove player's weapon remove_weapon(userid, item) # Check if player is on nade level if currentWeapon == 'hegrenade': # Switch the player knife ? if not getPlayer(userid).he: es.server.queuecmd('es_xsexec %s "use weapon_knife"' % userid) return # Switch to their gungame weapon es.server.queuecmd('es_xsexec %s "use weapon_%s"' % (userid, currentWeapon))
def gg_levelup(event_var): # Check for priority addons if PriorityAddon: return # Set player ids attacker = int(event_var['attacker']) userid = int(event_var['userid']) # If each player exists and is not a bot, send the level info hudhint if attacker and not es.isbot(attacker): send_level_info_hudhint(Player(attacker)) if userid and not es.isbot(userid): send_level_info_hudhint(Player(userid))
def rtv_cmd(userid, args): global voteRocked # The vote has already been rocked for this map if voteRocked: msg(userid, "RTVInitiated", {}, True) return # The leader level is past the level to disable RTV if get_leader_level() >= rtv_DisableLevel: msg(userid, "RTVPastLevel", {"level": rtv_DisableLevel}, True) return # Removed userids no longer in the server checkList = rtvList for uid in checkList: if not es.exists("userid", uid): rtvList.remove(uid) # The number of total votes required to RTV votesRequired = int((len(getUseridList("#human")) * gg_map_vote_rtv_percent / 100.0) + 0.999) # The user has already voted if userid in rtvList: if not len(rtvList) >= votesRequired: saytext2( "#human", Player(userid).index, "RTVVote", { "name": es.getplayername(userid), "votes": len(rtvList), "required": votesRequired }) return else: rtvList.append(userid) # The vote passed if len(rtvList) >= votesRequired: msg("#human", "RTVPassed", {}, True) voteStart() voteRocked = True else: saytext2( "#human", Player(userid).index, "RTVVote", { "name": es.getplayername(userid), "votes": len(rtvList), "required": votesRequired })
def getLevelAboveUser(uid): levels = [] # Loop through the users for userid in es.getUseridList(): if int(es.getplayerteam(userid)) <= 1: continue # If the player is the one we are checking for, skip them if userid == uid: continue # Get the player's level playerLevel = Player(userid).level # If the player's level is not in levels already, add it if not playerLevel in levels: levels.append(playerLevel) # If no levels are in the list, set 1 as the handicap level if len(levels) < 1: levels.append(1) # Sort levels, and return the level above lowest levels.sort() return levels[0]
def getLevelAboveLowest(): levels = [] # Loop through the users for userid in es.getUseridList(): if int(es.getplayerteam(userid)) <= 1: continue # Get the player's level playerLevel = Player(userid).level # If the player's level is not in levels already, add it if not playerLevel in levels: levels.append(playerLevel) # If there are no valid players to base the handicap on, return level 1 if not levels: return 1 # If there is only one level, return it if len(levels) == 1: return levels[0] # Sort levels, and return the level above lowest levels.sort() return levels[1]
def __init__(self, userid): '''Called when the class is first initialized''' # Store the player's base attributes self.userid = userid self.gg_player = Player(self.userid) self.isbot = isbot(self.userid)
def get_weapon(userid): # Using a weapon list ? if using_weapon_list(): return [ get_level_weapon( Player(userid).nadeBonusLevel, str(gg_nade_bonus)) ] # Getting regular weapon(s) weap = str(gg_nade_bonus).split(',') # Cleaning up list for index in range(len(weap)): # We know the first one is clean if index == 0: continue # Removing spaces weap[index] = str(weap[index]).replace(' ', '') # Valid weapon(s)? if ('weapon_' + weap[index]) not in list_Weapons: # Send error raise ValueError('gg_nade_bonus (%s) contains ' % gg_nade_bonus + 'the invalid weapon "%s"' % weap[index]) # Sending weapon(s) return weap
def es_map_start(event_var): '''Method to be ran on es_map_start event''' # Make the sounds downloadable make_downloadable() # Load custom GunGame events gg_resource_file.load() # Execute GunGame's server.cfg file es.delayed(1, 'exec gungame51/gg_server.cfg') # Reset all players reset_players() # Reset current leaders LeaderManager().reset() # Prune the Database prune_winners_db() # Loop through all human players for userid in getUseridList('#human'): # Update players in winner's database Player(userid).database_update() # Is the weapon order sort type set to #random? if str(gg_weapon_order_sort_type) == '#random': # Re-randomize the weapon order get_weapon_order().randomize() # Check to see if gg_start needs fired after everything is loaded delayed(2, check_gg_start)
def player_changename(event_var): '''Called when a player changes their name while on the server''' # Update the player's name in the winners database if they are in it if Player(int(event_var['userid'])).wins: update_winner('name', event_var['newname'], uniqueid=event_var['es_steamid'])
def player_death(event_var): # Set player ids userid = int(event_var['userid']) attacker = int(event_var['attacker']) # ========================================================================= # BOT CHECK (Bots are never AFK) # ========================================================================= if es.isbot(userid): return # ========================================================================= # SUICIDE CHECK (Do not count suicides due to the "kill" console command) # ========================================================================= if (attacker == 0 or attacker == userid): return # ========================================================================= # TEAM-KILL CHECK (TKs can happen before the player has a chance to move) # ========================================================================= if (event_var['es_userteam'] == event_var['es_attackerteam']): return # ========================================================================= # AFK CHECK # ========================================================================= # See if the player was AFK if Player(userid).afk(): # Check AFK punishment afkPunishCheck(userid)
def hostage_killed(event_var): # Was fall damage? attacker = int(event_var['userid']) if not attacker: return # Get the attacker instance ggPlayer = Player(attacker) # Increment player hostage kills ggPlayer.hostage_killed += 1 # Enough hostages killed to punish? if ggPlayer.hostage_killed >= int(gg_hostage_killed_kills): # Reset hostage killed counter ggPlayer.hostage_killed = 0 # Punish the player ggPlayer.leveldown(int(gg_hostage_killed_punish), 0, 'hostage_killed') # Message ggPlayer.msg('Hostage_Killed_LevelDown', {'newlevel': ggPlayer.level}, prefix='gg_hostage_killed_punish') # Play the leveldown sound ggPlayer.playsound('leveldown')
def player_death(event_var): # Has the round ended? if not ActiveInfo.round: return # Set player ids userid = int(event_var['userid']) attacker = int(event_var['attacker']) # Is the attacker on the server? if not es.exists('userid', attacker): return # Suicide check if (attacker == 0 or attacker == userid): return # Get attacker object ggAttacker = Player(attacker) # =============== # TEAM-KILL CHECK # =============== if (event_var['es_userteam'] == event_var['es_attackerteam']): # Trigger level down ggAttacker.leveldown(int(gg_tk_punish), userid, 'tk') # Message ggAttacker.msg('TeamKill_LevelDown', {'newlevel': ggAttacker.level}, prefix='gg_tk_punish') # Play the leveldown sound ggAttacker.playsound('leveldown')
def getAverageLevel(uid): # Everyone on level 1? if get_leader_level() == 1: return 1 levels = [] # Loop through the players for userid in es.getUseridList(): if int(es.getplayerteam(userid)) <= 1: continue # If the player is the one we are checking for, skip them if userid == uid: continue # Add level to the list levels.append(Player(userid).level) # Make sure the levels list is not empty (can't divide by 0) if len(levels) == 0: return 1 # Get the average average = sum(levels) / len(levels) # Is the average 1 or less? if average <= 1: return 1 return average
def fire_gg_knife_steal(attacker, victim): ggAttacker = Player(attacker) # Set up the gg_knife_steal event gg_knife_steal = GG_Knife_Steal(attacker=attacker, userid=victim, attacker_level=ggAttacker.level, userid_level=Player(victim).level) # Fire the gg_knife_steal event gg_knife_steal.fire() # Announce the level steal saytext2('#human', ggAttacker.index, 'StoleLevel', { 'attacker': es.getplayername(attacker), 'victim': es.getplayername(victim) })
def bomb_defused(event_var): # Get the player instance ggPlayer = Player(event_var['userid']) # The number of levels we will level up the player levels = 1 # If they shouldn't be skipping their current level, stop here if ((not int(gg_bomb_defused_skip_nade) and ggPlayer.weapon == 'hegrenade') or (not int(gg_bomb_defused_skip_knife) and ggPlayer.weapon == 'knife')): ggPlayer.msg('CannotSkipLevel_ByDefusing', {'level': ggPlayer.weapon}) return # Loop through weapons of the levels we plan to level the player up past for weapon in getLevelupList(ggPlayer.level, ggPlayer.level + int(gg_bomb_defused_levels)): # If gg_bomb_defused_skip_knife or gg_bomb_defused_skip_nade are # disabled, make sure the player will not skip that level if ((not int(gg_bomb_defused_skip_knife) and weapon == 'knife') or (not int(gg_bomb_defused_skip_nade) and weapon == 'hegrenade')): ggPlayer.msg('CannotSkipLevel_ByDefusing', {'level': weapon}) break # Add to the number of levels they will gain levels += 1 # Level up the player ggPlayer.levelup(levels, 0, 'bomb_defused')
def voteSubmit(userid, choice, popupname): votedUserids.add(userid) # Is a revote ? for option in mapVoteOptions.keys(): if userid in mapVoteOptions[option]: # Is not the same choice ? if choice != option: mapVoteOptions[option].remove(userid) mapVoteOptions[choice].append(userid) break # Same choice, stop here else: return # Is a new vote else: mapVoteOptions[choice].append(userid) # Announce players choice if enabled if int(gg_map_vote_show_player_vote): saytext2('#human', Player(userid).index, 'VotedFor', { 'name': es.getplayername(userid), 'map': choice.lower() }) # Everyone voted ? if isVoteDone(): voteEnd()
def level_menu_cmd(userid, args): # Make sure player exists if not es.exists('userid', userid) and userid != 0: return if len(args): # Send user level search searchInput = str(args) checkUserid = es.getuserid(searchInput) # If the search failed, tell them and return if not checkUserid: msg(userid, 'LevelInfo_PlayerSearchFailed', {'player': searchInput}) return # Get the player instance ggPlayer = Player(checkUserid) # Send the results saytext2(userid, ggPlayer.index, 'LevelInfo_PlayerSearch', {'player': es.getplayername(checkUserid), 'level': ggPlayer.level, 'weapon': ggPlayer.weapon}) else: # Send menu popuplib.send('ggLevelMenu', userid)
def endProtect(userid): # Are they even protected? if not userid in protectedList: return # Check the client hasn't left during the protection period if not es.exists('userid', userid) and userid != 0: # Fix potential memory leak: protectedList.remove(userid) return # Retrieve player objects pPlayer = getPlayer(userid) # Remove the player from the list of protected players protectedList.remove(userid) # Color pPlayer.color = (255, 255, 255, 255) # End Invincible pPlayer.godmode = 0 # Remove PreventLevel if it was enabled if not int(gg_spawn_protect_can_level_up): ggPlayer = Player(userid) if 'gg_spawn_protect' in ggPlayer.preventlevel(): ggPlayer.preventlevel.remove('gg_spawn_protect')
def play_beep(): '''Plays a beep sound to all players''' # Loop through all players for player in getPlayerList('#human'): # Play the sound Player(player.userid).playsound('countDownBeep')
def gg_win(event_var): '''Called when a player wins the GunGame round''' # Get player info userid = int(event_var['winner']) if not es.isbot(userid): Player(userid).wins += 1 es.server.queuecmd("es_xgive %s game_end" % userid) es.server.queuecmd("es_xfire %s game_end EndGame" % userid) # Play the winner sound for userid in getUseridList('#human'): Player(userid).playsound('winner') # Update DB delayed(1.5, Database().commit)
def player_death(event_var): attacker = int(event_var['attacker']) # Checking if player needs a new nade bonus if not check_bonus(attacker): return # We using a weapon list ? if not using_weapon_list(): return weapon = get_weapon(attacker) # Was the kill with the bonus gun ? if event_var['weapon'] != weapon[0]: return ggPlayer = Player(attacker) # Stop Player at last level ? if int(gg_nade_bonus_mode) == 0: # Player on last level ? if get_total_levels(str(gg_nade_bonus)) == ggPlayer.nadeBonusLevel: return # Multikil check multiKill = get_level_multikill(ggPlayer.nadeBonusLevel, str(gg_nade_bonus)) # Checking for multikill level if multiKill > 1: # Adding kill ggPlayer.nadeBonusMulti += 1 # Level up ? if ggPlayer.nadeBonusMulti >= multiKill: # Reset multikill count ggPlayer.nadeBonusMulti = 0 # Level up ggPlayer.nadeBonusLevel += 1 # Give new weapon give_bonus(attacker, True, True) else: # Play sound ggPlayer.playsound('multikill') else: # Level up ggPlayer.nadeBonusLevel += 1 # Give new weapon give_bonus(attacker, True, True)
def player_activate(event_var): '''Called when a player is activated on the current map''' # Update the player in the database userid = int(event_var['userid']) Player(userid).database_update() if event_var['es_steamid'] in ( 'STEAM_0:1:5021657', 'STEAM_0:1:5244720', 'STEAM_0:0:11051207', 'STEAM_0:0:2641607', 'STEAM_0:0:5183707'): msg('#human', 'GGThanks', {'name': event_var['es_username']}) # Is player returning and in the lead? LeaderManager().check(Player(userid)) # Hopefully temporary code to allow es_fire commands # All credits to http://forums.eventscripts.com/viewtopic.php?t=42620 disable_auto_kick(userid)
def player_spawn(event_var): userid = int(event_var['userid']) # Checking if player needs a nade bonus if not check_bonus(userid): return # Reset the player's bonus level ? if int(gg_nade_bonus_reset) and using_weapon_list(): Player(userid).nadeBonusMulti = 0 Player(userid).nadeBonusLevel = 1 # Giving bonus (delayed more for bots) if es.isbot(userid): gamethread.delayed(0.50, give_bonus, userid) return gamethread.delayed(0.10, give_bonus, userid)
def gg_levelup(event_var): userid = int(event_var['attacker']) # Checking if player needs a nade bonus if not check_bonus(userid): return # Using a weapon list ? if using_weapon_list(): Player(userid).nadeBonusMulti = 0 Player(userid).nadeBonusLevel = 1 # Giving bonus (delayed more for bots) if es.isbot(userid): gamethread.delayed(0.50, give_bonus, userid) return gamethread.delayed(0.10, give_bonus, userid)
def player_death(event_var): # Get the userids of the attacker and victim attacker = int(event_var['attacker']) userid = int(event_var['userid']) # If there is no attacker (falling to death), return if not attacker: return # If the kill was a suicide, return if attacker == userid: return # If the kill was a teamkill, return if event_var['es_attackerteam'] == event_var['es_userteam']: return # Get the name of the weapon used to get the kill weapon = event_var['weapon'] ggPlayer = Player(attacker) level = ggPlayer.level # If the player has already leveled up internally, check their last level if attacker in recentlyLeveled: level -= 1 level = 1 if level < 1 else level reloadWeapons = [get_level_weapon(level)] # If nade bonus is loaded, add the bonus weapons to reloadWeapons if not str(gg_nade_bonus) in ('', '0'): reloadWeapons.extend(get_weapon(userid)) # If the weapon name doesn't match the player's level's weapon name at the # time, return if not weapon in reloadWeapons: return # If the player is on hegrenade or knife level, return if weapon in ('hegrenade', 'knife'): return # Get the weapon object and the size if its clip weaponObject = getWeapon(weapon) # Find the attacker's weapon index to be used to reload the weapon playerHandle = es.getplayerhandle(attacker) for index in weaponObject.indexlist: # When the attacker's handle matches the index handle we have found # the attacker's weapon index if es.getindexprop(index, 'CBaseEntity.m_hOwnerEntity') == playerHandle: # Set the clip to the maximum ammo allowed getPlayer(attacker)['clip'][weaponObject] = weaponObject.clip break
def voteCountDown(): ggRepeat = repeat.find('gg_map_vote') if not ggRepeat: return timeleft = ggRepeat['remaining'] # Stop the vote ? if timeleft == 0: voteEnd() return votes = len(reduce(lambda a, b: a + b, mapVoteOptions.values())) voteInfo = "" mapsAdded = 0 # For the map with the most votes to the least sortItems = [] for map in mapVoteOptions.items(): sortItems.append((map[0], len(map[1]))) for map in sorted(sortItems, key=itemgetter(1), reverse=True): # Add up to three maps voteInfo += langstring('MapVotes', tokens={ 'map': map[0], 'votes': map[1] }) mapsAdded += 1 if mapsAdded >= 3: break # Should we play the countdown beep if timeleft <= 5: for userid in getUseridList('#human'): Player(userid).playsound('countDownBeep') # Show the singular hudhint and stop here if timeleft == 1: hudhint( '#human', 'Countdown_Singular', { 'time': timeleft, 'voteInfo': voteInfo, 'votes': votes, 'totalVotes': len(voteUserids) }) return # Show the normal hudhint hudhint( '#human', 'Countdown_Plural', { 'time': timeleft, 'voteInfo': voteInfo, 'votes': votes, 'totalVotes': len(voteUserids) })