GunGame Py
Note: This script needs GoldenEye: Source v4.1 to run. Also make sure you save it as Unicode not UTF8
<python> from GamePlay import PYBaseGamePlay from Utils.GEPlayerTracker import GEPlayerTracker import GEEntity, GEPlayer, GEUtil, GEWeapon, GEMPGameRules, GEGlobal
- NOTE NOTE #
- When changing the weapon list, make sure you also change the classname list
- or the weapons will not register as proper kills for the player's level
#
- The classnames for the following weapons should be substituted:
- grenade → npc_grenade
- rocket_launcher → npc_rocket
- grenade_launcher → npc_shell
- timed|proximitymine → npc_mine ##(ALL MINES ARE THE SAME CLASSNAME)##
#
- TODO: Make this a list of lists including ammo amt given at spawn
weapList = "golden_gun", "ar33", "rcp90", "auto_shotgun", "phantom", "d5k", "zmg", "kf7", "shotgun", "cmag", "sniper_rifle", "pp7", "klobb", "knife_throwing", "grenade", "knife" weapClassName = "golden_gun", "ar33", "rcp90", "auto_shotgun", "phantom", "d5k", "zmg", "kf7", "shotgun", "cmag", "sniper_rifle", "pp7", "klobb", "knife_throwing", "npc_grenade", "knife" iMaxLevel = len(weapList)-1
class GunGame(PYBaseGamePlay):
TR_SHOWROUND = "gground" TR_LEVEL = "gglevel" TR_WASINPLAY = "ggwasinplay" TR_ACTIVE = "ggactive" TR_WEAPSGIVEN = "ggweapons" def __init__(self): super(GunGame, self).__init__() self.InWarmup = True self.WaitingForPlayers = True self.StartedGame = False self.EndWarmUpTime = 0 self.RoundsPlayed = 0 self.PlayerStartLevel = 0 self.pltracker = GEPlayerTracker() # CVar Holders self.IsDM = True self.RoundLimit = 2
def GetPrintName(self): return "#GES_GP_GUNGAME_NAME" def GetHelpString(self): return "#GES_GP_GUNGAME_HELP" def GetGameDescription(self): return "GunGame"
def GetTeamPlay(self): return GEGlobal.TEAMPLAY_NONE def OnLoadGamePlay(self): self.CreateCVar("gg_avglevel", "0", "Give new players average level on join") self.CreateCVar("gg_warmup", "20", "The warm up time in seconds (Use 0 to disable warmup)") self.CreateCVar("gg_deathmatch", "1", "Enable DeathMatch mode (respawn allowed)") self.CreateCVar("gg_numrounds", "2", "This is the number of rounds that should be played. Use -1 for unlimited rounds per match. Max is 10.") self.LoadConfig() # Make sure we don't start out in wait time if we changed gameplay mid-match if GEMPGameRules.GetNumActivePlayers() >= 2: self.WaitingForPlayers = False # Setup warmup time if desired self.InWarmup = int(GEUtil.GetCVarValue("gg_warmup")) > 0 def OnCVarChanged(self, name, oldvalue, newvalue): if name == "gg_deathmatch": val = int(newvalue) if val != 0 and not self.IsDM: self.IsDM = True self.RoundsPlayed = 0 GEUtil.HudMessage( None, "Deathmatch mode was activated!", -1, -1, GEUtil.CColor(255,255,255,255), 4.0 ) GEMPGameRules.EndRound() elif val == 0: self.IsDM = False elif name == "gg_numrounds": val = int(newvalue) val = max(val, -1) val = min(val, 10) self.RoundLimit = val def OnRoundBegin(self): GEMPGameRules.AllowRoundTimer( False ) GEMPGameRules.UnlockRound() GEMPGameRules.DisableWeaponSpawns() GEMPGameRules.DisableAmmoSpawns() GEMPGameRules.DisableArmorSpawns() GEMPGameRules.ResetAllPlayersScores() leadLevel = -1 leadPlayer = -1 tie = False for i in range(32): if not GEUtil.IsValidPlayerIndex(i): continue player = GEUtil.GetMPPlayer(i) # If we have DM mode activated we need to reset everyone's level if self.IsDM: self.SetLevel( player, self.PlayerStartLevel ) pL = self.GetLevel( player ) if player.GetTeamNumber() != GEGlobal.TEAM_SPECTATOR: if pL > leadLevel: leadLevel = pL leadPlayer = i tie = False elif pL == leadLevel: tie = True self.pltracker.SetValue( player, self.TR_ACTIVE, True ) self.pltracker.SetValue( player, self.TR_WASINPLAY, True ) self.SetLevel( player, pL ) self.PrintCurLevel(player) self.GivePlayerWeapons(player) else: # Ensure we start as "not in play" self.pltracker.SetValue( player, self.TR_WASINPLAY, False ) if GEUtil.IsValidPlayerIndex(leadPlayer) and leadLevel > 0 and leadLevel < iMaxLevel: if tie: GEUtil.ClientPrintAll(GEGlobal.HUD_PRINTTALK, "#GES_GP_GUNGAME_LEADER_TIE", string(leadLevel+1) ) else: lp = GEUtil.GetMPPlayer(leadPlayer) GEUtil.ClientPrintAll(GEGlobal.HUD_PRINTTALK, "#GES_GP_GUNGAME_LEADER", lp.GetPlayerName(), string(leadLevel+1) )
if not self.InWarmup and not self.WaitingForPlayers: self.StartedGame = True self.RoundsPlayed = self.RoundsPlayed + 1 else: self.StartedGame = False def OnRoundEnd(self): for i in range(32): if not GEUtil.IsValidPlayerIndex(i): continue player = GEUtil.GetMPPlayer( i ) self.pltracker.SetValue( player, self.TR_SHOWROUND, True ) self.pltracker.SetValue( player, self.TR_WEAPSGIVEN, False ) # Reset their match score so the match report shows their final level not an accumulation if not self.IsDM and GEMPGameRules.IsGameOver(): player.SetMatchScore( self.GetLevel(player) + 1 ) def OnPlayerConnect(self, player): self.pltracker.Track(player)
self.SetLevel( player, -1 ) self.pltracker.SetValue( player, self.TR_ACTIVE, False ) self.pltracker.SetValue( player, self.TR_SHOWROUND, True ) self.pltracker.SetValue( player, self.TR_WASINPLAY, False ) self.pltracker.SetValue( player, self.TR_WEAPSGIVEN, False ) def OnPlayerDisconnect(self, player): self.pltracker.Drop( player ) def OnPlayerSpawn(self, player, isFirstSpawn): self.GivePlayerWeapons(player) self.SetLevel( player, self.GetLevel(player) ) if isFirstSpawn: GEUtil.ShowPopupHelp( player, "#GES_GP_GUNGAME_NAME", "#GES_GPH_GUNGAME_GOAL" ) if self.pltracker.GetValue( player, self.TR_SHOWROUND ): if not self.InWarmup and not self.WaitingForPlayers and self.IsDM and self.RoundLimit > 0: self.pltracker.SetValue( player, self.TR_SHOWROUND, False ) if self.RoundsPlayed < self.RoundLimit: GEUtil.HudMessage( player, "#GES_GP_GUNGAME_ROUNDCOUNT\r%i\r%i" % (self.RoundsPlayed, self.RoundLimit), -1, 0.70, GEUtil.CColor(255,255,255,255), 3.5 ) else: GEUtil.HudMessage( player, "#GES_GP_GUNGAME_FINALROUND", -1, 0.70, GEUtil.CColor(242,96,103,255), 3.5 )
def OnPlayerTeamChange(self, player, oldTeam, newTeam): if not self.IsDM and GEMPGameRules.IsRoundLocked(): if oldTeam == GEGlobal.TEAM_SPECTATOR: GEUtil.ShowPopupHelp( player, "#GES_GPH_CANTJOIN_TITLE", "#GES_GPH_CANTJOIN", "", 5.0, False ) else: GEUtil.ShowPopupHelp( player, "#GES_GPH_ELIMINATED_TITLE", "#GES_GPH_ELIMINATED", "", 5.0, False ) # Changing teams will automatically eliminate you (if the round is locked) self.pltracker.SetValue( player, self.TR_ACTIVE, False ) # If we were never in play give them starting level if not self.pltracker.GetValue( player, self.TR_WASINPLAY ): if GEUtil.GetCVarValue("gg_avglevel") != "0": self.SetLevel( player, self.AvgLevel() ) else: self.SetLevel( player, self.PlayerStartLevel ) def OnPlayerKilled(self, victim, killer, weapon): if not self.StartedGame: return #what exactly got killed? if not victim: return # Reset the victim getting their loadout self.pltracker.SetValue( victim, self.TR_WEAPSGIVEN, False ) #death by world if not killer or not weapon: self.IncrementLevel( victim, -1 ) return kId = killer.GetIndex() vId = victim.GetIndex() kL = self.GetLevel( killer ) vL = self.GetLevel( victim )
weapName = weapon.GetClassname().replace('weapon_', //).lower() # Non-DM Eliminates victim and locks the round if not self.IsDM: GEUtil.ClientPrintAll( GEGlobal.HUD_PRINTTALK, "#GES_GP_YOLT_ELIMINATED", victim.GetPlayerName() ) GEUtil.EmitGameplayEvent( "gg_eliminated", "%i" % victim.GetUserID(), "%i" % killer.GetUserID() ) GEUtil.ShowPopupHelp( victim, "#GES_GPH_ELIMINATED_TITLE", "#GES_GPH_ELIMINATED", "", 5.0, False ) self.pltracker.SetValue( victim, self.TR_ACTIVE, False ) GEMPGameRules.LockRound()
if vId == kId: # Suicide drops our level self.IncrementLevel( killer, -1 ) elif weapName == weapClassName[[kL]] or weapName == "knife" or weapName == "slappers": if weapName == "knife" and vL > 0: self.IncrementLevel( victim, -1 ) GEUtil.ClientPrintAll(GEGlobal.HUD_PRINTTALK, "#GES_GP_GUNGAME_KNIFED", victim.GetCleanPlayerName() ) GEUtil.EmitGameplayEvent( "gg_levelchange", "%i" % victim.GetUserID(), "%i" % (self.GetLevel(victim)+1), "knifed" ) if weapName == "slappers": if vL > 0: self.IncrementLevel( victim, -1 ) GEUtil.ClientPrintAll(GEGlobal.HUD_PRINTTALK, "#GES_GP_GUNGAME_SLAPPED", victim.GetCleanPlayerName(), killer.GetCleanPlayerName() ) GEUtil.EmitGameplayEvent( "gg_levelchange", "%i" % victim.GetUserID(), "%i" % (self.GetLevel(victim)+1), "slapped" ) else: GEUtil.ClientPrintAll(GEGlobal.HUD_PRINTTALK, "#GES_GP_GUNGAME_SLAPPED_NOLOSS", victim.GetCleanPlayerName(), killer.GetCleanPlayerName() )
killer.SetArmor( int(GEGlobal.GE_MAX_ARMOR) ) self.IncrementLevel( killer, 1 ) GEUtil.EmitGameplayEvent( "gg_levelchange", "%i" % killer.GetUserID(), "%i" % (self.GetLevel(killer)+1) ) if self.GetLevel(killer) > iMaxLevel: GEMPGameRules.SetPlayerWinner(killer) if self.RoundLimit == -1 or self.RoundsPlayed < self.RoundLimit: GEMPGameRules.EndRound() else: GEMPGameRules.EndMatch() else: self.PrintCurLevel(killer) self.GivePlayerWeapons(killer) def OnThink(self):
# Check for insufficient player count if GEMPGameRules.GetNumActivePlayers() < 2: self.StartedGame = False self.InWarmup = False self.WaitingForPlayers = True return elif self.WaitingForPlayers: # We have a new player, end waiting and begin warmup (if set) self.WaitingForPlayers = False self.InWarmup = True warmuptime = int( GEUtil.GetCVarValue("gg_warmup") ) if warmuptime > 0: self.EndWarmUpTime = GEUtil.GetTime() + warmuptime GEUtil.EmitGameplayEvent( "gg_startwarmup" ) else: self.EndWarmUpTime = GEUtil.GetTime() - 1.0 if self.InWarmup and GEUtil.GetTime() > self.EndWarmUpTime: # We finished warmup, restart the round and start the game self.InWarmup = False self.EndWarmUpTime = 0 GEUtil.EmitGameplayEvent( "gg_endwarmup" ) GEUtil.HudMessage( None, "#GES_GP_GETREADY", -1, -1, GEUtil.CColor(255,255,255,255), 2.5 ) GEMPGameRules.EndRound(False) return
elif self.InWarmup: # We are in warmup, display our time left GEUtil.ClientPrintAll( GEGlobal.HUD_PRINTCENTER, "Warm Up: %02.0f" % (self.EndWarmUpTime - GEUtil.GetTime()) ) return
# In DM mode we don't care about how many players are left alive if GEUtil.GetCVarValue("gg_deathmatch") != "0": return
if GEMPGameRules.GetNumAlivePlayers() <= 1: GEMPGameRules.EndRound() def CanPlayerHaveWeapon(self, player, weapon ): if not weapon or not player: return False # Allow the default loadout to be given to the player before GivePlayerWeapons() is called if not self.pltracker.GetValue( player, self.TR_WEAPSGIVEN ): return True
name = weapon.GetClassname().replace('weapon_', ).lower() pL = self.pltracker.GetValue( player, self.TR_LEVEL ) if pL < 0 or pL > iMaxLevel: return True if name == weapListpL or name == “knife” or name == “slappers”: return True return False def CanPlayerRespawn(self, player): if not player: return False if not self.StartedGame: return True if GEUtil.GetCVarValue(“gg_deathmatch”) == “0”: return self.pltracker.GetValue( player, self.TR_ACTIVE ) return True def OnPlayerSay(self, player, text): if text == “!level”: self.PrintCurLevel( player ) return True elif text == “!weapons”: self.PrintWeapons( player ) return True elif text == “!commands”: self.PrintCommands( player ) return True return False #——————-# - Utility Functions # #——————-# def GetLevel(self, player): if not player: return -1 return self.pltracker.GetValue( player, self.TR_LEVEL ) def SetLevel(self, player, lvl): if not player: return # Bound us! lvl = max(lvl, 0) # Set Level self.pltracker.SetValue( player, self.TR_LEVEL, lvl ) # Set Score player.SetScore( lvl + 1 ) def IncrementLevel(self, player, amt): self.SetLevel( player, self.pltracker.GetValue( player, self.TR_LEVEL ) + amt ) def PrintCurLevel(self, player): lvl = self.GetLevel(player) if not player or lvl > iMaxLevel: return if lvl >= 0: weapName = GEUtil.WeaponPrintName( “weapon_%s” % weapListlvl ) GEUtil.ClientPrintPlayer(player, GEGlobal.HUD_PRINTTALK, “%s1 %s2”, “^lLevel %i: ^y” % (lvl+1), “%s” % (weapName)) else: GEUtil.ClientPrintPlayer(player, GEGlobal.HUD_PRINTTALK, “^lYou are not in play” ) def GivePlayerWeapons(self, player ): if not player: return lvl = self.GetLevel( player ) if player.IsDead() or lvl < 0 or lvl > iMaxLevel: return player.StripAllWeapons() player.GiveNamedWeapon(“weapon_slappers”, 0) player.GiveNamedWeapon(“weapon_knife”, 0) curWeap = “weapon_%s” % weapListlvl if lvl != iMaxLevel: if curWeap == “weapon_grenade”: player.GiveNamedWeapon(curWeap, 1) else: player.GiveNamedWeapon(curWeap, 90) player.SwitchToWeapon( curWeap ) else: player.SwitchToWeapon( “weapon_knife” ) self.pltracker.SetValue(player, self.TR_WEAPSGIVEN, True) def AvgLevel(self): level = 0 count = 0 for i in range(32): if not GEUtil.IsValidPlayerIndex(i): continue player = GEUtil.GetMPPlayer(i) if player.GetTeamNumber() != GEGlobal.TEAM_SPECTATOR and self.GetLevel( player ) != -1: level += self.GetLevel( player ) count += 1 if count == 0: return 0 return int(level / count) def PrintWeapons(self, player ): if not player: return GEUtil.ClientPrintPlayer(player, GEGlobal.HUD_PRINTTALK, “^l—————————————————-”) GEUtil.ClientPrintPlayer(player, GEGlobal.HUD_PRINTTALK, “ GunGame Weapons Order”) GEUtil.ClientPrintPlayer(player, GEGlobal.HUD_PRINTTALK, “^l—————————————————-”) for i in range(iMaxLevel): GEUtil.ClientPrintPlayer( player, GEGlobal.HUD_PRINTTALK, “%i: %s” % (i+1, weapListi.replace('_',' ').capitalize()) ) GEUtil.ClientPrintPlayer(player, GEGlobal.HUD_PRINTTALK, “^l—————————————————-”) def PrintCommands(self, player ): if not player: return GEUtil.ClientPrintPlayer(player, GEGlobal.HUD_PRINTTALK, “^l————————————-”) GEUtil.ClientPrintPlayer(player, GEGlobal.HUD_PRINTTALK, “Type !level for current level”) GEUtil.ClientPrintPlayer(player, GEGlobal.HUD_PRINTTALK, “Type !weapons for weapon order”) GEUtil.ClientPrintPlayer(player, GEGlobal.HUD_PRINTTALK, “^l————————————-”) </python>