Add extra couch features
This commit is contained in:
@@ -6,9 +6,20 @@
|
||||
|
||||
#define PREFIX "\x01[SM] \x04"
|
||||
|
||||
// A player who keeps moving the couch the same way is reported at most once per this many seconds.
|
||||
#define LOG_REPEAT_INTERVAL 2.0
|
||||
|
||||
// So commands fail with a message instead of an unbound-native error while the core is unloaded.
|
||||
bool g_bCoreLoaded;
|
||||
|
||||
// Admins who asked to see couch interactions. Per slot, so it survives map changes.
|
||||
bool g_bLogging[MAXPLAYERS + 1];
|
||||
|
||||
// Per player: what was last reported, and when the same thing may be reported again.
|
||||
CouchMethod g_iLastMethod[MAXPLAYERS + 1];
|
||||
char g_sLastWeapon[MAXPLAYERS + 1][64];
|
||||
float g_fNextReport[MAXPLAYERS + 1];
|
||||
|
||||
public Plugin myinfo =
|
||||
{
|
||||
name = "Couch Admin",
|
||||
@@ -26,6 +37,20 @@ public void OnPluginStart()
|
||||
RegAdminCmd("sm_gotocouch", Command_GotoCouch, ADMFLAG_CHANGEMAP, "Teleports you to the couch");
|
||||
RegAdminCmd("sm_removecouch", Command_RemoveCouch, ADMFLAG_CHANGEMAP, "Removes the couch");
|
||||
RegAdminCmd("sm_couchpistolonly", Command_PistolOnly, ADMFLAG_CHANGEMAP, "sm_couchpistolonly [0|1] - only pistols and knives move the couch; no argument toggles");
|
||||
RegAdminCmd("sm_couchlog", Command_Log, ADMFLAG_CHANGEMAP, "sm_couchlog [0|1] - show who moves the couch and how in your console, grenades in chat too; no argument toggles");
|
||||
}
|
||||
|
||||
// Game time restarts with the map.
|
||||
public void OnMapStart()
|
||||
{
|
||||
for (int i = 1; i <= MAXPLAYERS; i++)
|
||||
g_fNextReport[i] = 0.0;
|
||||
}
|
||||
|
||||
public void OnClientDisconnect(int client)
|
||||
{
|
||||
g_bLogging[client] = false;
|
||||
g_fNextReport[client] = 0.0;
|
||||
}
|
||||
|
||||
public void OnAllPluginsLoaded()
|
||||
@@ -108,6 +133,19 @@ public Action Command_PistolOnly(int client, int args)
|
||||
return Plugin_Handled;
|
||||
}
|
||||
|
||||
public Action Command_Log(int client, int args)
|
||||
{
|
||||
if (!RequireInGame(client))
|
||||
return Plugin_Handled;
|
||||
|
||||
bool bEnable = !g_bLogging[client];
|
||||
if (args >= 1)
|
||||
bEnable = (GetCmdArgInt(1) != 0);
|
||||
|
||||
DoSetLogging(client, bEnable);
|
||||
return Plugin_Handled;
|
||||
}
|
||||
|
||||
bool RequireInGame(int client)
|
||||
{
|
||||
if (client >= 1 && IsClientInGame(client))
|
||||
@@ -202,6 +240,124 @@ void DoSetPistolOnly(int client, bool bEnable)
|
||||
LogAction(client, -1, "\"%L\" turned couch pistol-only mode %s.", client, bEnable ? "on" : "off");
|
||||
}
|
||||
|
||||
// Announced to everyone so players know to shoot the couch instead.
|
||||
void DoToggleUse(int client)
|
||||
{
|
||||
bool bAllow = !Couch_IsUseAllowed();
|
||||
Couch_SetUseAllowed(bAllow);
|
||||
|
||||
if (bAllow)
|
||||
ShowActivity2(client, PREFIX, "\x01Allowed pushing the \x04couch\x01 with USE.");
|
||||
else
|
||||
ShowActivity2(client, PREFIX, "\x01Disabled pushing the \x04couch\x01 with USE, it must be shot to move.");
|
||||
|
||||
LogAction(client, -1, "\"%L\" %s couch use.", client, bAllow ? "allowed" : "disallowed");
|
||||
}
|
||||
|
||||
// The tier cvars belong to the core plugin, so they are looked up by name. sName is "move" or "button".
|
||||
void DoChangeTier(int client, const char[] sName, int iDelta)
|
||||
{
|
||||
ConVar cvar = FindTierConVar(sName);
|
||||
if (cvar == null)
|
||||
return;
|
||||
|
||||
int iTier = cvar.IntValue + iDelta;
|
||||
if (iTier < 0)
|
||||
iTier = 0;
|
||||
|
||||
cvar.IntValue = iTier;
|
||||
|
||||
if (iTier == 0)
|
||||
{
|
||||
ShowActivity2(client, PREFIX, "\x01Turned off the couch \x04%s\x01 tier requirement.", sName);
|
||||
LogAction(client, -1, "\"%L\" turned off the couch %s tier requirement.", client, sName);
|
||||
}
|
||||
else
|
||||
{
|
||||
ShowActivity2(client, PREFIX, "\x01Set the couch \x04%s\x01 tier requirement to \x04%d\x01.", sName, iTier);
|
||||
LogAction(client, -1, "\"%L\" set the couch %s tier requirement to %d.", client, sName, iTier);
|
||||
}
|
||||
}
|
||||
|
||||
ConVar FindTierConVar(const char[] sName)
|
||||
{
|
||||
char sCvar[32];
|
||||
FormatEx(sCvar, sizeof(sCvar), "sm_couch_%s_tier", sName);
|
||||
return FindConVar(sCvar);
|
||||
}
|
||||
|
||||
// Only affects what this admin sees, so it is neither announced nor logged.
|
||||
void DoSetLogging(int client, bool bEnable)
|
||||
{
|
||||
g_bLogging[client] = bEnable;
|
||||
|
||||
if (bEnable)
|
||||
PrintToChat(client, PREFIX ... "\x01Couch log \x04on\x01, see your console for who moves the couch and how. Grenades also show here.");
|
||||
else
|
||||
PrintToChat(client, PREFIX ... "\x01Couch log \x04off\x01.");
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
// Couch log
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
|
||||
public void Couch_OnCouchInteraction(int couch, int client, CouchMethod method, const char[] weapon)
|
||||
{
|
||||
if (!AnyoneLogging())
|
||||
return;
|
||||
|
||||
// Held fire and shotgun pellets would flood the console; a change of weapon or method is always shown.
|
||||
float fNow = GetGameTime();
|
||||
if (fNow < g_fNextReport[client] && method == g_iLastMethod[client] && StrEqual(weapon, g_sLastWeapon[client]))
|
||||
return;
|
||||
|
||||
g_iLastMethod[client] = method;
|
||||
strcopy(g_sLastWeapon[client], sizeof(g_sLastWeapon[]), weapon);
|
||||
g_fNextReport[client] = fNow + LOG_REPEAT_INTERVAL;
|
||||
|
||||
// Plain text: the console doesn't render chat colour codes.
|
||||
char sHow[96];
|
||||
switch (method)
|
||||
{
|
||||
case CouchMethod_Bullet:
|
||||
{
|
||||
if (weapon[0] != '\0')
|
||||
FormatEx(sHow, sizeof(sHow), "shot the couch with %s", weapon);
|
||||
else
|
||||
strcopy(sHow, sizeof(sHow), "shot the couch");
|
||||
}
|
||||
case CouchMethod_Knife: strcopy(sHow, sizeof(sHow), "knifed the couch");
|
||||
case CouchMethod_Grenade: strcopy(sHow, sizeof(sHow), "hit the couch with a grenade");
|
||||
case CouchMethod_Use: strcopy(sHow, sizeof(sHow), "pushed the couch with USE");
|
||||
default: FormatEx(sHow, sizeof(sHow), "moved the couch with %s", weapon[0] != '\0' ? weapon : "something");
|
||||
}
|
||||
|
||||
// Everything goes to the console; grenades are rare and knock the couch far, so they go to chat too.
|
||||
// The userid is there so it can go straight into sm_couchban.
|
||||
int userid = GetClientUserId(client);
|
||||
for (int i = 1; i <= MaxClients; i++)
|
||||
{
|
||||
if (!g_bLogging[i] || !IsClientInGame(i))
|
||||
continue;
|
||||
|
||||
PrintToConsole(i, "[Couch] %N (#%d) %s", client, userid, sHow);
|
||||
|
||||
if (method == CouchMethod_Grenade)
|
||||
PrintToChat(i, "\x01[Couch] \x04%N\x01 (#%d) hit the couch with a \x04grenade", client, userid);
|
||||
}
|
||||
}
|
||||
|
||||
bool AnyoneLogging()
|
||||
{
|
||||
for (int i = 1; i <= MaxClients; i++)
|
||||
{
|
||||
if (g_bLogging[i])
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
// Menu
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
@@ -234,6 +390,14 @@ void ShowCouchMenu(int client)
|
||||
FormatEx(sItem, sizeof(sItem), "Pistol only: %s", Couch_IsPistolOnly() ? "ON" : "OFF");
|
||||
menu.AddItem("pistol", sItem);
|
||||
|
||||
FormatEx(sItem, sizeof(sItem), "Allow USE: %s", Couch_IsUseAllowed() ? "ON" : "OFF");
|
||||
menu.AddItem("use", sItem);
|
||||
|
||||
FormatEx(sItem, sizeof(sItem), "Log to my console: %s", g_bLogging[client] ? "ON" : "OFF");
|
||||
menu.AddItem("log", sItem);
|
||||
|
||||
menu.AddItem("tiers", "Tier requirements");
|
||||
|
||||
menu.ExitButton = true;
|
||||
menu.Display(client, MENU_TIME_FOREVER);
|
||||
}
|
||||
@@ -267,6 +431,15 @@ public int MenuHandler_Couch(Menu menu, MenuAction action, int param1, int param
|
||||
DoToggleEffect(client);
|
||||
else if (StrEqual(sInfo, "pistol"))
|
||||
DoSetPistolOnly(client, !Couch_IsPistolOnly());
|
||||
else if (StrEqual(sInfo, "use"))
|
||||
DoToggleUse(client);
|
||||
else if (StrEqual(sInfo, "log"))
|
||||
DoSetLogging(client, !g_bLogging[client]);
|
||||
else if (StrEqual(sInfo, "tiers"))
|
||||
{
|
||||
ShowTierMenu(client);
|
||||
return 0;
|
||||
}
|
||||
|
||||
ShowCouchMenu(client);
|
||||
}
|
||||
@@ -279,3 +452,73 @@ public int MenuHandler_Couch(Menu menu, MenuAction action, int param1, int param
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void ShowTierMenu(int client)
|
||||
{
|
||||
Menu menu = new Menu(MenuHandler_Tier);
|
||||
menu.SetTitle("Couch - Tier requirements");
|
||||
|
||||
AddTierItems(menu, "move", "Move");
|
||||
AddTierItems(menu, "button", "Button");
|
||||
|
||||
menu.ExitBackButton = true;
|
||||
menu.ExitButton = true;
|
||||
menu.Display(client, MENU_TIME_FOREVER);
|
||||
}
|
||||
|
||||
// Adds "<label> tier: <value>", increase and decrease. Info strings are "+move", "-move" and so on.
|
||||
void AddTierItems(Menu menu, const char[] sName, const char[] sLabel)
|
||||
{
|
||||
ConVar cvar = FindTierConVar(sName);
|
||||
int iTier = (cvar == null) ? 0 : cvar.IntValue;
|
||||
|
||||
char sItem[64], sInfo[16];
|
||||
if (iTier > 0)
|
||||
FormatEx(sItem, sizeof(sItem), "%s tier: %d", sLabel, iTier);
|
||||
else
|
||||
FormatEx(sItem, sizeof(sItem), "%s tier: OFF", sLabel);
|
||||
menu.AddItem("", sItem, ITEMDRAW_DISABLED);
|
||||
|
||||
FormatEx(sInfo, sizeof(sInfo), "+%s", sName);
|
||||
FormatEx(sItem, sizeof(sItem), "Increase %s tier", sName);
|
||||
menu.AddItem(sInfo, sItem, (cvar == null) ? ITEMDRAW_DISABLED : ITEMDRAW_DEFAULT);
|
||||
|
||||
FormatEx(sInfo, sizeof(sInfo), "-%s", sName);
|
||||
FormatEx(sItem, sizeof(sItem), "Decrease %s tier", sName);
|
||||
menu.AddItem(sInfo, sItem, (iTier > 0) ? ITEMDRAW_DEFAULT : ITEMDRAW_DISABLED);
|
||||
}
|
||||
|
||||
public int MenuHandler_Tier(Menu menu, MenuAction action, int param1, int param2)
|
||||
{
|
||||
switch (action)
|
||||
{
|
||||
case MenuAction_Select:
|
||||
{
|
||||
int client = param1;
|
||||
|
||||
char sInfo[16];
|
||||
menu.GetItem(param2, sInfo, sizeof(sInfo));
|
||||
|
||||
DoChangeTier(client, sInfo[1], (sInfo[0] == '+') ? 1 : -1);
|
||||
ShowTierMenu(client);
|
||||
}
|
||||
|
||||
case MenuAction_Cancel:
|
||||
{
|
||||
if (param2 == MenuCancel_ExitBack)
|
||||
{
|
||||
if (g_bCoreLoaded)
|
||||
ShowCouchMenu(param1);
|
||||
else
|
||||
RequireCore(param1);
|
||||
}
|
||||
}
|
||||
|
||||
case MenuAction_End:
|
||||
{
|
||||
delete menu;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user