Browse Source

Plugin commit

Adds core functionality of the plugin.
nosoop 7 years ago
parent
commit
71963f1741
1 changed files with 86 additions and 0 deletions
  1. 86 0
      scripting/csrd_extended_humiliation.sp

+ 86 - 0
scripting/csrd_extended_humiliation.sp

@@ -0,0 +1,86 @@
+/**
+ * [CSRD] Extended Humiliation Round Fixes
+ * 
+ * Minor quality-of-life improvements in extended humiliation rounds.
+ * 
+ * 1.  Hides the round win panel 5 seconds after the round is over.  Pairs well with an
+ * end-round Prop Hunt system as it prevents the win panel from covering up a good amount of the
+ * screen for the rest of the humiliation period.
+ * 2.  Hides losing player health.  "The losers are all too concerned with trying to escape the
+ * victors that they don't notice how much health they have left" is what I'd like to think.
+ */
+#pragma semicolon 1
+#include <sourcemod>
+
+#include <tf2_stocks>
+
+#pragma newdecls required
+
+#define PLUGIN_VERSION "1.0.0"
+public Plugin myinfo = {
+	name = "[CSRD] Extended Humiliation Round Fixes",
+	author = "nosoop",
+	description = "Improvements to deal with extended humiliation rounds.",
+	version = PLUGIN_VERSION,
+	url = "https://git.csrd.science/"
+}
+
+#define HIDEHUD_HEALTH ( 1 << 3 )
+
+public void OnPluginStart() {
+	HookEvent("teamplay_round_win", OnRoundWin, EventHookMode_PostNoCopy);
+}
+
+public void OnRoundWin(Event event, const char[] name, bool dontBroadcast) {
+	// we could pass it so only winners have their win panel closed...
+	if ((FindConVar("mp_bonusroundtime").IntValue > 5)) {
+		CreateTimer(5.0, HideWinPanelAll);
+	}
+}
+
+public Action HideWinPanelAll(Handle timer, any discard) {
+	int clients[MAXPLAYERS], numClients;
+	
+	for (int i = 1; i <= MaxClients; i++) {
+		if (!IsClientInGame(i) || IsFakeClient(i)) {
+			continue;
+		}
+		
+		TFTeam team = TF2_GetClientTeam(i);
+		
+		if (team == TFTeam_Red || team == TFTeam_Blue) {
+			clients[numClients++] = i;
+			
+			// just set and forget; no need to reset this at round start
+			SetEntProp(i, Prop_Data, "m_iHideHUD", HIDEHUD_HEALTH);
+		}
+	}
+	
+	TF2_HideWinPanel(clients, numClients);
+}
+
+/**
+ * Based off of CTFWinPanel:FireGameEvent():
+ * https://github.com/LestaD/SourceEngine2007/blob/master/se2007/game/client/tf/tf_hud_winpanel.cpp#L103
+ * 
+ * When a client receives the `teamplay_round_start` event, it hides the win panel.
+ * `teamplay_game_over` and `tf_game_over` may also possibly work, though I didn't bother
+ * checking since it's likely they do other stuff on the client (like showing other panels or
+ * something).
+ */
+stock void TF2_HideWinPanel(const int[] clients, int numClients) {
+	if (numClients) {
+		Event event = CreateEvent("teamplay_round_start", true);
+		
+		#if SOURCEMOD_V_MAJOR >= 1 && SOURCEMOD_V_MINOR > 8
+		// avoid broadcasting event
+		event.BroadcastDisabled = true;
+		#endif
+		
+		for (int i = 0; i < numClients; i++) {
+			event.FireToClient(clients[i]);
+		}
+		
+		delete event;
+	}
+}