CBaseEntity
Base managed wrapper for all Source 2 entities. Provides common operations: health, team, lifecycle, modifiers, schema access.
public class CBaseEntity : NativeEntity, IEquatable<CBaseEntity>
Namespace: DeadworksManaged.Api
Inherits / implements: NativeEntity, IEquatable<CBaseEntity>
Derived types: CBasePlayerController, CBasePlayerPawn, CBeam, CCitadel_Ability_Dash, CCitadel_Ability_Jump, CCitadelBaseAbility, CParticleSystem, CPointWorldText
Source: Entities/CBaseEntity.cs#L7
Properties
CBaseEntity.EntityHandle
Packed CEntityHandle (serial + index) captured at construction. Stable identity across frames.
Signature
public uint EntityHandle { get; }
Source: Entities/CBaseEntity.cs#L12
CBaseEntity.Handle
Resolves the native pointer through the entity system on every access. Returns 0 if the entity has been destroyed (serial mismatch).
Signature
public override nint Handle { get; }
Source: Entities/CBaseEntity.cs#L15
CBaseEntity.IsValid
True only if the entity still exists in the entity system. Returns false once the entity is destroyed (serial mismatch) or if the handle was never valid.
Signature
public override bool IsValid { get; }
Source: Entities/CBaseEntity.cs#L18
CBaseEntity.EntityIndex
Entity index (lower 14 bits of the handle).
Signature
public int EntityIndex { get; }
Source: Entities/CBaseEntity.cs#L21
CBaseEntity.DesignerName
The designer/map name (e.g. "npc_boss_tier3", "player").
Signature
public string DesignerName { get; }
Source: Entities/CBaseEntity.cs#L125
CBaseEntity.Name
The entity name (targetname set in Hammer or via code).
Signature
public string Name { get; }
Source: Entities/CBaseEntity.cs#L136
CBaseEntity.Classname
The C++ DLL class name (e.g. "CCitadelPlayerPawn", "CBaseEntity").
Signature
public string Classname { get; }
Source: Entities/CBaseEntity.cs#L146
CBaseEntity.BodyComponent
Signature
public CBodyComponent? BodyComponent { get; }
Source: Entities/CBaseEntity.cs#L319
CBaseEntity.Position
Signature
public Vector3 Position { get; }
Source: Entities/CBaseEntity.cs#L326
CBaseEntity.Collision
Collision property (OBB mins/maxs, bounding radius). Null for entities without a collision representation.
Signature
public CCollisionProperty? Collision { get; }
Source: Entities/CBaseEntity.cs#L330
CBaseEntity.Health
Signature
public int Health { get; set; }
Source: Entities/CBaseEntity.cs#L347
CBaseEntity.MaxHealth
Signature
public int MaxHealth { get; }
Source: Entities/CBaseEntity.cs#L350
CBaseEntity.TeamNum
Signature
public int TeamNum { get; set; }
Source: Entities/CBaseEntity.cs#L359
CBaseEntity.LifeState
Signature
public LifeState LifeState { get; set; }
Source: Entities/CBaseEntity.cs#L362
CBaseEntity.IsAlive
Signature
public bool IsAlive { get; }
Source: Entities/CBaseEntity.cs#L363
CBaseEntity.Flags
Engine flag bits (on-ground, ducking, client, in-vehicle, godmode, etc.). See EntityFlags.
Signature
public EntityFlags Flags { get; set; }
Source: Entities/CBaseEntity.cs#L367
CBaseEntity.IsBot
True if this entity has the EntityFlags.FakeClient flag set (i.e. it is a bot).
Signature
public bool IsBot { get; }
Source: Entities/CBaseEntity.cs#L370
CBaseEntity.GroundEntity
The entity this entity is standing on, or null if airborne.
Signature
public CBaseEntity? GroundEntity { get; }
Source: Entities/CBaseEntity.cs#L374
CBaseEntity.IsOnGround
Returns true if this entity is on the ground (has a valid ground entity).
Signature
public bool IsOnGround { get; }
Source: Entities/CBaseEntity.cs#L376
CBaseEntity.AbsVelocity
The entity's absolute velocity.
Signature
public Vector3 AbsVelocity { get; set; }
Source: Entities/CBaseEntity.cs#L380
CBaseEntity.Friction
Signature
public float Friction { get; set; }
Source: Entities/CBaseEntity.cs#L383
CBaseEntity.MoveType
How this entity is moving right now. Change it with SetMoveType.
Signature
public MoveType MoveType { get; }
Notes
This can differ from what you set: the noclip cheat command and abilities or items that change movement win while they're active, and an entity attached to another one usually reads Api.MoveType.None.
Source: Entities/CBaseEntity.cs#L392
CBaseEntity.GravityScale
This entity's gravity multiplier: 1 is normal, 0.5 is half gravity, 2 is double and 0 is no gravity. Change it with SetGravityScale.
Signature
public float GravityScale { get; }
Notes Abilities and items that change gravity multiply on top of this, so it isn't always the gravity the entity actually feels.
Source: Entities/CBaseEntity.cs#L414
CBaseEntity.IsModelEntity
True for entities that can have a model, such as heroes, NPCs, props, beams and world text. Only these have a RenderColor, and only these can use SetModel and ModelName.
Signature
public bool IsModelEntity { get; }
Source: Entities/CBaseEntity.cs#L426
CBaseEntity.RenderColor
Tint and transparency of the entity's model. Color.White means no tint. Lowering alpha only makes the entity see-through if it renders translucently.
Signature
public Color RenderColor { get; set; }
Throws
InvalidOperationException: The entity has no model.
Notes
Only entities with a model have one (see IsModelEntity). On anything else, like a player controller, reading or setting it throws.
Source: Entities/CBaseEntity.cs#L444
CBaseEntity.Rotation
Which way the entity faces, as (pitch, yaw, roll) in degrees. Change it with SetRotation.
Signature
public Vector3 Rotation { get; }
Source: Entities/CBaseEntity.cs#L460
CBaseEntity.ModifierProp
Signature
public CModifierProperty? ModifierProp { get; }
Source: Entities/CBaseEntity.cs#L469
CBaseEntity.SubclassVData
Signature
public CEntitySubclassVDataBase? SubclassVData { get; }
Source: Entities/CBaseEntity.cs#L478
CBaseEntity.ModelName
The current model path for this entity (e.g. "models/heroes_wip/werewolf/werewolf.vmdl"), or empty if unset.
Signature
public string ModelName { get; }
Source: Entities/CBaseEntity.cs#L533
Fields
CBaseEntity.InvalidEntityHandle
Sentinel value for an invalid CEntityHandle.
Signature
public const uint InvalidEntityHandle = 0xFFFFFFFF;
Source: Entities/CBaseEntity.cs#L9
Methods
CBaseEntity.ToString()
Signature
public override string ToString()
Source: Entities/CBaseEntity.cs#L32
CBaseEntity.Equals()
Two wrappers are equal iff they point at the same native entity (same packed handle: serial + index). Wrapper type is ignored.
Signature
public bool Equals(CBaseEntity? other)
public override bool Equals(object? obj)
Source: Entities/CBaseEntity.cs#L38, Entities/CBaseEntity.cs#L40
CBaseEntity.GetHashCode()
Signature
public override int GetHashCode()
Source: Entities/CBaseEntity.cs#L42
CBaseEntity.CreateByName()
Creates a new entity by class name (e.g. "info_particle_system"). Returns null on failure.
Signature
public static CBaseEntity? CreateByName(string className)
Source: Entities/CBaseEntity.cs#L53
CBaseEntity.CreateByDesignerName()
Creates an entity by its designer/subclass name (e.g. "npc_boss_tier2"). Resolves the designer name through the subclass registry, creates the entity using the base class, and writes m_nSubclassID + m_pSubclassVData directly so VData is available before Spawn is called.
Signature
public static CBaseEntity? CreateByDesignerName(string designerName)
Source: Entities/CBaseEntity.cs#L67
CBaseEntity.FromHandle()
Gets an entity by its entity handle (CEntityHandle as uint32). Returns null if invalid.
Signature
public static CBaseEntity? FromHandle(uint handle)
public static T? FromHandle<T>(uint handle) where T : CBaseEntity
Source: Entities/CBaseEntity.cs#L95, Entities/CBaseEntity.cs#L108
CBaseEntity.FromIndex()
Gets an entity by its global entity index. Returns null if the index is invalid or the entity doesn't exist.
Signature
public static CBaseEntity? FromIndex(int index)
public static T? FromIndex<T>(int index) where T : CBaseEntity
Source: Entities/CBaseEntity.cs#L102, Entities/CBaseEntity.cs#L117
CBaseEntity.Is()
Check if this entity's native type matches T's class name.
Signature
public bool Is<T>() where T : CBaseEntity
Source: Entities/CBaseEntity.cs#L154
CBaseEntity.As()
Cast this entity to T if the native type matches, otherwise null.
Signature
public T? As<T>() where T : CBaseEntity
Source: Entities/CBaseEntity.cs#L159
CBaseEntity.Remove()
Marks this entity for removal at the end of the current frame (UTIL_Remove).
Signature
public void Remove()
Source: Entities/CBaseEntity.cs#L164
CBaseEntity.Spawn()
Queues and executes entity spawn.
Signature
public void Spawn()
public void Spawn(void* ekv)
public void Spawn(CEntityKeyValues ekv)
Source: Entities/CBaseEntity.cs#L167, Entities/CBaseEntity.cs#L173, Entities/CBaseEntity.cs#L179
CBaseEntity.Teleport()
Teleports this entity. Pass null for any parameter to leave it unchanged.
Signature
public void Teleport(Vector3? position = null, Vector3? angles = null, Vector3? velocity = null)
Source: Entities/CBaseEntity.cs#L185
CBaseEntity.AcceptInput()
Fires an entity input (e.g. "Start", "Stop", "SetParent").
Signature
public void AcceptInput(string inputName, CBaseEntity? activator = null, CBaseEntity? caller = null, string? value = null)
Source: Entities/CBaseEntity.cs#L196
CBaseEntity.SetParent()
Sets this entity's parent via AcceptInput("SetParent", activator: parent, value: "!activator").
Signature
public void SetParent(CBaseEntity parent)
Source: Entities/CBaseEntity.cs#L215
CBaseEntity.ClearParent()
Clears this entity's parent.
Signature
public void ClearParent()
Source: Entities/CBaseEntity.cs#L218
CBaseEntity.AddModifier()
Adds a modifier by VData name (e.g. "modifier_ui_hud_message").
Signature
public CBaseModifier? AddModifier(string name, KeyValues3? kv = null, CBaseEntity? caster = null, CBaseEntity? ability = null, int team = 0)
public CBaseModifier? AddModifier(string name, Dictionary<string, float> abilityValues, KeyValues3? kv = null, CBaseEntity? caster = null, CBaseEntity? ability = null, int team = 0)
Example pawn.AddModifier("ability_doorman_bomb/debuff", kv: kv, abilityValues: new() { ["SlowPercent"] = 100.0f });
Source: Entities/CBaseEntity.cs#L221, Entities/CBaseEntity.cs#L245
CBaseEntity.RemoveModifier()
Removes a specific modifier instance from this entity.
Signature
public bool RemoveModifier(CBaseModifier modifier)
public bool RemoveModifier(string name)
Source: Entities/CBaseEntity.cs#L295, Entities/CBaseEntity.cs#L300
CBaseEntity.EmitSound()
Plays a sound event on this entity.
Signature
public void EmitSound(string soundName, int pitch = 100, float volume = 1.0f, float delay = 0.0f)
Source: Entities/CBaseEntity.cs#L311
CBaseEntity.DisableCollisionsWith()
Stops this entity and other colliding with each other. Everything else still collides with both. Undo it with EnableCollisionsWith.
Signature
public void DisableCollisionsWith(CBaseEntity other)
Source: Entities/CBaseEntity.cs#L341
CBaseEntity.EnableCollisionsWith()
Lets this entity and other collide again.
Signature
public void EnableCollisionsWith(CBaseEntity other)
Source: Entities/CBaseEntity.cs#L344
CBaseEntity.GetMaxHealth()
Gets the effective max health through the engine virtual call (accounts for modifiers, abilities, buffs).
Signature
public int GetMaxHealth()
Source: Entities/CBaseEntity.cs#L353
CBaseEntity.Heal()
Heals the entity by the specified amount (clamped to max health). Returns the actual amount healed.
Signature
public int Heal(float amount)
Source: Entities/CBaseEntity.cs#L356
CBaseEntity.SetMoveType()
Changes how this entity moves. Use Api.MoveType.None to freeze a hero in place, Api.MoveType.NoClip to let them fly through walls, and Api.MoveType.Walk to give them normal movement back. Takes effect straight away.
Signature
public void SetMoveType(MoveType moveType)
Notes
The noclip cheat command and abilities or items that change movement override your value while they're active. It applies again once they end.
Source: Entities/CBaseEntity.cs#L403
CBaseEntity.SetGravityScale()
Changes this entity's gravity multiplier: 1 is normal, 0.5 is half gravity, 2 is double and 0 turns gravity off. Takes effect straight away. Abilities and items that change gravity multiply on top of it.
Signature
public void SetGravityScale(float scale)
Source: Entities/CBaseEntity.cs#L420
CBaseEntity.SetRotation()
Turns the entity to face rotation (pitch, yaw, roll in degrees) without moving it. On a hero this doesn't turn the player's view; use CCitadelPlayerController.SetCameraAngles for that.
Signature
public void SetRotation(Vector3 rotation)
Source: Entities/CBaseEntity.cs#L466
CBaseEntity.Hurt()
Applies damage to this entity (convenience wrapper around TakeDamage).
Signature
public void Hurt(float damage, CBaseEntity? attacker = null, CBaseEntity? inflictor = null, CBaseEntity? ability = null, int damageType = 0)
Source: Entities/CBaseEntity.cs#L486
CBaseEntity.ApplyDamage()
Deals damage to this entity the way the game does, so the target's resistances and other damage modifiers apply. IDeadworksPlugin.OnTakeDamage is called for it.
Signature
public void ApplyDamage(CTakeDamageInfo info)
Notes
Set CTakeDamageInfo.CitadelDamageType to the kind of damage you are dealing (for example ECitadelDamageType.Bullet or ECitadelDamageType.Ability), since it decides which modifiers apply. It starts out as ECitadelDamageType.None.
The final amount is written back into info, so use a new CTakeDamageInfo for each call. Reusing one, for example for every target of an area attack, applies the modifiers again each time.
Calling this from inside an IDeadworksPlugin.OnTakeDamage handler triggers that handler again, so guard against loops (for example when reflecting damage back at the attacker).
Source: Entities/CBaseEntity.cs#L511
CBaseEntity.TakeDamage()
Deals exactly the damage in info, ignoring the target's resistances and other damage modifiers. IDeadworksPlugin.OnTakeDamage is not called. Use ApplyDamage for damage that should behave like the game's own.
Signature
public void TakeDamage(CTakeDamageInfo info)
Source: Entities/CBaseEntity.cs#L520
CBaseEntity.SetModel()
Sets the model for this entity (e.g. "models/heroes_wip/werewolf/werewolf.vmdl").
Signature
public void SetModel(string modelName)
Source: Entities/CBaseEntity.cs#L525
CBaseEntity.SetScale()
Sets this entity's model scale (1.0 = default).
Signature
public void SetScale(float scale)
Source: Entities/CBaseEntity.cs#L541
CBaseEntity.GetField()
Read any schema field by class and field name. For repeated access, prefer a static SchemaAccessor<T> instead.
Signature
public T GetField<T>(ReadOnlySpan<byte> className, ReadOnlySpan<byte> fieldName) where T : unmanaged
Source: Entities/CBaseEntity.cs#L546
CBaseEntity.SetField()
Write any schema field by class and field name. For repeated access, prefer a static SchemaAccessor<T> instead.
Signature
public void SetField<T>(ReadOnlySpan<byte> className, ReadOnlySpan<byte> fieldName, T value) where T : unmanaged
Source: Entities/CBaseEntity.cs#L550
Operators
CBaseEntity operator ==
Signature
public static bool operator ==(CBaseEntity? a, CBaseEntity? b)
Source: Entities/CBaseEntity.cs#L44
CBaseEntity operator !=
Signature
public static bool operator !=(CBaseEntity? a, CBaseEntity? b)
Source: Entities/CBaseEntity.cs#L50