From cbe461ac26891cb06d716f0a4a57e91c3e0ae6de Mon Sep 17 00:00:00 2001 From: Marisa Kirisame Date: Tue, 29 Sep 2026 18:18:33 +0100 Subject: [PATCH] Couch push scale --- Couch/scripting/CouchAdmin.sp | 100 +++++++++++++++++++++++++++++++++- 1 file changed, 99 insertions(+), 1 deletion(-) diff --git a/Couch/scripting/CouchAdmin.sp b/Couch/scripting/CouchAdmin.sp index 6d3d46f..48bbd5c 100644 --- a/Couch/scripting/CouchAdmin.sp +++ b/Couch/scripting/CouchAdmin.sp @@ -9,6 +9,9 @@ // 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 +// How much each press in the push scale menu changes sm_couch_push_scale. +#define PUSH_SCALE_STEP 0.25 + // So commands fail with a message instead of an unbound-native error while the core is unloaded. bool g_bCoreLoaded; @@ -286,6 +289,25 @@ ConVar FindTierConVar(const char[] sName) return FindConVar(sCvar); } +// Also a core plugin cvar. Rounded to the step so repeated presses don't drift, and read back +// afterwards so the announcement shows the value after the cvar's own bounds have clamped it. +void DoSetPushScale(int client, float fScale) +{ + ConVar cvar = FindConVar("sm_couch_push_scale"); + if (cvar == null) + return; + + fScale = RoundToNearest(fScale / PUSH_SCALE_STEP) * PUSH_SCALE_STEP; + if (fScale < 0.0) + fScale = 0.0; + + cvar.FloatValue = fScale; + fScale = cvar.FloatValue; + + ShowActivity2(client, PREFIX, "\x01Set the couch \x04push scale\x01 to \x04%.2fx\x01.", fScale); + LogAction(client, -1, "\"%L\" set the couch push scale to %.2f.", client, fScale); +} + // Only affects what this admin sees, so it is neither announced nor logged. void DoSetLogging(int client, bool bEnable) { @@ -393,10 +415,11 @@ void ShowCouchMenu(int client) 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"); + FormatEx(sItem, sizeof(sItem), "Couch logs (for me): %s", g_bLogging[client] ? "ON" : "OFF"); menu.AddItem("log", sItem); menu.AddItem("tiers", "Tier requirements"); + menu.AddItem("pushscale", "Push scale"); menu.ExitButton = true; menu.Display(client, MENU_TIME_FOREVER); @@ -440,6 +463,11 @@ public int MenuHandler_Couch(Menu menu, MenuAction action, int param1, int param ShowTierMenu(client); return 0; } + else if (StrEqual(sInfo, "pushscale")) + { + ShowPushScaleMenu(client); + return 0; + } ShowCouchMenu(client); } @@ -522,3 +550,73 @@ public int MenuHandler_Tier(Menu menu, MenuAction action, int param1, int param2 return 0; } + +void ShowPushScaleMenu(int client) +{ + ConVar cvar = FindConVar("sm_couch_push_scale"); + float fScale = (cvar == null) ? 1.0 : cvar.FloatValue; + + Menu menu = new Menu(MenuHandler_PushScale); + menu.SetTitle("Couch - Push scale"); + + char sItem[64]; + FormatEx(sItem, sizeof(sItem), "Push scale: %.2fx", fScale); + menu.AddItem("", sItem, ITEMDRAW_DISABLED); + + FormatEx(sItem, sizeof(sItem), "Increase push scale (+%.2f)", PUSH_SCALE_STEP); + menu.AddItem("+", sItem, (cvar == null) ? ITEMDRAW_DISABLED : ITEMDRAW_DEFAULT); + + FormatEx(sItem, sizeof(sItem), "Decrease push scale (-%.2f)", PUSH_SCALE_STEP); + menu.AddItem("-", sItem, (cvar != null && fScale > 0.0) ? ITEMDRAW_DEFAULT : ITEMDRAW_DISABLED); + + menu.AddItem("reset", "Reset push scale (1.00x)", (cvar != null && fScale != 1.0) ? ITEMDRAW_DEFAULT : ITEMDRAW_DISABLED); + + menu.ExitBackButton = true; + menu.ExitButton = true; + menu.Display(client, MENU_TIME_FOREVER); +} + +public int MenuHandler_PushScale(Menu menu, MenuAction action, int param1, int param2) +{ + switch (action) + { + case MenuAction_Select: + { + int client = param1; + + ConVar cvar = FindConVar("sm_couch_push_scale"); + if (cvar != null) + { + char sInfo[16]; + menu.GetItem(param2, sInfo, sizeof(sInfo)); + + if (StrEqual(sInfo, "+")) + DoSetPushScale(client, cvar.FloatValue + PUSH_SCALE_STEP); + else if (StrEqual(sInfo, "-")) + DoSetPushScale(client, cvar.FloatValue - PUSH_SCALE_STEP); + else if (StrEqual(sInfo, "reset")) + DoSetPushScale(client, 1.0); + } + + ShowPushScaleMenu(client); + } + + case MenuAction_Cancel: + { + if (param2 == MenuCancel_ExitBack) + { + if (g_bCoreLoaded) + ShowCouchMenu(param1); + else + RequireCore(param1); + } + } + + case MenuAction_End: + { + delete menu; + } + } + + return 0; +}