VoltMod
C++23 framework for CS2 server plugins
Loading...
Searching...
No Matches
EntitySystem.hpp
Go to the documentation of this file.
1#pragma once
2
13#include <optional>
14#include <string_view>
15#include <vector>
16
17namespace VoltMod
18{
19
20/** An outline drawn around a prop, through walls. */
22{
24 /** How far away it shows, in units. */
25 int Range = 5000;
26 /** The team that sees it; None shows it to everyone. */
28};
29
30/** What @ref EntitySystem::SpawnProp places. */
32{
33 std::string_view Model;
34 Vector Origin{0.0f, 0.0f, 0.0f};
35 QAngle Angles{0.0f, 0.0f, 0.0f};
36 /** False blocks nothing, bullets and traces included. */
37 bool Solid = true;
38 /** Material group; empty keeps the model's default. */
39 std::string_view Skin;
40 float Scale = 1.0f;
41 bool CastsShadow = true;
42 /** Set before it spawns, so a trace with @ref TraceOptions::IgnoreOwnedBy passes through it. */
44 std::optional<PropGlow> Glow;
45};
46
47/**
48 * @brief `runtime.Entities`: finds and creates entities. Everything it returns is valid for this
49 * frame only; see @ref Entity.
50 */
52{
53public:
54 /** Reads the entity system, which is null before the first map. @p interfaces and @p bindings
55 * must outlive this service. */
56 EntitySystem(VoltMod::Interfaces& interfaces, const VoltMod::Bindings& bindings);
57 EntitySystem(const EntitySystem&) = delete;
59
60 /** The controller in @p slot; falsy when the slot is empty. */
62
63 /** The living body of @p slot's player; falsy when there is none. */
64 VoltMod::Pawn Pawn(int slot);
65
66 /** The player pawn @p ref points at; falsy when it is gone or not a player pawn. */
68
69 /** What @p ref points at; falsy when it is unset, or its entity is gone or replaced. */
70 Entity Get(EntityRef ref);
71
72 /** The first entity of @p className, such as "cs_gamerules"; `*` wildcards match. */
73 Entity Find(std::string_view className);
74
75 /** Every entity of @p className, taken now, so removing them while looping is safe. */
76 std::vector<Entity> FindAll(std::string_view className);
77
78 /** An error when entity lookups can never work, or entities cannot be created or spawned. A
79 * missing system before the first map is fine: @ref OnServerStartup picks it up. */
80 Status Available() const;
81
82 /** A new entity that has not spawned yet: set its fields, then call @ref Entity::Spawn. */
83 Entity Create(std::string_view className);
84
85 /** Create and spawn; falsy on failure. The engine takes the keyvalues. */
86 Entity Spawn(std::string_view className, KeyValues& values);
87
88 /** A `prop_dynamic`; falsy when it did not spawn. */
89 Entity SpawnProp(const PropSpec& prop);
90
91 /** @p glow drawn around @p target without changing its look: an invisible copy of @p model, its
92 * model, that follows @p target in its pose. Remove it to take the outline off. */
93 Entity SpawnOutline(const Entity& target, std::string_view model, const PropGlow& glow);
94
95 /** A running particle effect such as "particles/explosion.vpcf"; empty for an empty name. Remove it to stop it. */
96 Entity SpawnParticle(std::string_view effect, const Vector& origin, const QAngle& angles = {0.0f, 0.0f, 0.0f});
97
98 /** A running particle effect from @p from whose control point 1 follows @p end, such as a tracer
99 * to its target. Linked by handle, so neither entity needs a name. */
100 Entity SpawnLine(std::string_view effect, const Vector& from, EntityRef end);
101
102 /** As above, to the fixed point @p to. The far end is an entity parented to the effect, so removing
103 * the effect removes both. */
104 Entity SpawnLine(std::string_view effect, const Vector& from, const Vector& to);
105
106 /** A straight line of @p width from @p from to @p to. */
107 Entity SpawnBeam(const Vector& from, const Vector& to, float width, Color color);
108
109 /** @name Framework plumbing */
110 /** @{ */
111 /** Re-read the system for the new map. */
112 void OnServerStartup();
113
114 /** The engine's entity system; null before the first map. */
115 CGameEntitySystem* Raw();
116
117 /** What the wrappers' verbs call the engine through. */
118 const VoltMod::Bindings& Bindings() const noexcept { return _bindings; }
119 const VoltMod::Interfaces& Interfaces() const noexcept { return _interfaces; }
120 /** @} */
121
122private:
123 CEntityInstance* RawController(int slot);
124
125 /** With @p outlineOnly the glow is drawn without the model. */
126 Entity SpawnProp(const PropSpec& prop, bool outlineOnly);
127
128 /** Null when the SDK's field does not hold a CGameEntitySystem. */
129 CGameEntitySystem* ReadEntitySystemPointer();
130
131 VoltMod::Interfaces& _interfaces;
132 const VoltMod::Bindings& _bindings;
133 /** Empty until the first pointer is checked. */
134 std::optional<bool> _isRealSystem;
135};
136
137} // namespace VoltMod
A player's identity behind a slot: name, money, team, scoreboard row. It survives death and respawn; ...
Entity Create(std::string_view className)
std::vector< Entity > FindAll(std::string_view className)
const VoltMod::Bindings & Bindings() const noexcept
Entity Find(std::string_view className)
Entity SpawnProp(const PropSpec &prop)
Entity SpawnBeam(const Vector &from, const Vector &to, float width, Color color)
VoltMod::Controller Controller(int slot)
Entity Spawn(std::string_view className, KeyValues &values)
VoltMod::Pawn Pawn(int slot)
EntitySystem(const EntitySystem &)=delete
Entity SpawnLine(std::string_view effect, const Vector &from, EntityRef end)
CGameEntitySystem * Raw()
Entity Get(EntityRef ref)
EntitySystem & operator=(const EntitySystem &)=delete
EntitySystem(VoltMod::Interfaces &interfaces, const VoltMod::Bindings &bindings)
const VoltMod::Interfaces & Interfaces() const noexcept
Entity SpawnParticle(std::string_view effect, const Vector &origin, const QAngle &angles={0.0f, 0.0f, 0.0f})
Entity SpawnOutline(const Entity &target, std::string_view model, const PropGlow &glow)
A live entity, valid for this frame only.
Definition Entity.hpp:40
Spawn keyvalues such as "origin", "spawnflags" or "effect_name".
Definition KeyValues.hpp:16
A player's body: health, armor, movement, aim, weapons. The engine replaces it on every spawn; the Co...
Definition Pawn.hpp:35
std::expected< void, Error > Status
Definition Result.hpp:67
::QAngle QAngle
Definition Math.hpp:15
::Vector Vector
Definition Math.hpp:12
An RGBA color in the engine's byte order, as m_clrRender and glow colors hold it.
Definition Color.hpp:15
Centralized holder for all SDK interface pointers.
VoltMod::Color Color
VoltMod::Team Team
std::optional< PropGlow > Glow
std::string_view Skin
std::string_view Model