diff options
author | BobTheBob <32057864+BobTheBob9@users.noreply.github.com> | 2021-11-07 03:53:07 +0000 |
---|---|---|
committer | BobTheBob <32057864+BobTheBob9@users.noreply.github.com> | 2021-11-07 03:53:07 +0000 |
commit | 35dfd937798d105238db23ea86f90f21be46694b (patch) | |
tree | d0e1ee639bc6177649dbcbde054f1e6094fc054c /Northstar.CustomServers/mod/scripts/vscripts/_menu_callbacks.gnut | |
parent | e79a58640e1ef1ea1c3c954aefccd36c3cb55286 (diff) | |
download | NorthstarMods-35dfd937798d105238db23ea86f90f21be46694b.tar.gz NorthstarMods-35dfd937798d105238db23ea86f90f21be46694b.zip |
code cleanup, xp, postgame and some small changes
Diffstat (limited to 'Northstar.CustomServers/mod/scripts/vscripts/_menu_callbacks.gnut')
-rw-r--r-- | Northstar.CustomServers/mod/scripts/vscripts/_menu_callbacks.gnut | 39 |
1 files changed, 38 insertions, 1 deletions
diff --git a/Northstar.CustomServers/mod/scripts/vscripts/_menu_callbacks.gnut b/Northstar.CustomServers/mod/scripts/vscripts/_menu_callbacks.gnut index edb8d79d5..e8deccb02 100644 --- a/Northstar.CustomServers/mod/scripts/vscripts/_menu_callbacks.gnut +++ b/Northstar.CustomServers/mod/scripts/vscripts/_menu_callbacks.gnut @@ -3,14 +3,35 @@ global function MenuCallbacks_Init void function MenuCallbacks_Init() { AddClientCommandCallback( "LeaveMatch", ClientCommandCallback_LeaveMatch ) + AddClientCommandCallback( "GenUp", ClientCommandCallback_GenUp ) } bool function ClientCommandCallback_LeaveMatch( entity player, array<string> args ) { - thread WritePersistenceAndLeave( player ) + // note: this is imperfect if we have multiple people of the same uid on a server, but that's only a thing in testing + if ( NSIsPlayerIndexLocalPlayer( player.GetPlayerIndex() ) ) + { + foreach ( entity otherPlayer in GetPlayerArray() ) + if ( otherPlayer != player ) + thread WritePersistenceAndLeave( otherPlayer ) + + thread WritePersistenceAndLeaveForLocalPlayerOnly( player ) + } + else + thread WritePersistenceAndLeave( player ) + return true } +void function WritePersistenceAndLeaveForLocalPlayerOnly( entity player ) +{ + float time = Time() + while ( GetPlayerArray().len() != 1 && Time() < time + 5.0 ) + WaitFrame() + + WritePersistenceAndLeave( player ) +} + void function WritePersistenceAndLeave( entity player ) { // write player persistence before we leave, since leaving player might load local lobby before server writes persistence, so they won't get newest @@ -21,4 +42,20 @@ void function WritePersistenceAndLeave( entity player ) // this is a custom concommand which can be called on clients, it causes them to leave and doesn't have issues if they're host ClientCommand( player, "ns_start_reauth_and_leave_to_lobby" ) +} + +bool function ClientCommandCallback_GenUp( entity player, array<string> args ) +{ + int gen = player.GetPersistentVarAsInt( "gen" ) + if ( player.GetPersistentVarAsInt( "xp" ) == GetMaxPlayerXP() && gen < MAX_GEN ) + { + player.SetPersistentVar( "xp", 0 ) + player.SetPersistentVar( "gen", gen + 1 ) + + // ensure client updates properly + player.GenChanged() + player.XPChanged() + } + + return true }
\ No newline at end of file |