Skip to content

Commit

Permalink
Move all owned NPCs together with player on Team Switching (#789)
Browse files Browse the repository at this point in the history
Uses a call back that is triggered when the player switches team to update their own entities accordingly.
  • Loading branch information
Zanieon authored Apr 12, 2024
1 parent f427583 commit 9661372
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions Northstar.CustomServers/mod/scripts/vscripts/mp/_gamestate_mp.nut
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ void function PIN_GameStart()

AddCallback_OnPlayerKilled( OnPlayerKilled )
AddDeathCallback( "npc_titan", OnTitanKilled )
AddCallback_EntityChangedTeam( "player", OnPlayerChangedTeam )

RegisterSignal( "CleanUpEntitiesForRoundEnd" )
}
Expand Down Expand Up @@ -1017,3 +1018,21 @@ void function DialoguePlayWinnerDetermined()
PlayFactionDialogueToTeam( "scoring_lost", losingTeam )
}
}

/// This is to move all NPCs that a player owns from one team to the other during a match
/// Auto-Titans, Turrets, Ticks and Hacked Spectres will all move along together with the player to the new Team
/// Also possibly prevents mods that spawns other types of NPCs that players can own from breaking when switching (i.e Drones, Hacked Reapers)
void function OnPlayerChangedTeam( entity player )
{
if ( !player.hasConnected ) // Prevents players who just joined to trigger below code, as server always pre setups their teams
return

NotifyClientsOfTeamChange( player, GetOtherTeam( player.GetTeam() ), player.GetTeam() )

foreach( npc in GetNPCArray() )
{
entity bossPlayer = npc.GetBossPlayer()
if ( IsValidPlayer( bossPlayer ) && bossPlayer == player && IsAlive( npc ) )
SetTeam( npc, player.GetTeam() )
}
}

0 comments on commit 9661372

Please sign in to comment.