Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added GetArgs #663

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions managed/CounterStrikeSharp.API/Modules/Commands/CommandInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,20 @@ internal CommandInfo(IntPtr pointer, CCSPlayerController? player)

public string ArgByIndex(int index) => NativeAPI.CommandGetArgByIndex(Handle, index);
public string GetArg(int index) => NativeAPI.CommandGetArgByIndex(Handle, index);


public IEnumerable<string> GetArgs(int startIndex = 0, int endIndex = -1)
{
var args = ArgString.Split(' ', StringSplitOptions.RemoveEmptyEntries);
int lastIndex = args.Length - 1;

startIndex = Math.Clamp(startIndex, 0, lastIndex);
endIndex = Math.Clamp(endIndex < 0 ? lastIndex : endIndex, startIndex, lastIndex);

return startIndex == endIndex ?
[args[startIndex]] :
args[startIndex..(endIndex + 1)];
}

/// <summary>
/// Whether or not the command was sent via Console or Chat.
/// </summary>
Expand Down Expand Up @@ -87,4 +100,4 @@ public void ReplyToCommand(string message)
}
}
}
}
}
Loading