Skip to content

Commit 8cce737

Browse files
committed
Added support for the menuselect
This command is more standard, and some players may already have these binds set, so use them if possible.
1 parent 42490ab commit 8cce737

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ https://www.youtube.com/watch?v=Be7qop6pVpI
77
When number keys are bound with the following snippet, automatically detected and the menu will look like it used to in CSS and CS:GO:
88

99
```
10-
bind 1 "slot1;css_1"
10+
bind 1 "slot1;css_1" // menuselect 1 is also supported
1111
bind 2 "slot2;css_2"
1212
...
1313
bind 9 "slot9;css_9"

src/SharpModMenu/SharpModMenu.cs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -338,6 +338,32 @@ private unsafe HookResult ProcessUserCmds(DynamicHook hook)
338338
return HookResult.Continue;
339339
}
340340

341+
[ConsoleCommand("menuselect")]
342+
public void MenuSelect(CCSPlayerController player, CommandInfo info)
343+
{
344+
if (player is null || !player.IsValid)
345+
return;
346+
var menuState = DriverInstance?.GetMenuState(player, create: true);
347+
if (menuState is null)
348+
return;
349+
350+
if (info.ArgCount < 2)
351+
{
352+
info.ReplyToCommand($"menuselect: Invalid number of arguments provided");
353+
return;
354+
}
355+
356+
var valStr = info.ArgByIndex(1);
357+
if (!int.TryParse(valStr, CultureInfo.InvariantCulture, out var val))
358+
{
359+
info.ReplyToCommand($"menuselect: Failed to parse argument as int: {valStr}");
360+
return;
361+
}
362+
363+
var key = (PlayerKey)((int)PlayerKey.SelectItem1 + (val - 1));
364+
menuState.HandleInput(key, info.CallingContext == CommandCallingContext.Console);
365+
}
366+
341367
[ConsoleCommand("css_1")]
342368
public void Css1(CCSPlayerController player, CommandInfo info)
343369
{

0 commit comments

Comments
 (0)