From cfa37daeb0ca0d47f6dc81703c03de24d5fb046f Mon Sep 17 00:00:00 2001 From: Irineu Date: Wed, 9 Sep 2026 12:20:57 -0300 Subject: [PATCH] Add game_text style hud list for couch shooters, and remove the chat message --- PropSpawner/scripting/PropSpawner.sp | 96 +++++++++++++++++++++++++--- 1 file changed, 88 insertions(+), 8 deletions(-) diff --git a/PropSpawner/scripting/PropSpawner.sp b/PropSpawner/scripting/PropSpawner.sp index df60ae0..4b533b7 100644 --- a/PropSpawner/scripting/PropSpawner.sp +++ b/PropSpawner/scripting/PropSpawner.sp @@ -21,9 +21,16 @@ Menu g_NpcMenu = null; KeyValues g_Models; ConVar g_cvNotifyShot; +ConVar g_cvNotifyTimer; ArrayList g_aSpawnedProps; // Tracks entity indices of props spawned by this plugin so we can unhook them +ArrayList g_aNotifyList; +enum struct NotifyListData +{ + int client; + Handle timer; +} public void OnPluginStart() { @@ -49,9 +56,11 @@ public void OnPluginStart() RegAdminCmd("sm_propspawner", Command_MainMenu, ADMFLAG_CHANGEMAP); //g g_cvNotifyShot = CreateConVar("sm_propspawner_notify_shot", "0", "If set to 1, announces in chat when a plugin-spawned prop is shot.", FCVAR_NOTIFY, true, 0.0, true, 1.0); + g_cvNotifyTimer = CreateConVar("sm_propspawner_notify_shot_timer", "0.5", "How long a player stays in the \"shooting couch\" list."); AutoExecConfig(true, "PropSpawner"); g_aSpawnedProps = new ArrayList(); + g_aNotifyList = new ArrayList(); HookEvent("round_end", Event_RoundEnd); } @@ -226,7 +235,7 @@ public int MainMenuHandler(Menu menu, MenuAction action, int client, int param2) } } } - return 0; + return 0; } public RotationHandler(Menu menu, MenuAction action, int client, int param2) @@ -547,7 +556,7 @@ void prop_any_create(int client) // Hook the prop so we can detect when it gets shot/damaged, and track it so we can unhook later if (g_cvNotifyShot.BoolValue) { - SetEntityFlags(prop, FL_CLIENT); //Now youre thinking with portals + SetEntityFlags(prop, FL_CLIENT); //Now youre thinking with portals SDKHook(prop, SDKHook_OnTakeDamage, OnPropTakeDamage); g_aSpawnedProps.Push(prop); } @@ -566,14 +575,85 @@ public Action OnPropTakeDamage(int victim, int &attacker, int &inflictor, float if (attacker < 1 || attacker > MaxClients || !IsClientInGame(attacker)) return Plugin_Continue; - char sPropName[64]; - GetEntPropString(victim, Prop_Data, "m_ModelName", sPropName, sizeof(sPropName)); + Handle timer = CreateTimer(g_cvNotifyTimer.FloatValue, OnNotifyTimer, attacker); + int idx = FindInNotifyList(attacker); + if (idx == -1) + { + NotifyListData data; + data.client = attacker; + data.timer = timer; + g_aNotifyList.PushArray(data, sizeof(NotifyListData)); + } + else + { + NotifyListData buf; + g_aNotifyList.GetArray(idx, buf, sizeof(NotifyListData)); + if (buf.timer != INVALID_HANDLE) + KillTimer(buf.timer); - char sAttackerName[MAX_NAME_LENGTH]; - GetClientName(attacker, sAttackerName, sizeof(sAttackerName)); - - PrintToChatAll("\x01[SM] \x04%s\x01 is shooting the couch.", sAttackerName); + buf.timer = timer; + g_aNotifyList.SetArray(idx, buf, sizeof(NotifyListData)); + } + + DisplayNotifyList(); return Plugin_Continue; } +void DisplayNotifyList() +{ + static int channel = -1; + char text[255]; + strcopy(text, sizeof(text), "Shooting Couch:\n"); + + for (int i = g_aNotifyList.Length - 1; i >= 0; i--) + { + NotifyListData buf; + g_aNotifyList.GetArray(i, buf, sizeof(NotifyListData)); + + if (!IsClientInGame(buf.client)) + { + if (buf.timer != INVALID_HANDLE) + KillTimer(buf.timer); + + g_aNotifyList.Erase(i); + continue; + } + + char clientName[32]; + GetClientName(buf.client, clientName, sizeof(clientName)); + StrCat(text, sizeof(text), clientName); + StrCat(text, sizeof(text), "\n"); + } + + SetHudTextParams(0.8, -1.0, g_cvNotifyTimer.FloatValue, 255, 255, 255, 255, 0, 0.0, 0.0, 0.0); + for (int i = 1; i <= MaxClients; i++) + { + if (IsClientInGame(i)) + channel = ShowHudText(i, channel, text); + } +} + +void OnNotifyTimer(Handle timer, any data) +{ + int client = view_as(data); + int idx = FindInNotifyList(client); + if (idx != -1) + g_aNotifyList.Erase(idx); + + if (g_aNotifyList.Length) + DisplayNotifyList(); +} + +int FindInNotifyList(int client) +{ + for (int i = 0; i < g_aNotifyList.Length; i++) + { + NotifyListData buf; + g_aNotifyList.GetArray(i, buf, sizeof(NotifyListData)); + if (buf.client == client) + return i; + } + + return -1; +} -- 2.47.3