|
CS2-Kit
C++23 library for CS2 Metamod:Source plugin development
|
Work in Progress — The command API may change.
The command system (CS2Kit::Commands) provides a framework for registering and dispatching chat commands. It includes:
Handlers receive a CS2Kit::Players::Player* directly — no caller adapter is required.
Use CommandBuilder to define commands and register them with CommandManager:
| Method | Description |
|---|---|
CommandBuilder(name) | Constructor — sets the primary command name |
.WithAliases({...}) | Alternative names (e.g., {"k", "boot"}) |
.WithDescription(desc) | Human-readable description |
.WithUsage(usage) | Usage string shown in help |
.RequirePermission(flags) | Required admin flag string (e.g., "c" for kick) |
.WithArgs(min, max) | Argument count bounds (default: 0–99) |
.OnExecute(handler) | The command handler function |
.Build() | Returns the constructed Command |
Commands are triggered by chat messages starting with ! or .:
The CommandManager strips the prefix and matches the remaining text against registered command names and aliases.
Set a permission callback on CommandManager to integrate with your admin system:
Command handlers receive a CS2Kit::Players::Player* (the same pointer returned by PlayerManager::GetPlayerBySlot). Use caller->GetSteamID() and caller->GetName() directly.
Server-console commands are not currently dispatched through CommandManager — only chat messages are. If console support is added later, the signature will be revised then.
Handlers return a CommandResult:
By default the result is discarded after dispatch. Register a ResultCallback on CommandManager to forward Message somewhere — typically as a chat reply via Chat Output :
The callback also fires for early dispatch failures (bad arg count, permission denied) with a synthesized CommandResult like {false, "Usage: !ban <target> <minutes>"} or {false, "You do not have permission..."}, so every code path the caller hits produces feedback without each handler having to do it manually.