# HG changeset patch # User Adam Kaminski # Date 1606647409 18000 # Sun Nov 29 05:56:49 2020 -0500 # Node ID 2c46abb35ba3fb7cf94c06b42b8d427cbc2ac042 # Parent 88c9bdf3076280ce36653903a0d73f0f9172f55c Added ACS functions: SetPlayerScore(int player, int type, int value) and GetPlayerScore(int player, int type) to get or set the player's score. The type can be either frags, points, wins, deaths, kills, or the item and secret counts. diff -r 88c9bdf30762 -r 2c46abb35ba3 docs/zandronum-history.txt --- a/docs/zandronum-history.txt Sat Nov 28 08:46:12 2020 -0500 +++ b/docs/zandronum-history.txt Sun Nov 29 05:56:49 2020 -0500 @@ -27,6 +27,7 @@ + - Added a new scoreboard icon that displays if a player is lagging to the server. [Kaminsky] + - Added new compatibility flag "compat_resetglobalvarsonmapreset" to reset all global ACS variables upon resetting the map like in survival. [Kaminsky] + - Added ACS functions: SetPlayerChasecam(int player, bool enable) and GetPlayerChasecam(int player) to enable or disable the built-in chasecam for the player. [Kaminsky] ++ - Added ACS functions: SetPlayerScore(int player, int type, int value) and GetPlayerScore(int player, int type) to get or set the player's score. The type can be either frags, points, wins, deaths, kills, or the item and secret counts. [Kaminsky] - - Fixed: Bots tries to jump to reach item when sv_nojump is true. [sleep] - - Fixed: ACS function SetSkyScrollSpeed didn't work online. [Edward-san] - - Fixed: color codes in callvote reasons weren't terminated properly. [Dusk] diff -r 88c9bdf30762 -r 2c46abb35ba3 src/cl_main.cpp --- a/src/cl_main.cpp Sat Nov 28 08:46:12 2020 -0500 +++ b/src/cl_main.cpp Sun Nov 29 05:56:49 2020 -0500 @@ -2083,6 +2083,18 @@ } break; + case SVC2_SETPLAYERDEATHS: + { + const ULONG ulPlayer = pByteStream->ReadByte(); + const int deaths = pByteStream->ReadVariable(); + + if ( PLAYER_IsValidPlayer( ulPlayer ) == false ) + break; + + players[ulPlayer].ulDeathCount = deaths; + } + break; + case SVC2_SRP_USER_START_AUTHENTICATION: case SVC2_SRP_USER_PROCESS_CHALLENGE: case SVC2_SRP_USER_VERIFY_SESSION: diff -r 88c9bdf30762 -r 2c46abb35ba3 src/network_enums.h --- a/src/network_enums.h Sat Nov 28 08:46:12 2020 -0500 +++ b/src/network_enums.h Sun Nov 29 05:56:49 2020 -0500 @@ -371,6 +371,7 @@ ENUM_ELEMENT ( SVC2_SETMAPSKYSCROLLSPEED ), ENUM_ELEMENT ( SVC2_SETLOCALPLAYERJUMPTICS ), ENUM_ELEMENT ( SVC2_STOPSOUND ), + ENUM_ELEMENT ( SVC2_SETPLAYERDEATHS ), // [BB] Commands necessary for the account system. ENUM_ELEMENT ( SVC2_SRP_USER_START_AUTHENTICATION ), ENUM_ELEMENT ( SVC2_SRP_USER_PROCESS_CHALLENGE ), diff -r 88c9bdf30762 -r 2c46abb35ba3 src/p_acs.cpp --- a/src/p_acs.cpp Sat Nov 28 08:46:12 2020 -0500 +++ b/src/p_acs.cpp Sun Nov 29 05:56:49 2020 -0500 @@ -249,6 +249,18 @@ WARPF_USEPTR = 0x2000, }; +// [AK] SetPlayerScore and GetPlayerScore +enum +{ + SCORE_FRAGS, + SCORE_POINTS, + SCORE_WINS, + SCORE_DEATHS, + SCORE_KILLS, + SCORE_ITEMS, + SCORE_SECRETS, +}; + struct CallReturn { CallReturn(int pc, ScriptFunction *func, FBehavior *module, const ACSLocalVariables &locals, ACSLocalArrays *arrays, bool discard, unsigned int runaway) @@ -5195,6 +5207,8 @@ ACSF_SetPlayerClass, ACSF_SetPlayerChasecam, ACSF_GetPlayerChasecam, + ACSF_SetPlayerScore, + ACSF_GetPlayerScore, // ZDaemon ACSF_GetTeamScore = 19620, // (int team) @@ -7311,6 +7325,113 @@ return 0; } + case ACSF_SetPlayerScore: + { + const ULONG ulPlayer = static_cast ( args[0] ); + int oldvalue; + + if ( PLAYER_IsValidPlayer( ulPlayer ) ) + { + switch ( args[1] ) + { + case SCORE_FRAGS: + { + // [AK] Keep the original value of the player's frags. + oldvalue = players[ulPlayer].fragcount; + players[ulPlayer].fragcount = args[2]; + + // [AK] If we're the server, tell the clients the player's new frag count. + if (( NETWORK_GetState() == NETSTATE_SERVER ) && ( oldvalue != players[ulPlayer].fragcount )) + SERVERCOMMANDS_SetPlayerFrags( ulPlayer ); + return 1; + } + + case SCORE_POINTS: + { + // [AK] Keep the original value of the player's points. + oldvalue = players[ulPlayer].lPointCount; + players[ulPlayer].lPointCount = args[2]; + + // [AK] If we're the server, tell the clients the player's new point count. + if (( NETWORK_GetState() == NETSTATE_SERVER ) && ( oldvalue != players[ulPlayer].lPointCount )) + SERVERCOMMANDS_SetPlayerPoints( ulPlayer ); + return 1; + } + + case SCORE_WINS: + { + // [AK] Keep the original value of the player's wins. + oldvalue = players[ulPlayer].ulWins; + players[ulPlayer].ulWins = args[2] >= 0 ? args[2] : 0; + + // [AK] If we're the server, tell the clients the player's new win count. + if (( NETWORK_GetState() == NETSTATE_SERVER ) && ( oldvalue != players[ulPlayer].ulWins )) + SERVERCOMMANDS_SetPlayerWins( ulPlayer ); + return 1; + } + + case SCORE_DEATHS: + { + // [AK] Keep the original value of the player's deaths. + oldvalue = players[ulPlayer].ulDeathCount; + players[ulPlayer].ulDeathCount = args[2] >= 0 ? args[2] : 0; + + // [AK] If we're the server, tell the clients the player's new death count. + if (( NETWORK_GetState() == NETSTATE_SERVER ) && ( oldvalue != players[ulPlayer].ulDeathCount )) + SERVERCOMMANDS_SetPlayerDeaths( ulPlayer ); + return 1; + } + + case SCORE_KILLS: + { + // [AK] Keep the original value of the player's kills. + oldvalue = players[ulPlayer].killcount; + players[ulPlayer].killcount = args[2]; + + // [AK] If we're the server, tell the clients the player's new kill count. + if (( NETWORK_GetState() == NETSTATE_SERVER ) && ( oldvalue != players[ulPlayer].killcount )) + SERVERCOMMANDS_SetPlayerKillCount( ulPlayer ); + return 1; + } + + case SCORE_ITEMS: + { + players[ulPlayer].itemcount = args[2]; + return 1; + } + + case SCORE_SECRETS: + { + players[ulPlayer].secretcount = args[2]; + return 1; + } + } + } + + return 0; + } + + case ACSF_GetPlayerScore: + { + const ULONG ulPlayer = static_cast ( args[0] ); + + if ( PLAYER_IsValidPlayer( ulPlayer ) ) + { + switch ( args[1] ) + { + case SCORE_FRAGS: return players[ulPlayer].fragcount; + case SCORE_POINTS: return players[ulPlayer].lPointCount; + case SCORE_WINS: return players[ulPlayer].ulWins; + case SCORE_DEATHS: return players[ulPlayer].ulDeathCount; + case SCORE_KILLS: return players[ulPlayer].killcount; + case SCORE_ITEMS: return players[ulPlayer].itemcount; + case SCORE_SECRETS: return players[ulPlayer].secretcount; + } + } + + return 0; + } + case ACSF_GetActorFloorTexture: { auto a = SingleActorFromTID(args[0], activator); diff -r 88c9bdf30762 -r 2c46abb35ba3 src/sv_commands.cpp --- a/src/sv_commands.cpp Sat Nov 28 08:46:12 2020 -0500 +++ b/src/sv_commands.cpp Sun Nov 29 05:56:49 2020 -0500 @@ -605,6 +605,19 @@ //***************************************************************************** // +void SERVERCOMMANDS_SetPlayerDeaths( ULONG ulPlayer, ULONG ulPlayerExtra, ServerCommandFlags flags ) +{ + if ( PLAYER_IsValidPlayer( ulPlayer ) == false ) + return; + + NetCommand command( SVC2_SETPLAYERDEATHS ); + command.addByte( ulPlayer ); + command.addVariable( players[ulPlayer].ulDeathCount ); + command.sendCommandToClients( ulPlayerExtra, flags ); +} + +//***************************************************************************** +// void SERVERCOMMANDS_SetPlayerKillCount( ULONG ulPlayer, ULONG ulPlayerExtra, ServerCommandFlags flags ) { if ( PLAYER_IsValidPlayer( ulPlayer ) == false ) diff -r 88c9bdf30762 -r 2c46abb35ba3 src/sv_commands.h --- a/src/sv_commands.h Sat Nov 28 08:46:12 2020 -0500 +++ b/src/sv_commands.h Sun Nov 29 05:56:49 2020 -0500 @@ -122,6 +122,7 @@ void SERVERCOMMANDS_SetPlayerFrags( ULONG ulPlayer, ULONG ulPlayerExtra = MAXPLAYERS, ServerCommandFlags flags = 0 ); void SERVERCOMMANDS_SetPlayerPoints( ULONG ulPlayer, ULONG ulPlayerExtra = MAXPLAYERS, ServerCommandFlags flags = 0 ); void SERVERCOMMANDS_SetPlayerWins( ULONG ulPlayer, ULONG ulPlayerExtra = MAXPLAYERS, ServerCommandFlags flags = 0 ); +void SERVERCOMMANDS_SetPlayerDeaths( ULONG ulPlayer, ULONG ulPlayerExtra = MAXPLAYERS, ServerCommandFlags flags = 0 ); void SERVERCOMMANDS_SetPlayerKillCount( ULONG ulPlayer, ULONG ulPlayerExtra = MAXPLAYERS, ServerCommandFlags flags = 0 ); void SERVERCOMMANDS_SetPlayerChatStatus( ULONG ulPlayer, ULONG ulPlayerExtra = MAXPLAYERS, ServerCommandFlags flags = 0 ); void SERVERCOMMANDS_SetPlayerConsoleStatus( ULONG ulPlayer, ULONG ulPlayerExtra = MAXPLAYERS, ServerCommandFlags flags = 0 );