Couch push scale
This commit is contained in:
@@ -9,6 +9,9 @@
|
|||||||
// A player who keeps moving the couch the same way is reported at most once per this many seconds.
|
// 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
|
#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.
|
// So commands fail with a message instead of an unbound-native error while the core is unloaded.
|
||||||
bool g_bCoreLoaded;
|
bool g_bCoreLoaded;
|
||||||
|
|
||||||
@@ -286,6 +289,25 @@ ConVar FindTierConVar(const char[] sName)
|
|||||||
return FindConVar(sCvar);
|
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.
|
// Only affects what this admin sees, so it is neither announced nor logged.
|
||||||
void DoSetLogging(int client, bool bEnable)
|
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");
|
FormatEx(sItem, sizeof(sItem), "Allow USE: %s", Couch_IsUseAllowed() ? "ON" : "OFF");
|
||||||
menu.AddItem("use", sItem);
|
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("log", sItem);
|
||||||
|
|
||||||
menu.AddItem("tiers", "Tier requirements");
|
menu.AddItem("tiers", "Tier requirements");
|
||||||
|
menu.AddItem("pushscale", "Push scale");
|
||||||
|
|
||||||
menu.ExitButton = true;
|
menu.ExitButton = true;
|
||||||
menu.Display(client, MENU_TIME_FOREVER);
|
menu.Display(client, MENU_TIME_FOREVER);
|
||||||
@@ -440,6 +463,11 @@ public int MenuHandler_Couch(Menu menu, MenuAction action, int param1, int param
|
|||||||
ShowTierMenu(client);
|
ShowTierMenu(client);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
else if (StrEqual(sInfo, "pushscale"))
|
||||||
|
{
|
||||||
|
ShowPushScaleMenu(client);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
ShowCouchMenu(client);
|
ShowCouchMenu(client);
|
||||||
}
|
}
|
||||||
@@ -522,3 +550,73 @@ public int MenuHandler_Tier(Menu menu, MenuAction action, int param1, int param2
|
|||||||
|
|
||||||
return 0;
|
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;
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user