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
12#include <optional>
13#include <string_view>
14#include <vector>
15
16namespace VoltMod
17{
18
19/** What @ref EntitySystem::SpawnProp places. */
21{
22 std::string_view Model;
23 Vector Origin{0.0f, 0.0f, 0.0f};
24 QAngle Angles{0.0f, 0.0f, 0.0f};
25 /** False blocks nothing, bullets and traces included. */
26 bool Solid = true;
27 /** Material group; empty keeps the model's default. */
28 std::string_view Skin;
29 float Scale = 1.0f;
30 bool CastsShadow = true;
31 /** Set before it spawns, so a trace with @ref TraceOptions::IgnoreOwnedBy passes through it. */
33};
34
35/**
36 * @brief `runtime.Entities`: finds and creates entities. Everything it returns is valid for this
37 * frame only; see @ref Entity.
38 */
40{
41public:
42 /** Reads the entity system, which is null before the first map. @p interfaces and @p bindings
43 * must outlive this service. */
46 EntitySystem(const EntitySystem&) = delete;
48
49 /** The controller in @p slot; falsy when the slot is empty. */
51
52 /** The living body of @p slot's player; falsy when there is none. */
54
55 /** The player pawn @p ref points at; falsy when it is gone or not a player pawn. */
57
58 /** What @p ref points at; falsy when it is unset, or its entity is gone or replaced. */
60
61 /** The first entity of @p className, such as "cs_gamerules"; `*` wildcards match. */
62 Entity Find(std::string_view className);
63
64 /** Every entity of @p className, taken now, so removing them while looping is safe. */
65 std::vector<Entity> FindAll(std::string_view className);
66
67 /** An error when entity lookups can never work, or entities cannot be created or spawned. A
68 * missing system before the first map is fine: @ref OnServerStartup picks it up. */
69 Status Available() const;
70
71 /** A new entity that has not spawned yet: set its fields, then call @ref Entity::Spawn. */
72 Entity Create(std::string_view className);
73
74 /** Create and spawn; falsy on failure. The engine takes the keyvalues. */
75 Entity Spawn(std::string_view className, KeyValues& values);
76
77 /** A `prop_dynamic`; falsy when it did not spawn. */
79
80 /** A running particle effect such as "particles/explosion.vpcf"; empty for an empty name. Remove it to stop it. */
81 Entity SpawnParticle(std::string_view effect, const Vector& origin, const QAngle& angles = {0.0f, 0.0f, 0.0f});
82
83 /** A running particle effect from @p from whose control point 1 follows @p end, such as a tracer
84 * to its target. Linked by handle, so neither entity needs a name. */
85 Entity SpawnLine(std::string_view effect, const Vector& from, EntityRef end);
86
87 /** A straight line of @p width from @p from to @p to. */
88 Entity SpawnBeam(const Vector& from, const Vector& to, float width, Color color);
89
90 /** @name Framework plumbing */
91 /** @{ */
92 /** Re-read the system for the new map. */
93 void OnServerStartup();
94
95 /** The engine's entity system; null before the first map. */
97
98 /** What the wrappers' verbs call the engine through. */
99 const VoltMod::Bindings& Bindings() const noexcept { return _bindings; }
100 const VoltMod::Interfaces& Interfaces() const noexcept { return _interfaces; }
101 /** @} */
102
103private:
104 CEntityInstance* RawController(int slot);
105
106 /** Null when the gamedata offset does not reach a CGameEntitySystem. */
107 CGameEntitySystem* ReadEntitySystemPointer();
108
109 /** Also publishes it for the SDK's ::GameEntitySystem(). */
110 void SetEntitySystem(CGameEntitySystem* system);
111
112 VoltMod::Interfaces& _interfaces;
113 const VoltMod::Bindings& _bindings;
114 /** Empty until the first pointer is checked. */
115 std::optional<bool> _isRealSystem;
116};
117
118} // namespace VoltMod
A player's identity behind a slot: name, money, team, scoreboard row. It survives death and respawn; ...
runtime.Entities: finds and creates entities. Everything it returns is valid for this frame only; see...
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)
Entity Spawn(std::string_view className, KeyValues &values)
EntitySystem(const EntitySystem &)=delete
Entity SpawnLine(std::string_view effect, const Vector &from, EntityRef end)
CGameEntitySystem * Raw()
EntitySystem & operator=(const EntitySystem &)=delete
const VoltMod::Interfaces & Interfaces() const noexcept
Entity SpawnParticle(std::string_view effect, const Vector &origin, const QAngle &angles={0.0f, 0.0f, 0.0f})
A live entity, valid for this frame only.
Definition Entity.hpp:29
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:19
static std::string ReadFile(const std::filesystem::path &path)
Definition Loader.cpp:56
::QAngle QAngle
Definition Math.hpp:14
std::expected< void, Error > Status
Definition Result.hpp:67
::Vector Vector
Definition Math.hpp:11
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 HL2SDK interface pointers.
std::string_view Skin
std::string_view Model