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
6#include <cstdint>
7#include <string>
8#include <string_view>
9#include <vector>
10
11namespace VoltMod
12{
13
14/**
15 * @brief A player's body: health, armor, movement, aim, weapons. The engine replaces it on every
16 * spawn; the @ref Controller is the identity that stays.
17 */
18class Pawn : public Entity
19{
20public:
21 using Entity::Entity;
22
23 /** @name CCSPlayerPawn, CBasePlayerPawn and CBaseModelEntity fields
24 * `VelocityModifier` decays back toward 1 on its own, and `ViewOffset` is the eye height. */
25 /** @{ */
26#include <VoltMod/Schema/Generated/Wrappers/Pawn.inc>
27 /** @} */
28
29 bool IsAlive() const { return _e != nullptr && LifeState() == LIFE_ALIVE; }
30
31 bool IsOnGround() const { return (Flags() & FL_ONGROUND) != 0; }
32
33 /** Where shots start: the origin plus the view offset. */
34 Vector EyePosition() const;
35
36 /** Does nothing when the CommitSuicide index did not bind. */
37 void Slay() const;
38
39 /** The FL_GODMODE flag, which is what makes a CS2 pawn take no damage. */
40 bool Godmode() const { return (Flags() & FL_GODMODE) != 0; }
41 void SetGodmode(bool on) const;
42
43 /** Set the pawn's velocity and lift it off the ground this tick, so the engine keeps the velocity.
44 * SetAbsVelocity alone leaves a grounded pawn grounded. */
45 void SetVelocity(Vector velocity) const;
46
47 /** Add @p amount health, up to MaxHealth. False when nothing changed, such as a dead pawn. */
48 bool Heal(int amount) const;
49
50 /** Give an item by class name, such as "weapon_ak47". A weapon the pawn's team cannot buy is
51 * given through a same-frame team swap. The given item; falsy when the engine refused it. */
52 Entity GiveItem(std::string_view item) const;
53
54 /** Remove every weapon, and with @p removeSuit the armor and defuse kit too. */
55 bool StripWeapons(bool removeSuit = true) const;
56
57 /** The carried weapons, knife and grenades included. */
58 std::vector<Entity> Weapons() const;
59
60 /** Draw @p weapon. Does nothing for a weapon the pawn does not carry, or when the SelectItem index
61 * did not bind. */
62 void SelectWeapon(const Entity& weapon) const;
63
64 /** Remove @p weapon through the engine's input queue, so it is safe inside a death event. A weapon in a
65 * live pawn's hand is first swapped for the one held before it. */
66 void RemoveWeapon(const Entity& weapon) const;
67
68 /** Keep the weapon in hand from either attack before engine tick @p tick. A weapon switched to
69 * later is not covered, so call it every frame to hold fire for a while. */
70 void HoldFire(int tick) const;
71
74
75 /** Current model path; empty when unavailable. */
76 std::string ModelName() const;
77
78 /** The owning player's controller. */
80
81 /** The owning player's slot, or -1. Constant time. */
82 int Slot() const;
83};
84
85} // namespace VoltMod
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:29
Entity() noexcept
Definition Entity.hpp:36
CEntityInstance * _e
Definition Entity.hpp:32
A player's body: health, armor, movement, aim, weapons. The engine replaces it on every spawn; the Co...
Definition Pawn.hpp:19
std::string ModelName() const
Definition Pawn.cpp:201
bool IsAlive() const
Definition Pawn.hpp:29
void SetGodmode(bool on) const
Definition Pawn.cpp:29
Vector EyePosition() const
Definition Pawn.cpp:24
void Slay() const
Definition Pawn.cpp:170
bool Godmode() const
Definition Pawn.hpp:40
bool StripWeapons(bool removeSuit=true) const
Definition Pawn.cpp:91
void SelectWeapon(const Entity &weapon) const
Definition Pawn.cpp:122
std::vector< Entity > Weapons() const
Definition Pawn.cpp:102
bool IsOnGround() const
Definition Pawn.hpp:31
Entity GiveItem(std::string_view item) const
Definition Pawn.cpp:54
VoltMod::ObserverMode ObserverMode() const
Definition Pawn.cpp:183
void RemoveWeapon(const Entity &weapon) const
Definition Pawn.cpp:139
Status SetObserverMode(VoltMod::ObserverMode mode) const
Definition Pawn.cpp:189
bool Heal(int amount) const
Definition Pawn.cpp:42
void HoldFire(int tick) const
Definition Pawn.cpp:151
VoltMod::Controller Controller() const
Definition Pawn.cpp:213
void SetVelocity(Vector velocity) const
Definition Pawn.cpp:34
int Slot() const
Definition Pawn.cpp:218
static std::string ReadFile(const std::filesystem::path &path)
Definition Loader.cpp:56
std::expected< void, Error > Status
Definition Result.hpp:67
::Vector Vector
Definition Math.hpp:11