|
VoltMod
C++23 framework for CS2 server plugins
|
A live entity, valid for this frame only. More...
#include <Entity.hpp>
Public Member Functions | |
| Entity () noexcept | |
| Entity (EntitySystem &entities, CEntityInstance *raw) noexcept | |
| Entity (const Entity &)=default | |
| Entity & | operator= (const Entity &)=delete |
| operator bool () const noexcept | |
| CEntityInstance * | Raw () const noexcept |
| int | Index () const |
| EntityRef | Ref () const |
| std::string_view | ClassName () const |
| Pawn | AsPawn () const |
| std::optional< WeaponData > | FindWeaponData () const |
| Vector | Origin () const |
| QAngle | Angles () const |
| void | Teleport (std::optional< Vector > origin, std::optional< QAngle > angles, std::optional< Vector > velocity) const |
| Schema::MoveType_t | MoveType () const |
| void | SetMoveType (Schema::MoveType_t type) const |
| void | Spawn (KeyValues &values) const |
| void | AcceptInput (std::string_view input, std::string_view value={}, const Entity &activator={}) const |
| void | Remove () const |
| void | RemoveAfter (float seconds) const |
| void | SetParent (const Entity &parent, std::string_view attachment={}) const |
| void | ClearParent () const |
| void | StopEffect (bool immediately) const |
| void | EmitSound (std::string_view soundEvent, float volume=1.0f) const |
| void | EmitSound (std::string_view soundEvent, IRecipientFilter &recipients, float volume=1.0f) const |
| void | EmitSoundTo (std::string_view soundEvent, int slot, float volume=1.0f) const |
| void | StopSound (std::string_view soundEvent) const |
Model entities only | |
Props, pawns, weapons and beams. On any other entity these do nothing. | |
| void | SetModel (std::string_view path) const |
| void | Follow (const Entity &parent, bool copyBones) const |
| void | SetScale (float scale) const |
| void | SetRender (Schema::RenderMode_t mode, Color color) const |
| void | SetVisible (bool visible, uint8_t alpha=0) const |
| void | PlayAnimation (std::string_view animation, std::string_view idle={}) const |
| void | LoopAnimation (std::string_view animation) const |
| void | SetPlaybackRate (float rate) const |
| void | SetSkin (int skin) const |
| void | SetBodygroup (std::string_view group, int value) const |
Protected Attributes | |
| EntitySystem * | _sys = nullptr |
| CEntityInstance * | _e = nullptr |
A live entity, valid for this frame only.
The engine can free it between frames: store an EntityRef and resolve it again where you use it. if (entity) is the validity check. A falsy entity reads zero and ignores writes and verbs. Copies are cheap; assignment is deleted so a rebind never reads like a field write.
Fields are generated pairs: Health() reads, SetHealth(100) writes and replicates.
Definition at line 39 of file Entity.hpp.
|
inlinenoexcept |
Definition at line 47 of file Entity.hpp.
Referenced by AcceptInput(), VoltMod::Controller::Controller(), Entity(), Follow(), operator=(), and SetParent().
|
inlinenoexcept |
Prefer runtime.Entities lookups over building one by hand.
Definition at line 50 of file Entity.hpp.
|
default |
References Entity().
| void VoltMod::Entity::AcceptInput | ( | std::string_view | input, |
| std::string_view | value = {}, | ||
| const Entity & | activator = {} ) const |
Fire an entity input, such as "Explode" or ("FollowEntity", "!activator", pawn).
Definition at line 143 of file Entity.cpp.
References _e, _sys, Entity(), VoltMod::FireInput(), and Raw().
Referenced by ClearParent(), VoltMod::BoneFollow::Detach(), LoopAnimation(), PlayAnimation(), SetBodygroup(), SetParent(), SetSkin(), and StopEffect().
| QAngle VoltMod::Entity::Angles | ( | ) | const |
Definition at line 112 of file Entity.cpp.
References VoltMod::Schema::CGameSceneNode::AbsRotation(), and VoltMod::SceneNode().
| Pawn VoltMod::Entity::AsPawn | ( | ) | const |
This entity as a player pawn; falsy for anything else, such as a prop or a grenade.
Definition at line 243 of file Pawn.cpp.
References _e, _sys, and ClassName().
Referenced by VoltMod::EntitySystem::Pawn().
| std::string_view VoltMod::Entity::ClassName | ( | ) | const |
Such as "player". Points into engine memory: copy it to keep it.
Definition at line 75 of file Entity.cpp.
References _e.
Referenced by AsPawn(), and FindWeaponData().
| void VoltMod::Entity::ClearParent | ( | ) | const |
Definition at line 296 of file Entity.cpp.
References AcceptInput().
| void VoltMod::Entity::EmitSound | ( | std::string_view | soundEvent, |
| float | volume = 1.0f ) const |
Play a .vsndevts event from this entity, to everyone or to recipients.
Definition at line 306 of file Entity.cpp.
Referenced by EmitSoundTo().
| void VoltMod::Entity::EmitSound | ( | std::string_view | soundEvent, |
| IRecipientFilter & | recipients, | ||
| float | volume = 1.0f ) const |
Definition at line 314 of file Entity.cpp.
| void VoltMod::Entity::EmitSoundTo | ( | std::string_view | soundEvent, |
| int | slot, | ||
| float | volume = 1.0f ) const |
Play a .vsndevts event from this entity to the player in slot alone.
Definition at line 330 of file Entity.cpp.
References EmitSound(), and VoltMod::IsValidSlot().
| std::optional< WeaponData > VoltMod::Entity::FindWeaponData | ( | ) | const |
This weapon's VData, or empty for anything that is not a weapon. Read it where you use it: a subclass change swaps it.
Definition at line 85 of file Entity.cpp.
References _sys, ClassName(), VoltMod::Schema::CCSWeaponBaseVData::GearSlot(), VoltMod::Schema::CCSWeaponBaseVData::IsFullAuto(), VoltMod::Schema::CCSWeaponBaseVData::Name(), VoltMod::Offset< T >::Read(), and VoltMod::Schema::CCSWeaponBaseVData::WeaponType().
| void VoltMod::Entity::Follow | ( | const Entity & | parent, |
| bool | copyBones ) const |
Parent this entity to parent at the parent's origin. With copyBones its bones take the parent's pose by name, and traces such as bullets stop hitting it, as with worn gear, even after ClearParent. BoneFollow keeps a pawn shootable.
Definition at line 215 of file Entity.cpp.
References _e, _sys, Entity(), VoltMod::IsModelEntity(), and Raw().
Referenced by VoltMod::BoneFollow::Attach(), and VoltMod::EntitySystem::SpawnOutline().
| int VoltMod::Entity::Index | ( | ) | const |
Network index; -1 when falsy.
Definition at line 65 of file Entity.cpp.
References _e.
Referenced by VoltMod::AddHandleVector(), VoltMod::CollectHiddenPlayer(), VoltMod::Visibility::OnCheckTransmit(), and VoltMod::Pawn::Slot().
| void VoltMod::Entity::LoopAnimation | ( | std::string_view | animation | ) | const |
Loop animation from its first frame.
Definition at line 259 of file Entity.cpp.
References AcceptInput().
|
inline |
Definition at line 89 of file Entity.hpp.
Referenced by VoltMod::MovementFreeze::Hold().
|
inlineexplicitnoexcept |
Definition at line 55 of file Entity.hpp.
References _e.
| Vector VoltMod::Entity::Origin | ( | ) | const |
World position and rotation, from the scene node.
Definition at line 106 of file Entity.cpp.
References VoltMod::Schema::CGameSceneNode::AbsOrigin(), and VoltMod::SceneNode().
Referenced by VoltMod::Damage::Apply(), VoltMod::Pawn::EyePosition(), and VoltMod::EntitySystem::SpawnOutline().
| void VoltMod::Entity::PlayAnimation | ( | std::string_view | animation, |
| std::string_view | idle = {} ) const |
Play animation once from its first frame, then loop idle.
Definition at line 250 of file Entity.cpp.
References AcceptInput().
|
inlinenoexcept |
The engine entity, for calls the framework does not wrap.
Definition at line 58 of file Entity.hpp.
References _e.
Referenced by AcceptInput(), VoltMod::Damage::Apply(), VoltMod::CollectHiddenPlayer(), VoltMod::Controller::Controller(), Follow(), VoltMod::GameRules(), VoltMod::FireHold::Hold(), VoltMod::Pawn::HoldFire(), VoltMod::MakeFilter(), VoltMod::ObserverTarget(), VoltMod::FireHold::Release(), VoltMod::Pawn::SelectWeapon(), VoltMod::EntitySystem::SpawnBeam(), and VoltMod::EntitySystem::SpawnLine().
| EntityRef VoltMod::Entity::Ref | ( | ) | const |
The handle to store; unset when falsy.
Definition at line 70 of file Entity.cpp.
References _e, and VoltMod::EntityRef::Unset.
Referenced by VoltMod::BoneFollow::Attach(), VoltMod::BoneFollow::Detach(), VoltMod::FireHold::Hold(), VoltMod::MovementFreeze::Hold(), VoltMod::FireHold::Release(), VoltMod::MovementFreeze::Release(), VoltMod::Pawn::RemoveWeapon(), VoltMod::Pawn::SelectWeapon(), VoltMod::EntitySystem::SpawnLine(), and VoltMod::MovementFreeze::Sync().
| void VoltMod::Entity::Remove | ( | ) | const |
Remove now.
Definition at line 174 of file Entity.cpp.
References _e.
Referenced by VoltMod::EntitySystem::SpawnLine().
| void VoltMod::Entity::RemoveAfter | ( | float | seconds | ) | const |
Remove after seconds, through the engine's input queue.
Definition at line 190 of file Entity.cpp.
Referenced by VoltMod::Pawn::RemoveWeapon().
| void VoltMod::Entity::SetBodygroup | ( | std::string_view | group, |
| int | value ) const |
Pick choice value of the model's bodygroup group, such as ("warhead", 1).
Definition at line 278 of file Entity.cpp.
References AcceptInput().
| void VoltMod::Entity::SetModel | ( | std::string_view | path | ) | const |
Definition at line 207 of file Entity.cpp.
References _e, _sys, and VoltMod::IsModelEntity().
| void VoltMod::Entity::SetMoveType | ( | Schema::MoveType_t | type | ) | const |
Writes both move-type fields; the engine reverts a lone one next tick.
Definition at line 129 of file Entity.cpp.
Referenced by VoltMod::MovementFreeze::Hold(), and VoltMod::MovementFreeze::Release().
| void VoltMod::Entity::SetParent | ( | const Entity & | parent, |
| std::string_view | attachment = {} ) const |
Move with parent, keeping this entity where it is; with attachment, snap to that attachment on the parent's model, such as a hand. A child is removed with its parent: call ClearParent first to keep it.
Definition at line 283 of file Entity.cpp.
References AcceptInput(), and Entity().
Referenced by VoltMod::EntitySystem::SpawnLine().
| void VoltMod::Entity::SetPlaybackRate | ( | float | rate | ) | const |
Speed the current animation up or down; 1 is its own pace. A new animation resets it.
Definition at line 264 of file Entity.cpp.
References _e, _sys, and VoltMod::FireInput().
| void VoltMod::Entity::SetRender | ( | Schema::RenderMode_t | mode, |
| Color | color ) const |
Write m_nRenderMode and m_clrRender together. kRenderTransAlpha makes the alpha show.
Definition at line 233 of file Entity.cpp.
References _e, VoltMod::IsModelEntity(), VoltMod::Schema::CBaseModelEntity::SetRenderColor(), and VoltMod::Schema::CBaseModelEntity::SetRenderMode().
Referenced by SetVisible(), and VoltMod::EntitySystem::SpawnBeam().
| void VoltMod::Entity::SetScale | ( | float | scale | ) | const |
Render and collision scale, clamped to 0.05-3: larger values have crashed the server.
Definition at line 223 of file Entity.cpp.
References _e, _sys, VoltMod::FireInput(), VoltMod::MaxScale, and VoltMod::MinScale.
| void VoltMod::Entity::SetSkin | ( | int | skin | ) | const |
| void VoltMod::Entity::SetVisible | ( | bool | visible, |
| uint8_t | alpha = 0 ) const |
Fade to alpha, or restore. A pawn's held weapons and wearables stay visible; hide a player completely with Visibility.
Definition at line 244 of file Entity.cpp.
References VoltMod::Schema::kRenderNormal, VoltMod::Schema::kRenderTransAlpha, and SetRender().
| void VoltMod::Entity::Spawn | ( | KeyValues & | values | ) | const |
Spawn an entity from EntitySystem::Create; the engine takes the keyvalues.
Definition at line 135 of file Entity.cpp.
References _e, _sys, and VoltMod::KeyValues::Detach().
Referenced by VoltMod::EntitySystem::Spawn(), VoltMod::EntitySystem::SpawnBeam(), and VoltMod::EntitySystem::SpawnLine().
| void VoltMod::Entity::StopEffect | ( | bool | immediately | ) | const |
Stop a particle effect: new particles stop, and those drawn fade out, or vanish at once when immediately. The entity stays until removed; removing a looping effect alone can leave it drawn.
Definition at line 301 of file Entity.cpp.
References AcceptInput().
| void VoltMod::Entity::StopSound | ( | std::string_view | soundEvent | ) | const |
Stop every soundEvent this entity is playing, for everyone.
Definition at line 339 of file Entity.cpp.
| void VoltMod::Entity::Teleport | ( | std::optional< Vector > | origin, |
| std::optional< QAngle > | angles, | ||
| std::optional< Vector > | velocity ) const |
Move the entity; std::nullopt leaves that part unchanged. Does nothing when the Teleport slot did not bind.
Definition at line 118 of file Entity.cpp.
|
protected |
Definition at line 43 of file Entity.hpp.
Referenced by AcceptInput(), AsPawn(), VoltMod::Controller::ChangeTeam(), ClassName(), EmitSound(), EmitSound(), VoltMod::Controller::ExecuteCommand(), Follow(), Index(), VoltMod::Pawn::IsAlive(), VoltMod::Controller::Kick(), operator bool(), Raw(), Ref(), Remove(), RemoveAfter(), VoltMod::Controller::Respawn(), SetModel(), SetPlaybackRate(), SetRender(), SetScale(), VoltMod::Pawn::Slay(), Spawn(), StopSound(), and Teleport().
|
protected |
Definition at line 42 of file Entity.hpp.
Referenced by AcceptInput(), VoltMod::Pawn::ActiveWeapon(), AsPawn(), VoltMod::Controller::ChangeTeam(), VoltMod::Pawn::Controller(), EmitSound(), EmitSound(), VoltMod::Controller::ExecuteCommand(), FindWeaponData(), Follow(), VoltMod::Pawn::GiveItem(), VoltMod::Controller::InputPawn(), VoltMod::Controller::Kick(), VoltMod::Controller::Pawn(), RemoveAfter(), VoltMod::Pawn::RemoveWeapon(), VoltMod::Controller::Respawn(), VoltMod::Pawn::SelectWeapon(), SetModel(), SetPlaybackRate(), SetScale(), VoltMod::Pawn::Slay(), VoltMod::Pawn::Slot(), Spawn(), StopSound(), VoltMod::Pawn::StripWeapons(), Teleport(), and VoltMod::Pawn::Weapons().