|
CS2-Kit
C++23 library for CS2 Metamod:Source plugin development
|
Work in Progress — The player API may change.
The player module (CS2Kit::Players) tracks connected players by slot and SteamID. It is intentionally minimal — only identity and connection metadata. Plugin-specific state (admin flags, punishment cache, stats) belongs in your own managers, keyed off SteamID, not on the Player type.
Single-threaded by design. All access happens from game-thread Metamod hooks, so no mutex is needed.
PlayerManager does not hook engine callbacks itself — your plugin drives it from its own connect/disconnect hooks.
| Method | Returns | Description |
|---|---|---|
GetSlot() | int | Player's slot index (0–63) |
GetSteamID() | int64_t | 64-bit SteamID |
GetName() | const std::string& | Display name at connect time (use SetName to refresh on rename) |
GetIpAddress() | const std::string& | Connection IP |
GetConnectTime() | int64_t | Unix timestamp when the player joined |
GetPlaytime() | int64_t | Seconds since GetConnectTime |
SetName(name) | void | Update the cached name |
| Method | Returns | Description |
|---|---|---|
AddPlayer(slot, steamId, name, ip) | Player* | Create or replace the player in this slot. Returned pointer is owned by the manager. |
RemovePlayer(slot) | void | Drop the player from both indexes. |
Clear() | void | Drop all players (call from Plugin::Unload). |
GetPlayerBySlot(slot) | Player* or nullptr | O(1) slot lookup. |
GetPlayerBySteamId(steamId) | Player* or nullptr | O(1) SteamID lookup. |
FindPlayersByName(substring) | std::vector<Player*> | Case-insensitive contains match across all players. |
GetAllPlayers() | std::vector<Player*> | Snapshot of every connected player. |
GetPlayerCount() | size_t | Count of currently tracked players. |
Player* returned by any of the lookup methods is owned by PlayerManager and remains valid until:
RemovePlayer(slot) is called for that slot, orAddPlayer(slot, …) reassigns that slot (e.g., a new player joins the same slot), orClear() is called.Do not store Player* across the disconnect callback. If you need to remember a player after they leave, copy the SteamID — that is the stable identifier.
Player deliberately does not carry admin flags, mute/gag flags, or any other plugin concern. Keep that state in your own services, keyed by SteamID:
This keeps CS2Kit::Players::Player reusable across plugins that have nothing to do with admins or punishments.