Merge pull request 'Add game_text style hud list for couch shooters, and remove the chat message' (#3) from Irineu/sm-plugins:master into master
Reviewed-on: #3
This commit was merged in pull request #3.
This commit is contained in:
@@ -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<int>(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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user