VoltMod
C++23 framework for CS2 server plugins
Loading...
Searching...
No Matches
Pawn.hpp
Go to the documentation of this file.
1#pragma once
2
7#include <cstdint>
8#include <string>
9#include <string_view>
10#include <vector>
11
12namespace VoltMod
13{
14
15/** The tick to hold fire until when holding it every frame: past what a client predicts, so it shows
16 * no shot or recoil, and moved in steps, so the weapon's networked ticks change once a step. */
17int HoldFireTick(const Clock& clock);
18
19/** A standing player's collision box, in units from their feet. */
21{
22 static constexpr float HalfWidth = 16.0f;
23 static constexpr float Height = 72.0f;
24 /** The tallest ledge a player walks up without jumping. */
25 static constexpr float StepHeight = 18.0f;
26 static inline const Vector Mins{-HalfWidth, -HalfWidth, 0.0f};
27 static inline const Vector Maxs{HalfWidth, HalfWidth, Height};
28};
29
30/**
31 * @brief A player's body: health, armor, movement, aim, weapons. The engine replaces it on every
32 * spawn; the @ref Controller is the identity that stays.
33 */
34class Pawn : public Entity
35{
36public:
37 using Entity::Entity;
38
39 /** @name CCSPlayerPawn, CBasePlayerPawn and CBaseModelEntity fields
40 * `VelocityModifier` decays back toward 1 on its own, and `ViewOffset` is the eye height. */
41 /** @{ */
42#include <VoltMod/Schema/Generated/Wrappers/Pawn.inc>
43 /** @} */
44
45 bool IsAlive() const { return _e != nullptr && LifeState() == LIFE_ALIVE; }
46
47 bool IsOnGround() const { return (Flags() & FL_ONGROUND) != 0; }
48
49 /** Where shots start: the origin plus the view offset. */
50 Vector EyePosition() const;
51
52 /** The unit vector the player aims along. */
53 Vector EyeForward() const;
54
55 /** Does nothing when the CommitSuicide index did not bind. */
56 void Slay() const;
57
58 /** The FL_GODMODE flag, which is what makes a CS2 pawn take no damage. */
59 bool Godmode() const { return (Flags() & FL_GODMODE) != 0; }
60 void SetGodmode(bool on) const;
61
62 /** Set the pawn's velocity and lift it off the ground this tick, so the engine keeps the velocity.
63 * SetAbsVelocity alone leaves a grounded pawn grounded. */
64 void SetVelocity(Vector velocity) const;
65
66 /** Add @p amount health, up to MaxHealth. False when nothing changed, such as a dead pawn. */
67 bool Heal(int amount) const;
68
69 /** Give an item by class name, such as "weapon_ak47". A weapon the pawn's team cannot buy is
70 * given through a same-frame team swap. The given item; falsy when the engine refused it. */
71 Entity GiveItem(std::string_view item) const;
72
73 /** Give the default knife of the pawn's team: "weapon_knife" is the CT one. */
74 Entity GiveKnife() const;
75
76 /** Remove every weapon, and with @p removeSuit the armor and defuse kit too. */
77 bool StripWeapons(bool removeSuit = true) const;
78
79 /** The carried weapons, knife and grenades included. */
80 std::vector<Entity> Weapons() const;
81
82 /** Draw @p weapon. Does nothing for a weapon the pawn does not carry, or when the SelectItem index
83 * did not bind. */
84 void SelectWeapon(const Entity& weapon) const;
85
86 /** Remove @p weapon through the engine's input queue, so it is safe inside a death event. A weapon in a
87 * live pawn's hand is first swapped for the one held before it. */
88 void RemoveWeapon(const Entity& weapon) const;
89
90 /** The weapon in hand; falsy when there is none. */
91 Entity ActiveWeapon() const;
92
93 /** Keep the weapon in hand from either attack before engine tick @p tick. A weapon switched to
94 * later is not covered, so call it every frame to hold fire for a while. */
95 void HoldFire(int tick) const;
96
97 /** @ref HoldFire until @ref HoldFireTick; call it every frame to hold fire. */
98 void HoldFire(const Clock& clock) const;
99
100 /** Keep the pawn crouched whatever its player holds; call it every frame to hold it. Each step of
101 * @p amount past 1 lowers the eye 18 units more. */
102 void HoldCrouch(float amount = 1.0f) const;
103 /** Let the pawn stand up again once its player lets go of crouch. */
104 void ReleaseCrouch() const;
105
108
109 /** Current model path; empty when unavailable. */
110 std::string ModelName() const;
111
112 /** The owning player's controller. */
114
115 /** The owning player's slot, or -1. Constant time. */
116 int Slot() const;
117};
118
119} // namespace VoltMod
The engine's simulation clock, read straight from IVEngineServer2::GetServerGlobals().
Definition Clock.hpp:19
A player's identity behind a slot: name, money, team, scoreboard row. It survives death and respawn; ...
A live entity, valid for this frame only.
Definition Entity.hpp:40
Entity() noexcept
Definition Entity.hpp:47
CEntityInstance * _e
Definition Entity.hpp:43
A player's body: health, armor, movement, aim, weapons. The engine replaces it on every spawn; the Co...
Definition Pawn.hpp:35
void HoldCrouch(float amount=1.0f) const
Definition Pawn.cpp:199
std::string ModelName() const
Definition Pawn.cpp:266
Entity GiveKnife() const
Definition Pawn.cpp:107
bool IsAlive() const
Definition Pawn.hpp:45
void SetGodmode(bool on) const
Definition Pawn.cpp:45
Vector EyePosition() const
Definition Pawn.cpp:35
void Slay() const
Definition Pawn.cpp:235
Vector EyeForward() const
Definition Pawn.cpp:40
void ReleaseCrouch() const
Definition Pawn.cpp:220
bool Godmode() const
Definition Pawn.hpp:59
bool StripWeapons(bool removeSuit=true) const
Definition Pawn.cpp:112
void SelectWeapon(const Entity &weapon) const
Definition Pawn.cpp:143
std::vector< Entity > Weapons() const
Definition Pawn.cpp:123
bool IsOnGround() const
Definition Pawn.hpp:47
Entity GiveItem(std::string_view item) const
Definition Pawn.cpp:70
VoltMod::ObserverMode ObserverMode() const
Definition Pawn.cpp:248
void RemoveWeapon(const Entity &weapon) const
Definition Pawn.cpp:159
Entity() noexcept
Definition Entity.hpp:47
Entity ActiveWeapon() const
Definition Pawn.cpp:171
Status SetObserverMode(VoltMod::ObserverMode mode) const
Definition Pawn.cpp:254
bool Heal(int amount) const
Definition Pawn.cpp:58
void HoldFire(int tick) const
Definition Pawn.cpp:177
VoltMod::Controller Controller() const
Definition Pawn.cpp:278
void SetVelocity(Vector velocity) const
Definition Pawn.cpp:50
int Slot() const
Definition Pawn.cpp:283
std::expected< void, Error > Status
Definition Result.hpp:67
::Vector Vector
Definition Math.hpp:12
int HoldFireTick(const Clock &clock)
Definition Pawn.cpp:27
static constexpr float HalfWidth
Definition Pawn.hpp:22
static const Vector Mins
Definition Pawn.hpp:26
static const Vector Maxs
Definition Pawn.hpp:27
static constexpr float Height
Definition Pawn.hpp:23
static constexpr float StepHeight
Definition Pawn.hpp:25