aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWilliam Miller <william-millennium@hotmail.com>2024-11-22 11:23:21 -0300
committerGitHub <noreply@github.com>2024-11-22 15:23:21 +0100
commit13211e9037d3c2d6bf5e0c1c2ff00fb9a7b3c36b (patch)
tree5ddf9d64e60d67d1b59e0cc591ecdaff52c3392f
parentaba62bfaf4556c3b6285066b43a6063976a8d4f9 (diff)
downloadNorthstarMods-13211e9037d3c2d6bf5e0c1c2ff00fb9a7b3c36b.tar.gz
NorthstarMods-13211e9037d3c2d6bf5e0c1c2ff00fb9a7b3c36b.zip
Add button to allow players to change teams (#872)
Adds button and logic to allow players to switch teams. This is a feature used in FSU and popular on many servers. Team switch is disabled via script for some gamemodes where switching teams does not make sense.
-rw-r--r--Northstar.Client/mod/resource/northstar_client_localisation_english.txt6
-rw-r--r--Northstar.Client/mod/scripts/vscripts/ui/menu_ingame.nut21
-rw-r--r--Northstar.Custom/mod/scripts/vscripts/gamemodes/_gamemode_hidden.nut1
-rw-r--r--Northstar.Custom/mod/scripts/vscripts/gamemodes/_gamemode_inf.gnut1
-rw-r--r--Northstar.CustomServers/mod.json5
-rw-r--r--Northstar.CustomServers/mod/scripts/vscripts/mp/_base_gametype_mp.gnut49
6 files changed, 83 insertions, 0 deletions
diff --git a/Northstar.Client/mod/resource/northstar_client_localisation_english.txt b/Northstar.Client/mod/resource/northstar_client_localisation_english.txt
index f7c5ee2d..76e4fce1 100644
--- a/Northstar.Client/mod/resource/northstar_client_localisation_english.txt
+++ b/Northstar.Client/mod/resource/northstar_client_localisation_english.txt
@@ -312,6 +312,12 @@ Press Yes if you agree to this. This choice can be changed in the mods menu at a
// In-game chat
"HUD_CHAT_WHISPER_PREFIX" "[WHISPER]"
"HUD_CHAT_SERVER_PREFIX" "[SERVER]"
+
+ // Team Switching
+ "TEAMSWITCH_GAMEMODE" "Gamemode does not allow Team Switching"
+ "TEAMSWITCH_BUFFER" "Team Switching is on Cooldown"
+ "TEAMSWITCH_GAMEPLAY" "Team change not allowed outside playing phase"
+ "TEAMSWITCH_DISABLED" "Current gamemode doesn't support team change"
"NO_GAMESERVER_RESPONSE" "Couldn't reach game server"
"BAD_GAMESERVER_RESPONSE" "Game server gave an invalid response"
diff --git a/Northstar.Client/mod/scripts/vscripts/ui/menu_ingame.nut b/Northstar.Client/mod/scripts/vscripts/ui/menu_ingame.nut
index 35c9e9ba..ac617a9c 100644
--- a/Northstar.Client/mod/scripts/vscripts/ui/menu_ingame.nut
+++ b/Northstar.Client/mod/scripts/vscripts/ui/menu_ingame.nut
@@ -85,6 +85,9 @@ void function InitInGameMPMenu()
var gameHeader = AddComboButtonHeader( comboStruct, headerIndex, "#MENU_HEADER_GAME" )
var leaveButton = AddComboButton( comboStruct, headerIndex, buttonIndex++, "#LEAVE_MATCH" )
Hud_AddEventHandler( leaveButton, UIE_CLICK, OnLeaveButton_Activate )
+ var teamChangeButton = AddComboButton( comboStruct, headerIndex, buttonIndex++, "#SWITCH_TEAMS" )
+ Hud_AddEventHandler( teamChangeButton, UIE_CLICK, OnRequestTeamSwitch )
+ thread UpdateTeamSwitchButton_Threaded( teamChangeButton )
#if DEV
var devButton = AddComboButton( comboStruct, headerIndex, buttonIndex++, "Dev" )
Hud_AddEventHandler( devButton, UIE_CLICK, AdvanceMenuEventHandler( GetMenu( "DevMenu" ) ) )
@@ -700,3 +703,21 @@ void function SetTitanSelectButtonVisibleState( bool state )
Hud_Hide( file.titanSelectButton )
}
}
+
+void function UpdateTeamSwitchButton_Threaded( var button )
+{
+ while ( true )
+ {
+ Hud_SetLocked( button, !GetConVarBool( "ns_allow_team_change" ) )
+ wait 0.5
+ }
+}
+
+void function OnRequestTeamSwitch( var button )
+{
+ if ( !Hud_IsLocked( button ) )
+ {
+ ClientCommand( "changeteam" )
+ CloseAllMenus()
+ }
+}
diff --git a/Northstar.Custom/mod/scripts/vscripts/gamemodes/_gamemode_hidden.nut b/Northstar.Custom/mod/scripts/vscripts/gamemodes/_gamemode_hidden.nut
index 6729ff97..c3bdd484 100644
--- a/Northstar.Custom/mod/scripts/vscripts/gamemodes/_gamemode_hidden.nut
+++ b/Northstar.Custom/mod/scripts/vscripts/gamemodes/_gamemode_hidden.nut
@@ -11,6 +11,7 @@ void function GamemodeHidden_Init()
SetLoadoutGracePeriodEnabled( false ) // prevent modifying loadouts with grace period
SetWeaponDropsEnabled( false )
SetRespawnsEnabled( false )
+ SetGamemodeAllowsTeamSwitch( false )
Riff_ForceTitanAvailability( eTitanAvailability.Never )
Riff_ForceBoostAvailability( eBoostAvailability.Disabled )
Riff_ForceSetEliminationMode( eEliminationMode.Pilots )
diff --git a/Northstar.Custom/mod/scripts/vscripts/gamemodes/_gamemode_inf.gnut b/Northstar.Custom/mod/scripts/vscripts/gamemodes/_gamemode_inf.gnut
index 02f0799a..e03f01ad 100644
--- a/Northstar.Custom/mod/scripts/vscripts/gamemodes/_gamemode_inf.gnut
+++ b/Northstar.Custom/mod/scripts/vscripts/gamemodes/_gamemode_inf.gnut
@@ -11,6 +11,7 @@ void function GamemodeInfection_Init()
SetSpawnpointGamemodeOverride( FFA )
SetLoadoutGracePeriodEnabled( false ) // prevent modifying loadouts with grace period
SetWeaponDropsEnabled( false )
+ SetGamemodeAllowsTeamSwitch( false )
SetShouldUseRoundWinningKillReplay( true )
Riff_ForceTitanAvailability( eTitanAvailability.Never )
Riff_ForceBoostAvailability( eBoostAvailability.Disabled )
diff --git a/Northstar.CustomServers/mod.json b/Northstar.CustomServers/mod.json
index fa51f4d4..6735306e 100644
--- a/Northstar.CustomServers/mod.json
+++ b/Northstar.CustomServers/mod.json
@@ -49,6 +49,11 @@
"Name": "ns_progression_enabled",
"DefaultValue": "0",
"Flags": "ARCHIVE_PLAYERPROFILE"
+ },
+ {
+ "Name": "ns_allow_team_change",
+ "DefaultValue": "1",
+ "Flags": "REPLICATED"
}
],
"Scripts": [
diff --git a/Northstar.CustomServers/mod/scripts/vscripts/mp/_base_gametype_mp.gnut b/Northstar.CustomServers/mod/scripts/vscripts/mp/_base_gametype_mp.gnut
index b77a37b2..6b4e82d6 100644
--- a/Northstar.CustomServers/mod/scripts/vscripts/mp/_base_gametype_mp.gnut
+++ b/Northstar.CustomServers/mod/scripts/vscripts/mp/_base_gametype_mp.gnut
@@ -18,6 +18,7 @@ global function TrackTitanDamageInPlayerGameStat
global function ShouldEntTakeDamage_SPMP
global function GetTitanBuildTime
global function TitanPlayerHotDropsIntoLevel
+global function SetGamemodeAllowsTeamSwitch
global function SetRecalculateRespawnAsTitanStartPointCallback
@@ -30,10 +31,13 @@ struct {
array<entity> specCams
entity functionref( entity player, entity basePoint ) recalculateRespawnAsTitanStartPointCallback
+ table<entity, float> playerChangeTeamTimeBuffer
+ bool gamemodeTeamSwitchEnabled = true
} file
void function BaseGametype_Init_MPSP()
{
+ AddClientCommandCallback( "changeteam", ClientCommandCallbackChangeTeam )
AddSpawnCallback( "info_intermission", SetIntermissionCamera )
AddPostDamageCallback( "player", AddToTitanDamageStat )
@@ -630,6 +634,51 @@ void function SetRecalculateRespawnAsTitanStartPointCallback( entity functionref
file.recalculateRespawnAsTitanStartPointCallback = callbackFunc
}
+void function SetGamemodeAllowsTeamSwitch( bool enabled )
+{
+ file.gamemodeTeamSwitchEnabled = enabled
+}
+
+bool function ClientCommandCallbackChangeTeam( entity player, array<string> args )
+{
+ if ( !GetConVarBool( "ns_allow_team_change" ) || IsPrivateMatchSpectator( player ) )
+ return true
+
+ if ( !file.gamemodeTeamSwitchEnabled )
+ {
+ SendHudMessage( player, "#TEAMSWITCH_GAMEMODE", -1, 0.4, 255, 255, 255, 255, 0.15, 3.0, 0.5 )
+ return true
+ }
+
+ if ( !( player in file.playerChangeTeamTimeBuffer ) )
+ {
+ file.playerChangeTeamTimeBuffer[ player ] <- Time() + 5.0
+ }
+ else
+ {
+ if ( file.playerChangeTeamTimeBuffer[ player ] > Time() )
+ {
+ SendHudMessage( player, "#TEAMSWITCH_BUFFER", -1, 0.4, 255, 255, 255, 255, 0.15, 3.0, 0.5 )
+ return true
+ }
+ }
+
+ if ( player in file.playerChangeTeamTimeBuffer && file.playerChangeTeamTimeBuffer[ player ] < Time() )
+ file.playerChangeTeamTimeBuffer[ player ] = Time() + 5.0
+
+ if ( !GamePlaying() )
+ {
+ SendHudMessage( player, "#TEAMSWITCH_GAMEPLAY", -1, 0.4, 255, 255, 255, 255, 0.15, 3.0, 0.5 )
+ return true
+ }
+ if ( GetCurrentPlaylistVarInt( "max_teams", 0 ) > 1 && !IsFFAGame() )
+ SetTeam( player, GetOtherTeam( player.GetTeam() ) )
+ else
+ SendHudMessage( player, "#TEAMSWITCH_DISABLED", -1, 0.4, 255, 255, 255, 255, 0.15, 3.0, 0.5 )
+
+ return true
+}
+
// stuff to change later
bool function ShouldEntTakeDamage_SPMP( entity ent, var damageInfo )