class BasePlayer(PlayerCountdown): '''Class used to interact with a specific player''' 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 dm_loaded(self): '''Called when DeathMatch is first loaded''' # Is the player alive? if not getPlayer(self.userid).isdead: # No need to spawn the player return # Is the player a spectator? if self.gg_player.team < 2: # No need to spawn the player return # Start the player's repeat self.start_repeat() def send_hudhint(self, message, tokens={}): '''Checks if a player is a bot, and sends a hudhint if not''' # Is the player a bot? if not self.isbot: # If not, send the player a hudhint message self.gg_player.hudhint(message, tokens) def check_join_team(self, args): '''Checks to see if the player needs spawned when joining a team''' # Does the command used have arguments? if not len(args) > 1: # If not, return return True # Is the player joining spectators? if args[0].lower() == 'jointeam' and int(args[1]) == 1: # Is the player's repeat active? if self.repeat.status != 1: # Stop the player's repeat self.stop_repeat() # Send a message to the player that they will not be respawned self.send_hudhint('RespawnCountdown_CancelTeam') # No need to go further return True # Is the player joining a class? if args[0].lower() == 'joinclass': # Start the player's repeat self.start_repeat() # Finally, return return True
def player_death(event_var): # Was the death caused by prop_physics? if event_var['weapon'] != 'prop_physics': return attacker = event_var['attacker'] userid = event_var['userid'] # Was there an attacker, or was it a suicide? if attacker in (userid, '0'): return # Was it a Team Kill? if event_var['es_userteam'] == event_var['es_attackerteam']: return # Get the Player instance ggPlayer = Player(attacker) # Get the multikill amount multiKill = get_level_multikill(ggPlayer.level) # Is the weapon able to be levelled up? if (not int(gg_prop_physics_nade) and ggPlayer.weapon == 'hegrenade') or ( not int(gg_prop_physics_knife) and ggPlayer.weapon == 'knife'): # Send a message if it hasn't already been sent if not ggPlayer.userid in gg_multi_messages: # Get the difference between multikill amounts killDifference = multiKill - ggPlayer.multikill # Which message should we send message = 'Cannot%sLevel_WithPropPhysics' % ( 'Skip' if killDifference == 1 else 'Increment') # Send the message msg(ggPlayer.userid, message, {'level': ggPlayer.weapon}) # Add userid to gg_multi_messages, so they don't get sent multiples gg_multi_messages.add(ggPlayer.userid) # Delay to remove userid from gg_multi_messages delayed(0, gg_multi_messages.discard, ggPlayer.userid) return # If set to 1, level the player up if multiKill == 1: # Level them up levelup_player(ggPlayer, userid) return # Multikill value is > 1 ... add 1 to the multikill ggPlayer.multikill += 1 # Finished the multikill? if ggPlayer.multikill >= multiKill: # Level them up levelup_player(ggPlayer, userid) # Increment their current multikill value else: # Message the attacker multiKill = get_level_multikill(ggPlayer.level) ggPlayer.hudhint('MultikillNotification', {'kills': ggPlayer.multikill, 'total': multiKill}) # Play the multikill sound ggPlayer.playsound('multikill')
def player_death(event_var): '''Called every time a player dies''' # Is the round active? if not ActiveInfo.round: # If not, do nothing 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 # TEAM-KILL CHECK if (event_var['es_userteam'] == event_var['es_attackerteam']): return # Get victim object ggVictim = Player(userid) # Get attacker object ggAttacker = Player(attacker) # Check the weapon was correct (Normal Kill) if event_var['weapon'] != ggAttacker.weapon: return # Don't continue if the victim is AFK if not int(gg_allow_afk_levels): # Make sure the victim is not a bot if not es.isbot(userid): # Is AFK ? if ggVictim.afk(): # Is their weapon an hegrenade # and do we allow AFK leveling? if (ggAttacker.weapon == 'hegrenade' and int(gg_allow_afk_levels_nade)): # Pass if we are allowing AFK leveling on nade level pass # Is their weapon a knife and do we allow AFK leveling? elif (ggAttacker.weapon == 'knife' and int(gg_allow_afk_levels_knife)): # Pass if we are allowing AFK leveling on knife level pass # None of the above checks apply --- continue with hudhint else: # Make sure the attacker is not a bot if es.isbot(attacker): return # Tell the attacker they victim was AFK ggAttacker.hudhint( 'PlayerAFK', {'player': event_var['es_username']}) return # Get the current level's multikill value multiKill = get_level_multikill(ggAttacker.level) # If set to 1, level the player up if multiKill == 1: # Level them up ggAttacker.levelup(1, userid, 'kill') return # Multikill value is > 1 ... add 1 to the multikill attribute ggAttacker.multikill += 1 # Finished the multikill if ggAttacker.multikill >= multiKill: # Level them up ggAttacker.levelup(1, userid, 'kill') # Increment their current multikill value else: # Play the multikill sound ggAttacker.playsound('multikill')