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
 
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 EmitSound (std::string_view soundEvent, float volume=1.0f) const
 
void EmitSound (std::string_view soundEvent, IRecipientFilter &recipients, 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 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
 

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 28 of file Entity.hpp.

Constructor & Destructor Documentation

◆ Entity() [1/3]

VoltMod::Entity::Entity ( )
inlinenoexcept

Definition at line 36 of file Entity.hpp.

◆ Entity() [2/3]

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

Prefer runtime.Entities lookups over building one by hand.

Definition at line 39 of file Entity.hpp.

◆ Entity() [3/3]

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

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 134 of file Entity.cpp.

References _e, _sys, VoltMod::EntitySystem::Bindings(), VoltMod::FireInput(), and VoltMod::ReadFile().

Referenced by PlayAnimation().

◆ Angles()

QAngle VoltMod::Entity::Angles ( ) const

Definition at line 103 of file Entity.cpp.

References VoltMod::ReadFile(), and VoltMod::SceneNode().

◆ 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 178 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 87 of file Entity.cpp.

References _e.

Referenced by AsPawn().

◆ 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 242 of file Entity.cpp.

References _e, _sys, VoltMod::EntitySystem::Bindings(), VoltMod::Bindings::EmitSoundParams, and VoltMod::ReadFile().

◆ EmitSound() [2/2]

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

◆ Index()

int VoltMod::Entity::Index ( ) const

Network index; -1 when falsy.

Definition at line 77 of file Entity.cpp.

References _e.

Referenced by VoltMod::Visibility::OnCheckTransmit(), and VoltMod::Pawn::Slot().

◆ MoveType()

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

Definition at line 74 of file Entity.hpp.

◆ operator bool()

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

Definition at line 44 of file Entity.hpp.

References _e.

◆ operator=()

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

◆ Origin()

Vector VoltMod::Entity::Origin ( ) const

World position and rotation, from the scene node.

Definition at line 97 of file Entity.cpp.

References VoltMod::ReadFile(), and VoltMod::SceneNode().

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

◆ 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 233 of file Entity.cpp.

References AcceptInput(), and VoltMod::ReadFile().

◆ Raw()

CEntityInstance * VoltMod::Entity::Raw ( ) const
inlinenoexcept

The engine entity, for calls the framework does not wrap.

Definition at line 47 of file Entity.hpp.

References _e.

Referenced by VoltMod::Damage::Apply(), VoltMod::CollectHiddenPlayer(), and VoltMod::Controller::InputPawn().

◆ Ref()

EntityRef VoltMod::Entity::Ref ( ) const

The handle to store; unset when falsy.

Definition at line 82 of file Entity.cpp.

References _e, VoltMod::ReadFile(), and VoltMod::EntityRef::Unset.

◆ Remove()

void VoltMod::Entity::Remove ( ) const

Remove now.

Definition at line 165 of file Entity.cpp.

References _e, and VoltMod::ReadFile().

Referenced by VoltMod::ScreenEntity::Remove().

◆ RemoveAfter()

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

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

Definition at line 181 of file Entity.cpp.

References _e, _sys, VoltMod::Bindings::AddEntityIOEvent, VoltMod::EntitySystem::Bindings(), VoltMod::EntitySystem::Raw(), and VoltMod::ReadFile().

◆ SetModel()

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

◆ 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 120 of file Entity.cpp.

◆ 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 216 of file Entity.cpp.

References _e, VoltMod::IsModelEntity(), VoltMod::ReadFile(), and VoltMod::Schema::CBaseModelEntity::SetRenderMode().

Referenced by SetVisible().

◆ 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 206 of file Entity.cpp.

References _e, _sys, VoltMod::EntitySystem::Bindings(), VoltMod::FireInput(), VoltMod::MaxScale, VoltMod::MinScale, and VoltMod::ReadFile().

◆ 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 227 of file Entity.cpp.

References VoltMod::Color::A, VoltMod::Schema::kRenderNormal, VoltMod::Schema::kRenderTransAlpha, VoltMod::ReadFile(), and SetRender().

◆ Spawn()

void VoltMod::Entity::Spawn ( KeyValues &  values) const

Spawn an entity from EntitySystem::Create; the engine takes the keyvalues.

Definition at line 126 of file Entity.cpp.

References _e, _sys, VoltMod::EntitySystem::Bindings(), VoltMod::Bindings::DispatchSpawn, and VoltMod::ReadFile().

◆ StopSound()

void VoltMod::Entity::StopSound ( std::string_view  soundEvent) const

Stop every soundEvent this entity is playing, for everyone.

Definition at line 266 of file Entity.cpp.

References _e, _sys, VoltMod::EntitySystem::Bindings(), VoltMod::ReadFile(), and VoltMod::Bindings::StopSound.

◆ 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 109 of file Entity.cpp.

References _e, _sys, VoltMod::EntitySystem::Bindings(), VoltMod::ReadFile(), and VoltMod::Bindings::Teleport.

Member Data Documentation

◆ _e

◆ _sys


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