# HG changeset patch # User Adam Kaminski # Date 1608525211 18000 # Sun Dec 20 23:33:31 2020 -0500 # Node ID 69aabcc96c45e1173563161661c1e5b4ac104e4a # Parent a439fc54b0eaba0aa7db18d4efeea9c0cf61fd16 Added a new SBARINFO command: IfSpectator [not] [dead] that executes a sub block if the local player is (not) a (dead) spectator. diff -r a439fc54b0ea -r 69aabcc96c45 docs/zandronum-history.txt --- a/docs/zandronum-history.txt Sun Dec 20 23:23:43 2020 -0500 +++ b/docs/zandronum-history.txt Sun Dec 20 23:33:31 2020 -0500 @@ -28,6 +28,7 @@ + - Added a new scoreboard icon that displays if a player is lagging to the server. [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] + - Added an ACS special to check whether the game is in demo or not [DoomJoshuaBoy/geNia] ++ - Added a new SBARINFO command: IfSpectator [not] [dead] that executes a sub block if the local player is (not) a (dead) spectator. [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 a439fc54b0ea -r 69aabcc96c45 src/g_shared/sbarinfo_commands.cpp --- a/src/g_shared/sbarinfo_commands.cpp Sun Dec 20 23:23:43 2020 -0500 +++ b/src/g_shared/sbarinfo_commands.cpp Sun Dec 20 23:33:31 2020 -0500 @@ -3626,6 +3626,64 @@ //////////////////////////////////////////////////////////////////////////////// +class CommandIfSpectator : public SBarInfoCommandFlowControl +{ + public: + CommandIfSpectator(SBarInfo *script) : SBarInfoCommandFlowControl(script), + negate(false), deadspectator(false) + { + } + + void Parse(FScanner &sc, bool fullScreenOffsets) + { + if (sc.CheckToken(TK_Identifier)) + { + if (sc.Compare("not")) + { + negate = true; + if (sc.CheckToken(TK_Identifier)) + { + if (sc.Compare("dead")) + deadspectator = true; + else + sc.ScriptError("Unknown identifier '%s'.", sc.String); + } + } + else if (sc.Compare("dead")) + { + deadspectator = true; + if (sc.CheckToken(TK_Identifier)) + { + if (sc.Compare("not")) + sc.ScriptError("The 'not' identifier must come first before 'dead'."); + else + sc.ScriptError("Unknown identifier '%s'.", sc.String); + } + } + else + sc.ScriptError("Unknown identifier '%s'.", sc.String); + } + SBarInfoCommandFlowControl::Parse(sc, fullScreenOffsets); + } + + void Tick(const SBarInfoMainBlock *block, const DSBarInfo *statusBar, bool hudChanged) + { + SBarInfoCommandFlowControl::Tick(block, statusBar, hudChanged); + + // [AK] Check if the local player is (not) also a dead spectator. + if(deadspectator) + SetTruth((players[consoleplayer].bDeadSpectator) ^ negate, block, statusBar); + // [AK] Otherwise, just check if they're (not) a spectator. + else + SetTruth((players[consoleplayer].bSpectating) ^ negate, block, statusBar); + } + protected: + bool negate; + bool deadspectator; +}; + +//////////////////////////////////////////////////////////////////////////////// + static const char *SBarInfoCommandNames[] = { "drawimage", "drawnumber", "drawswitchableimage", @@ -3636,6 +3694,9 @@ "isselected", "usesammo", "usessecondaryammo", "hasweaponpiece", "inventorybarnotvisible", "weaponammo", "ininventory", "alpha", + + // [AK] Zandronum-exclusive "IfSpectator" command. + "ifspectator", NULL }; @@ -3649,6 +3710,9 @@ SBARINFO_ISSELECTED, SBARINFO_USESAMMO, SBARINFO_USESSECONDARYAMMO, SBARINFO_HASWEAPONPIECE, SBARINFO_INVENTORYBARNOTVISIBLE, SBARINFO_WEAPONAMMO, SBARINFO_ININVENTORY, SBARINFO_ALPHA, + + // [AK] Zandronum-exclusive "IfSpectator" command. + SBARINFO_IFSPECTATOR, }; SBarInfoCommand *SBarInfoCommandFlowControl::NextCommand(FScanner &sc) @@ -3681,6 +3745,9 @@ case SBARINFO_WEAPONAMMO: return new CommandWeaponAmmo(script); case SBARINFO_ININVENTORY: return new CommandInInventory(script); case SBARINFO_ALPHA: return new CommandAlpha(script); + + // [AK] Zandronum-exclusive "IfSpectator" command. + case SBARINFO_IFSPECTATOR: return new CommandIfSpectator(script); } sc.ScriptError("Unknown command '%s'.\n", sc.String);