Compare commits

..
5 Commits
2 changed files with 109 additions and 9 deletions
+87 -7
View File
@@ -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));
buf.timer = timer;
g_aNotifyList.SetArray(idx, buf, sizeof(NotifyListData));
}
PrintToChatAll("\x01[SM] \x04%s\x01 is shooting the couch.", sAttackerName);
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;
}
@@ -2310,6 +2310,16 @@ NominateResult InternalNominateMap(char[] map, int owner)
return Nominate_Added;
}
public void GetMapCategory(const char[] mapname, char[] output_category, int maxlen)
{
strcopy(output_category, maxlen, "Uncategorized");
if (g_Config && g_Config.JumpToKey(mapname))
{
g_Config.GetString("MapCategory", output_category, maxlen, "Uncategorized");
g_Config.Rewind();
}
}
/* Add natives to allow nominate and initiate vote to be call */
/* native bool NominateMap(const char[] map, bool force, &NominateError:error); */
@@ -3054,7 +3064,17 @@ public int Native_SimulateMapEnd(Handle plugin, int numParams)
stock void AddMapItem(const char[] map)
{
AddMenuItem(g_VoteMenu, map, map);
char map_with_category[1024];
if (StrContains(map, "ze_") == 0)
{
GetMapCategory(map, map_with_category, sizeof(map_with_category));
Format(map_with_category, sizeof(map_with_category), "%s (%s)", map, map_with_category);
AddMenuItem(g_VoteMenu, map, map_with_category);
}
else
{
AddMenuItem(g_VoteMenu, map, map);
}
}
stock void GetMapItem(Handle menu, int position, char[] map, int mapLen)