7#include <entity2/entityclass.h>
8#include <entity2/entityidentity.h>
9#include <entity2/entityinstance.h>
10#include <entity2/entitysystem.h>
12#include <gameentitysystem.h>
13#include <recipientfilter.h>
14#include <schemalib/schemaclassinfo.h>
15#include <shareddefs.h>
25static_assert(std::to_underlying(
Team::None) == TEAM_UNASSIGNED);
27static_assert(std::to_underlying(
Team::T) == CS_TEAM_T);
28static_assert(std::to_underlying(
Team::CT) == CS_TEAM_CT);
43 const EmitSound_t& params);
49static void FireInput(
const Bindings& bindings, CEntityInstance* entity, std::string_view input, variant_t& value,
50 CEntityInstance* activator)
52 if (!bindings.
AcceptInput || !entity || input.empty())
56 bindings.
AcceptInput(entity, std::string(input).c_str(), activator,
nullptr, &value);
62 return entity.BodyComponent().SceneNode();
67 return (
_e &&
_e->m_pEntity) ?
_e->GetEntityIndex().Get() : -1;
77 if (!
_e || !
_e->m_pEntity)
81 const char* name =
_e->GetClassname();
82 return name ? std::string_view(name) : std::string_view{};
92 void* field = SubclassIdAddress();
99 const char* name = data.
Name();
103 .BaseName = name ? std::string_view(name) : std::string_view{}};
118void Entity::Teleport(std::optional<Vector> origin, std::optional<QAngle> angles, std::optional<Vector> velocity)
const
120 if (!
_e || !
_sys || !
_sys->Bindings().Teleport)
125 _sys->Bindings().Teleport(
_e, origin ? &*origin :
nullptr, angles ? &*angles :
nullptr,
126 velocity ? &*velocity :
nullptr);
131 SetMoveTypeRaw(type);
132 SetActualMoveType(type);
137 if (
_e &&
_sys &&
_sys->Bindings().DispatchSpawn)
150 const std::string text(value);
151 variant_t variant(text.c_str());
158 const CEntityIdentity* identity = entity ? entity->m_pEntity :
nullptr;
159 if (!identity || !identity->m_pClass || !identity->m_pClass->m_pClassInfo)
163 const CSchemaClassInfo* klass = identity->m_pClass->GetSchemaBinding();
164 for (; klass; klass = klass->m_nNumBaseClasses > 0 ? klass->m_pBaseClasses[0].m_pClass :
nullptr)
166 if (klass->m_pName && std::string_view(klass->m_pName) ==
"CBaseModelEntity")
176 CEntityIdentity* identity =
_e ?
_e->m_pEntity :
nullptr;
177 if (!identity || !identity->m_pClass)
183 const BASEPTR remove = identity->m_pClass->m_NameToThinkFunc(
"CBaseEntitySUB_Remove");
192 if (!
_e || !
_sys || !
_sys->Bindings().AddEntityIOEvent)
196 CEntitySystem* system =
_sys->Raw();
203 const variant_t value(
"");
204 _sys->Bindings().AddEntityIOEvent(system,
_e,
"Kill",
nullptr,
nullptr, &value, seconds,
nullptr,
nullptr);
211 _sys->Bindings().SetModel(
_e, std::string(path).c_str());
219 _sys->Bindings().FollowEntity(
_e, parent.
Raw(), copyBones);
268 variant_t value(rate);
280 AcceptInput(
"SetBodygroup", std::format(
"{},{}", group, value));
290 if (!attachment.empty())
303 AcceptInput(immediately ?
"DestroyImmediately" :
"Stop");
308 if (
_e &&
_sys &&
_sys->Bindings().EmitSoundParams && !soundEvent.empty())
310 _sys->Bindings().EmitSoundParams(
_e, std::string(soundEvent).c_str(), 100, volume, 0.0f);
314void Entity::EmitSound(std::string_view soundEvent, IRecipientFilter& recipients,
float volume)
const
316 if (!
_e || !
_sys || !
_sys->Bindings().EmitSoundFilter || soundEvent.empty())
322 const std::string sound(soundEvent);
324 params.m_pSoundName = sound.c_str();
325 params.m_flVolume = volume;
327 std::bit_cast<EmitSoundFilterFn>(
_sys->Bindings().EmitSoundFilter.Ptr())(recipients,
_e->GetEntityIndex(), params);
334 CReliableSingleUserRecipientFilter player(slot);
341 if (
_e &&
_sys &&
_sys->Bindings().StopSound && !soundEvent.empty())
343 _sys->Bindings().StopSound(
_e, std::string(soundEvent).c_str());
A live entity, valid for this frame only.
std::optional< WeaponData > FindWeaponData() const
void SetParent(const Entity &parent, std::string_view attachment={}) const
void SetRender(Schema::RenderMode_t mode, Color color) const
void SetPlaybackRate(float rate) const
void SetModel(std::string_view path) const
void SetMoveType(Schema::MoveType_t type) const
void SetVisible(bool visible, uint8_t alpha=0) const
void RemoveAfter(float seconds) const
std::string_view ClassName() const
void Follow(const Entity &parent, bool copyBones) const
void AcceptInput(std::string_view input, std::string_view value={}, const Entity &activator={}) const
void EmitSound(std::string_view soundEvent, float volume=1.0f) const
void LoopAnimation(std::string_view animation) const
void EmitSoundTo(std::string_view soundEvent, int slot, float volume=1.0f) const
void Spawn(KeyValues &values) const
void PlayAnimation(std::string_view animation, std::string_view idle={}) const
void SetBodygroup(std::string_view group, int value) const
void Teleport(std::optional< Vector > origin, std::optional< QAngle > angles, std::optional< Vector > velocity) const
void StopEffect(bool immediately) const
void SetScale(float scale) const
void StopSound(std::string_view soundEvent) const
CEntityInstance * Raw() const noexcept
void SetSkin(int skin) const
Spawn keyvalues such as "origin", "spawnflags" or "effect_name".
CEntityKeyValues * Detach()
T Read(const void *base) const
void SetRenderMode(RenderMode_t value) const
void SetRenderColor(Color value) const
CSWeaponType WeaponType() const
gear_slot_t GearSlot() const
const char * Name() const
QAngle AbsRotation() const
static constexpr float MinScale
static constexpr float MaxScale
static bool IsModelEntity(CEntityInstance *entity)
constexpr bool IsValidSlot(int slot)
static void FireInput(const Bindings &bindings, CEntityInstance *entity, std::string_view input, variant_t &value, CEntityInstance *activator)
static Schema::CGameSceneNode SceneNode(const Entity &entity)
StartSoundEventInfo(*)(IRecipientFilter &filter, CEntityIndex sourceIndex, const EmitSound_t ¶ms) EmitSoundFilterFn
Fn< void(CEntityInstance *, const char *, CEntityInstance *, CEntityInstance *, void *)> AcceptInput
An RGBA color in the engine's byte order, as m_clrRender and glow colors hold it.
static constexpr uint32_t Unset