VoltMod
C++23 framework for CS2 server plugins
Loading...
Searching...
No Matches
Controller.hpp
Go to the documentation of this file.
1#pragma once
2
6#include <cstdint>
7// The IN_* bits Buttons() returns.
8#include <in_buttons.h>
9#include <string_view>
10
11namespace VoltMod
12{
13
14/**
15 * @brief A player's identity behind a slot: name, money, team, scoreboard row. It survives death
16 * and respawn; the body is @ref Pawn(). Its own CBaseEntity fields, such as Health, mean nothing
17 * for gameplay.
18 */
19class Controller : public Entity
20{
21public:
22 Controller() = default;
23
24 /** Prefer `runtime.Entities.Controller(slot)`. */
25 Controller(EntitySystem& entities, CEntityInstance* raw, int slot);
26
27 Controller(const Controller&) = default;
28 Controller& operator=(const Controller&) = delete;
29
30 /** @name CCSPlayerController and CBasePlayerController fields
31 * `SetPlayerName` shows on the scoreboard with the next state change, such as @ref ChangeTeam. */
32 /** @{ */
33#include <VoltMod/Schema/Generated/Wrappers/Controller.inc>
34 /** @} */
35
36 /** The slot, or -1. */
37 int Slot() const noexcept { return _slot; }
38
39 /** The living body; falsy while dead. */
40 VoltMod::Pawn Pawn() const;
41
42 /** The pawn the player's input drives: @ref Pawn while alive, the observer pawn while dead or
43 * spectating. */
45
46 /** Held buttons as `IN_*` bits, read from @ref InputPawn so they arrive while dead too. */
47 uint64_t Buttons() const;
48
49 /** The buy-menu balance; 0 when unavailable. */
50 int Money() const;
51
52 /** Does nothing when the money services are unavailable. */
53 void SetMoney(int amount) const;
54
55 void Kick(std::string_view reason) const;
56
57 /** Run one console command as this player, server-side and without a chat echo; plugins
58 * hooking ISource2GameClients::ClientCommand see it. Refuses and logs `;` and newlines. */
59 void ExecuteCommand(std::string_view command) const;
60
61 /** Does nothing for a team outside Spectator..CT or when the vtable slot did not bind. */
62 void ChangeTeam(VoltMod::Team team) const;
63
64 Status Respawn() const;
65
66private:
67 int _slot = -1;
68 /** Resolved once: callers ask for the pawn several times per wrapper. */
69 CEntityInstance* _pawn = nullptr;
70};
71
72} // namespace VoltMod
A player's identity behind a slot: name, money, team, scoreboard row. It survives death and respawn; ...
void SetMoney(int amount) const
int Slot() const noexcept
VoltMod::Pawn InputPawn() const
void ChangeTeam(VoltMod::Team team) const
uint64_t Buttons() const
Controller & operator=(const Controller &)=delete
Controller(const Controller &)=default
void ExecuteCommand(std::string_view command) const
Status Respawn() const
runtime.Entities: finds and creates entities. Everything it returns is valid for this frame only; see...
A live entity, valid for this frame only.
Definition Entity.hpp:29
A player's body: health, armor, movement, aim, weapons. The engine replaces it on every spawn; the Co...
Definition Pawn.hpp:19
static std::string ReadFile(const std::filesystem::path &path)
Definition Loader.cpp:56
std::expected< void, Error > Status
Definition Result.hpp:67
@ Kick
the client refused AddonDecision::Id too often