diff --git a/Northstar.Client/mod/resource/northstar_client_localisation_english.txt b/Northstar.Client/mod/resource/northstar_client_localisation_english.txt index f7c5ee2d1..60258a072 100644 --- a/Northstar.Client/mod/resource/northstar_client_localisation_english.txt +++ b/Northstar.Client/mod/resource/northstar_client_localisation_english.txt @@ -312,6 +312,11 @@ 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_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 35c9e9bae..ac617a9c7 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.CustomServers/mod.json b/Northstar.CustomServers/mod.json index fa51f4d41..6735306e6 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 b77a37b2a..406b8d68d 100644 --- a/Northstar.CustomServers/mod/scripts/vscripts/mp/_base_gametype_mp.gnut +++ b/Northstar.CustomServers/mod/scripts/vscripts/mp/_base_gametype_mp.gnut @@ -30,10 +30,12 @@ struct { array specCams entity functionref( entity player, entity basePoint ) recalculateRespawnAsTitanStartPointCallback + table playerChangeTeamTimeBuffer } file void function BaseGametype_Init_MPSP() { + AddClientCommandCallback( "changeteam", ClientCommandCallbackChangeTeam ) AddSpawnCallback( "info_intermission", SetIntermissionCamera ) AddPostDamageCallback( "player", AddToTitanDamageStat ) @@ -630,6 +632,40 @@ void function SetRecalculateRespawnAsTitanStartPointCallback( entity functionref file.recalculateRespawnAsTitanStartPointCallback = callbackFunc } +bool function ClientCommandCallbackChangeTeam( entity player, array args ) +{ + if ( !GetConVarBool( "ns_allow_team_change" ) ) + 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 )