summaryrefslogtreecommitdiff
path: root/sourcemod/scripting/include/smlib/game.inc
diff options
context:
space:
mode:
authornavewindre <nw@moneybot.cc>2023-11-13 14:28:08 +0100
committernavewindre <nw@moneybot.cc>2023-11-13 14:28:08 +0100
commitda518fdc0f32839730ccdee8098b59c6f842d93f (patch)
treed6f856a6148c0b4d5819f88f068b7287b8044513 /sourcemod/scripting/include/smlib/game.inc
parentbc678b10830cdaef64bcc592ca2524ebe0fcdc45 (diff)
ya
Diffstat (limited to 'sourcemod/scripting/include/smlib/game.inc')
-rw-r--r--sourcemod/scripting/include/smlib/game.inc57
1 files changed, 57 insertions, 0 deletions
diff --git a/sourcemod/scripting/include/smlib/game.inc b/sourcemod/scripting/include/smlib/game.inc
new file mode 100644
index 0000000..ee3d145
--- /dev/null
+++ b/sourcemod/scripting/include/smlib/game.inc
@@ -0,0 +1,57 @@
+#if defined _smlib_game_included
+ #endinput
+#endif
+#define _smlib_game_included
+
+#include <sourcemod>
+#include <sdktools_functions>
+#include <sdktools_entinput>
+
+/*
+ * End's the game and displays the scoreboard with intermission time.
+ *
+ * @return True on success, false otherwise
+ */
+stock bool Game_End()
+{
+ int game_end = FindEntityByClassname(-1, "game_end");
+
+ if (game_end == -1) {
+ game_end = CreateEntityByName("game_end");
+
+ if (game_end == -1) {
+ ThrowError("Unable to find or create entity \"game_end\"");
+ }
+ }
+
+ return AcceptEntityInput(game_end, "EndGame");
+}
+
+/*
+ * End's the current round, allows specifying the winning
+ * team and more.
+ * This function currently works in TF2 only (it uses the game_round_win entity).
+ *
+ * @param team The winning Team, pass 0 for Sudden Death mode (no winning team)
+ * @param forceMapReset If to force the map to reset during the force respawn after the round is over.
+ * @param switchTeams If to switch the teams when the game is going to be reset.
+ * @return True on success, false otherwise
+ */
+stock bool Game_EndRound(int team=0, bool forceMapReset=false, bool switchTeams=false)
+{
+ int game_round_win = FindEntityByClassname(-1, "game_round_win");
+
+ if (game_round_win == -1) {
+ game_round_win = CreateEntityByName("game_round_win");
+
+ if (game_round_win == -1) {
+ ThrowError("Unable to find or create entity \"game_round_win\"");
+ }
+ }
+
+ DispatchKeyValue(game_round_win, "TeamNum" , (team ? "true" : "false"));
+ DispatchKeyValue(game_round_win, "force_map_reset" , (forceMapReset? "true" : "false"));
+ DispatchKeyValue(game_round_win, "switch_teams" , (switchTeams ? "true" : "false"));
+
+ return AcceptEntityInput(game_round_win, "RoundWin");
+}