# HG changeset patch # User Adam Kaminski # Date 1604064879 14400 # Fri Oct 30 09:34:39 2020 -0400 # Node ID fc84f686e7eaa833dde60768bb2f42800d48f461 # Parent a423beb3f31804d1cd7555091204d7df65c32143 Added new SBARINFO command "IfSpectator [not] [dead]", that executes a sub block if the local player is (not) a (dead) spectator. diff -r a423beb3f318 -r fc84f686e7ea docs/zandronum-history.txt --- a/docs/zandronum-history.txt Fri Oct 30 09:34:00 2020 -0400 +++ b/docs/zandronum-history.txt Fri Oct 30 09:34:39 2020 -0400 @@ -23,6 +23,7 @@ + - Added new ACS functions: SetGamemodeLimits(int limit, int value) to change gamemode limits, SetCurrentGamemode(str gamemode, bool reset) to switch gamemodes during a game, and GetCurrentGamemode() to get the gamemode being played. [Kaminsky] + - Added new console variable "sv_noobituaries" to prevent obituaries from being printed to the server console when a player dies. [Kaminsky] + - Added ACS function: SetPlayerClass(int player, str class, bool respawn) to allow changing of a player's class. [Kaminsky] ++ - Added 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 a423beb3f318 -r fc84f686e7ea src/g_shared/sbarinfo_commands.cpp --- a/src/g_shared/sbarinfo_commands.cpp Fri Oct 30 09:34:00 2020 -0400 +++ b/src/g_shared/sbarinfo_commands.cpp Fri Oct 30 09:34:39 2020 -0400 @@ -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);