From 81809dfba9a8329f07d68d1fd66133161234effa Mon Sep 17 00:00:00 2001 From: BobTheBob <32057864+BobTheBob9@users.noreply.github.com> Date: Thu, 3 Mar 2022 20:54:59 +0000 Subject: spectator refactor and private match spectator support --- .../mod/scripts/vscripts/sh_mp_utility.gnut | 146 +++++++++++++++++++++ 1 file changed, 146 insertions(+) create mode 100644 Northstar.CustomServers/mod/scripts/vscripts/sh_mp_utility.gnut (limited to 'Northstar.CustomServers/mod/scripts/vscripts/sh_mp_utility.gnut') diff --git a/Northstar.CustomServers/mod/scripts/vscripts/sh_mp_utility.gnut b/Northstar.CustomServers/mod/scripts/vscripts/sh_mp_utility.gnut new file mode 100644 index 000000000..2e6e04f42 --- /dev/null +++ b/Northstar.CustomServers/mod/scripts/vscripts/sh_mp_utility.gnut @@ -0,0 +1,146 @@ +untyped + +globalize_all_functions + +struct +{ + table > mapModeScoreLimits +} file + +int function GetRoundScoreLimit_FromPlaylist() +{ + if ( !GameMode_IsDefined( GAMETYPE ) ) + return GetCurrentPlaylistVarInt( "roundscorelimit", 10 ) + + return GameMode_GetRoundScoreLimit( GAMETYPE ) +} + +int function GetScoreLimit_FromPlaylist() +{ + if ( GameMode_HasMapSpecificScoreLimits( GAMETYPE ) ) + return GameMode_GetMapSpecificScoreLimit( GAMETYPE ) + + if ( !GameMode_IsDefined( GAMETYPE ) ) + return GetCurrentPlaylistVarInt( "scorelimit", 10 ) + + return GameMode_GetScoreLimit( GAMETYPE ) +} + +bool function GameMode_HasMapSpecificScoreLimits( string gameType ) +{ + if ( gameType in file.mapModeScoreLimits ) + { + if ( GetMapName() in file.mapModeScoreLimits[gameType] ) + return true + } + return false +} + +int function GameMode_GetMapSpecificScoreLimit( string gameType ) +{ + return file.mapModeScoreLimits[gameType][GetMapName()] +} + +void function GameMode_SetMapSpecificScoreLimit( table mapModeScoreTable, string gameType ) +{ + Assert( !( gameType in file.mapModeScoreLimits ), "GAMETYPE has already been added to mapModeScoreLimits" ) + file.mapModeScoreLimits[gameType] <- mapModeScoreTable +} + +bool function IsSuddenDeathGameMode() +{ + return GameMode_GetSuddenDeathEnabled( GameRules_GetGameMode() ) +} + +bool function IsCaptureMode() +{ + return GameRules_GetGameMode() == CAPTURE_POINT +} + +bool function GameModeWantsToSkipBoostsAndTitanEarning() +{ + if ( Riff_TitanAvailability() == eTitanAvailability.Never ) + return true + if ( Riff_BoostAvailability() == eBoostAvailability.Disabled ) + return true + + return false +} + +IntFromEntityCompare function GetScoreboardCompareFunc() +{ + return ScoreboardCompareFuncForGamemode( GameRules_GetGameMode() ) +} + +IntFromEntityCompare function ScoreboardCompareFuncForGamemode( string gamemode ) +{ + IntFromEntityCompare func = GameMode_GetScoreCompareFunc( gamemode ) + if ( func != null ) + return func + + return CompareScore +} + + +bool function IsRoundWinningKillReplayEnabled() +{ + return expect bool ( level.nv.roundWinningKillReplayEnabled ) +} + +bool function IsRoundWinningKillReplayPlaying() +{ + return expect bool ( level.nv.roundWinningKillReplayPlaying ) +} + +bool function HasRoundScoreLimitBeenReached() //Different from RoundScoreLimit_Complete in that it only checks to see if the score required has been reached. Allows us to use it on the client to cover 90% of the cases we want +{ + if ( !IsRoundBased() ) + return false + + int roundLimit = GetRoundScoreLimit_FromPlaylist() + + if ( !roundLimit ) + return false + + int militiaScore = GameRules_GetTeamScore2( TEAM_MILITIA ) + int imcScore = GameRules_GetTeamScore2( TEAM_IMC ) + + if ( ( militiaScore >= roundLimit ) || ( imcScore >= roundLimit ) ) + return true + + return false +} + + +bool function IsTitanAvailable( entity player ) +{ + var shiftIndex = player.GetEntIndex() - 1 + var elimMask = (1 << shiftIndex) + + return (level.nv.titanAvailableBits & elimMask) != 0 +} + + + +bool function IsRespawnAvailable( entity player ) +{ + var shiftIndex = player.GetEntIndex() - 1 + var elimMask = (1 << shiftIndex) + + return (level.nv.respawnAvailableBits & elimMask) != 0 +} + +bool function IsPrivateMatchSpectator( entity player ) +{ + // JFS + #if SERVER + if ( !player.p.clientScriptInitialized ) + return false + #endif + + // NS: allow spectators on non-private_match playlists + if ( ( IsPrivateMatch() || GetConVarBool( "ns_allow_spectators" ) ) && player.GetPersistentVarAsInt( "privateMatchState" ) == 1 ) + return true + + return false +} \ No newline at end of file -- cgit v1.2.3