VoltMod
C++23 framework for CS2 server plugins
Loading...
Searching...
No Matches
VoltMod::Entity Class Reference

A live entity, valid for this frame only. More...

#include <Entity.hpp>

Inheritance diagram for VoltMod::Entity:

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

Detailed Description

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.

Constructor & Destructor Documentation

◆ Entity() [1/3]

VoltMod::Entity::Entity ( )
inlinenoexcept

◆ Entity() [2/3]

VoltMod::Entity::Entity ( EntitySystem & entities,
CEntityInstance * raw )
inlinenoexcept

Prefer runtime.Entities lookups over building one by hand.

Definition at line 50 of file Entity.hpp.

◆ Entity() [3/3]

VoltMod::Entity::Entity ( const Entity & )
default

References Entity().

Member Function Documentation

◆ AcceptInput()

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().

◆ Angles()

QAngle VoltMod::Entity::Angles ( ) const

◆ AsPawn()

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().

◆ ClassName()

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().

◆ ClearParent()

void VoltMod::Entity::ClearParent ( ) const

Definition at line 296 of file Entity.cpp.

References AcceptInput().

◆ EmitSound() [1/2]

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.

References _e, and _sys.

Referenced by EmitSoundTo().

◆ EmitSound() [2/2]

void VoltMod::Entity::EmitSound ( std::string_view soundEvent,
IRecipientFilter & recipients,
float volume = 1.0f ) const

Definition at line 314 of file Entity.cpp.

References _e, and _sys.

◆ EmitSoundTo()

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().

◆ FindWeaponData()

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().

◆ Follow()

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().

◆ Index()

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().

◆ LoopAnimation()

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().

◆ MoveType()

Schema::MoveType_t VoltMod::Entity::MoveType ( ) const
inline

Definition at line 89 of file Entity.hpp.

Referenced by VoltMod::MovementFreeze::Hold().

◆ operator bool()

VoltMod::Entity::operator bool ( ) const
inlineexplicitnoexcept

Definition at line 55 of file Entity.hpp.

References _e.

◆ operator=()

Entity & VoltMod::Entity::operator= ( const Entity & )
delete

References Entity().

◆ Origin()

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().

◆ PlayAnimation()

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().

◆ Raw()

◆ Ref()

◆ Remove()

void VoltMod::Entity::Remove ( ) const

Remove now.

Definition at line 174 of file Entity.cpp.

References _e.

Referenced by VoltMod::EntitySystem::SpawnLine().

◆ RemoveAfter()

void VoltMod::Entity::RemoveAfter ( float seconds) const

Remove after seconds, through the engine's input queue.

Definition at line 190 of file Entity.cpp.

References _e, and _sys.

Referenced by VoltMod::Pawn::RemoveWeapon().

◆ SetBodygroup()

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().

◆ SetModel()

void VoltMod::Entity::SetModel ( std::string_view path) const

Definition at line 207 of file Entity.cpp.

References _e, _sys, and VoltMod::IsModelEntity().

◆ SetMoveType()

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().

◆ SetParent()

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().

◆ SetPlaybackRate()

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().

◆ SetRender()

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().

◆ SetScale()

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.

◆ SetSkin()

void VoltMod::Entity::SetSkin ( int skin) const

Material group by index.

Definition at line 273 of file Entity.cpp.

References AcceptInput().

◆ SetVisible()

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().

◆ Spawn()

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().

◆ StopEffect()

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().

◆ StopSound()

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.

References _e, and _sys.

◆ Teleport()

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.

References _e, and _sys.

Member Data Documentation

◆ _e

◆ _sys


The documentation for this class was generated from the following files: