Skip to content

EntityFuncs

GeckoN edited this page Mar 29, 2017 · 5 revisions

The class CEntityFuncs provides an interface that can be used to access methods that operate on entities.

HTML documentation can be found here.

A single global instance exists:

CEntityFuncs g_EntityFuncs;

Methods

CreateEntity

CBaseEntity@ CreateEntity(const string& in szClassName, dictionary@ pDictionary = null, bool fSpawn = true)

Create an entity by class name. Pass keyvalues in using the dictionary, if any. Keyvalues must be strings. The class name can be either one of the entities included with the game or a custom entity.

ArgumentPurpose
szClassNameClass name of the entity to create.
pDictionaryDictionary of keyvalues to initialize the entity with.
fSpawnWhether or not to call DispatchSpawn on the entity.

Returns the entity on success, false otherwise.

Create

CBaseEntity@ Create(const string& in szClassname, const Vector& in vecOrigin, const Vector& in vecAngles, bool fCreateAndDontSpawn, edict_t@ entOwner = null)

Creates an entity by class name.

ArgumentPurpose
szClassNameClass name of the entity to create.
vecOriginOrigin in the world to place the entity.
vecAnglesAngles to set on the entity.
fCreateAndDontSpawnIf true, creates the entity but does not call DispatchSpawn on it.
entOwnerEntity that owns this entity.

Returns the entity on success, false otherwise.

CreateDecal

void CreateDecal(const string& in szDecalName, const Vector& in vecOrigin, const string& in szTargetName = "")

Creates a decal with the specified name. Creating a decal with no name will only work correctly if done at map spawn time.

ArgumentPurpose
szDecalNameName of the decal texture.
vecOriginOrigin in the world to place the decal.
szTargetNameIf not empty, the decal will not be applied immediately, but instead will be applied when triggered.

CreateSprite

CSprite@ CreateSprite(const string& in szSpriteName, const Vector& in vecOrigin, bool fAnimated, float flFrameRate = 10.0f)

Creates a sprite. flFrameRate must be set to a valid value to animate the sprite.

ArgumentPurpose
szSpriteNameName of the sprite file to use. Must be precached.
vecOriginLocation in the world to place the sprite at.
fAnimatedIf true, the sprite is animated.
flFrameRateFramerate for animated sprites.

Returns the sprite on success, null otherwise.

CreateBeam

CBeam@ CreateBeam(const string& in szSpriteName, int width)

Creates a beam entity with the given sprite and width set.

ArgumentPurpose
szSpriteNameName of the sprite file to use. Must be precached.
widthWidth of the beam in units.

Returns the beam on success, null otherwise.

CreateExplosion

void CreateExplosion(const Vector& in vecCenter, const Vector& in vecAngles, edict_t@ pOwner, int iMagnitude, bool fDoDamage)

Creates an explosion.

ArgumentPurpose
vecCenterCenter point of the explosion.
vecAnglesAngles of the explosion entity.
pOwnerOwner of the explosion.
iMagnitudeDamage and radius of the explosion. Radius is 2.5 times the amount of damage.
fDoDamageWhether to do damage or not. Explosions that deal no damage will be a visual effect only.

CreateDisplacerPortal

CBaseEntity@ CreateDisplacerPortal(const Vector& in vecOrigin, const Vector& in vecVelocity, edict_t@ pOwner, float flDamage, float flRadius)

Creates a displacer portal.

ArgumentPurpose
vecOriginOrigin in the world of the displacer portal.
vecVelocityVelocity of the portal. Determines the direction and speed.
pOwnerOwner of the portal. Can be null.
flDamageDamage to deal on touch and on detonation.
flRadiusRadius of the detonation.

Returns the portal entity on success, null otherwise.

CreateRPGRocket

CBaseEntity@ CreateRPGRocket(const Vector& in vecOrigin, const Vector& in vecAngles, edict_t@ pOwner)

Creates an rpg rocket.

ArgumentPurpose
vecOriginOrigin in the world to place the rocket.
vecAnglesAngles of the rocket. Converted to a velocity.
pOwnerOwner of the rocket.

Returns the rocket entity on success, null otherwise.

CreateRPGRocket

CBaseEntity@ CreateRPGRocket(const Vector& in vecOrigin, const Vector& in vecAngles, const Vector& in vecVelocity, edict_t@ pOwner)

Creates an rpg rocket with custom velocity.

Creates an rpg rocket.

ArgumentPurpose
vecOriginOrigin in the world to place the rocket.
vecAnglesAngles of the rocket.
vecVelocityVelocity of the rocket.
pOwnerOwner of the rocket.

Returns the rocket entity on success, null otherwise.

CreateGib

CGib@ CreateGib( const Vector& in vecOrigin, const Vector& in vecAngles)

Creates a server side gib.

ShootTimed

CGrenade@ ShootTimed(entvars_t@ pevOwner, const Vector& in vecStart, const Vector& in vecVelocity, float flTime)

Spawns a timed (hand) grenade.

ArgumentPurpose
pevOwnerOwner of the grenade.
vecStartOrigin in the world to place the grenade.
vecVelocityVelocity of the grenade.
flTimeTime in seconds until explosion.

Returns the grenade entity on success, null otherwise.

ShootContact

CGrenade@ ShootContact(entvars_t@ pevOwner, const Vector& in vecStart, const Vector& in vecVelocity)

Spawns a contact (AR) grenade.

ArgumentPurpose
pevOwnerOwner of the grenade.
vecStartOrigin in the world to place the grenade.
vecVelocityVelocity of the grenade.

Returns the grenade entity on success, null otherwise.

ShootMortar

CGrenade@ ShootMortar(entvars_t@ pevOwner, const Vector& in vecStart, const Vector& in vecVelocity)

Spawns a mortar grenade.

ArgumentPurpose
pevOwnerOwner of the mortar.
vecStartOrigin in the world to place the mortar.
vecVelocityVelocity of the mortar.

Returns the mortar entity on success, null otherwise.

ShootBananaCluster

CGrenade@ ShootBananaCluster(entvars_t@ pevOwner, const Vector& in vecStart, const Vector& in vecVelocity)

Spawn a banana bomb.

ArgumentPurpose
pevOwnerOwner of the bomb.
vecStartOrigin in the world to place the bomb.
vecVelocityVelocity of the bomb.

Returns the bomb entity on success, null otherwise.

UseSatchelCharges

void UseSatchelCharges(entvars_t@ pevOwner, SATCHELCODE code)

Triggers all satchel charges owned by pevOwner to either be released from ownership, or detonated.

See the SATCHELCODE enum.

SpawnHeadGib

void SpawnHeadGib(entvars_t@ pevVictim)

Spawns a head gib for the target victim.

SpawnRandomGibs

void SpawnRandomGibs(entvars_t@ pevVictim, int cGibs, int iHuman)

Spawns random gibs for the target victim.

ArgumentPurpose
pevVictimEntity to spawn gibs for.
cGibsIgnored.
iHumanWhether the gibs should be human (1) or alien (0).

SpawnStickyGibs

void SpawnStickyGibs(entvars_t@ pevVictim, const Vector& in vecOrigin, int cGibs)

Spawns sticky gibs for the target victim.

ArgumentPurpose
pevVictimEntity to spawn gibs for.
vecOriginOrigin in the world to spawn the gibs at.
cGibsNumber of gibs to spawn.

SetOrigin

void SetOrigin(CBaseEntity@ entity, const Vector& in vecOrigin)

Sets the origin of an entity.

SetModel

void SetModel(CBaseEntity@ entity, const string& in szFileName)

Sets the model of an entity. Also sets the entity's bounds (entvars_t::mins and entvars_t::maxs). Call SetSize after this if you need to change the entity's bounds.

SetSize

void SetSize(entvars_t@ pev, const Vector& in vecMin, const Vector& in vecMax)

Sets the size of an entity.

ArgumentPurpose
pevEntity whose bounds will be set.
vecMinMinimum bounds to set.
vecMaxMaximum bounds to set.

FindEntityInSphere

CBaseEntity@ FindEntityInSphere(CBaseEntity@ pStartEntity, const Vector& in vecCenter, float flRadius, const string& in szValue = "", const string& in szKeyword = "targetname")

Finds an entity in a sphere. You can optionally filter by keyvalue.

ArgumentPurpose
pStartEntityif null, finds the first entity in the given sphere. Otherwise, finds the next entity after the given entity that is in the sphere.
vecCenterSphere center.
flRadiusSphere radius.
szValueValue to filter by.
szKeywordKey to filter by.

Returns the next entity, or null.

FindEntityByString

CBaseEntity@ FindEntityByString(CBaseEntity@ pStartEntity, const string& in szKeyword, const string& in szValue)

Finds an entity based on a key value pair.

ArgumentPurpose
pStartEntityif null, finds the first entity that matches the keyvalue pair. Otherwise, finds the next entity after the given entity.
szKeywordKey to filter by.
szValueValue to filter by.

Returns the next entity, or null.

FindEntityByClassname

CBaseEntity@ FindEntityByClassname(CBaseEntity@ startEntity, const string& in name)

Finds an entity by class name.

ArgumentPurpose
pStartEntityif null, finds the first entity with the given classname. Otherwise, finds the next entity after the given entity.
nameClassname to filter by.

Returns the next entity, or null.

FindEntityTargetname

CBaseEntity@ FindEntityByTargetname(CBaseEntity@ startEntity, const string& in name)

Finds an entity by target name.

ArgumentPurpose
pStartEntityif null, finds the first entity with the given targetname. Otherwise, finds the next entity after the given entity.
nameTargetname to filter by.

Returns the next entity, or null.

FindEntityGeneric

CBaseEntity@ FindEntityGeneric(const string& in szName, const Vector& in vecSrc, float flRadius)

Finds an entity by target name in a sphere.

ArgumentPurpose
szNameTargetname to filter by.
vecSrcSphere center.
flRadiusSphere radius.

Returns the first entity it finds, or null.

MonstersInSphere

int MonstersInSphere(array<CBaseEntity@>@ pArray, const Vector& in vecCenter, float flRadius)

Finds monsters in a sphere.

ArgumentPurpose
pArrayArray of entity handles. This array must be resized to the maximum number of entities you wish to find.
vecCenterSphere center.
flRadiusSphere radius.

Returns the number of entities it found.

EntitiesInBox

int EntitiesInBox(array<CBaseEntity@>@ pArray, const Vector& in mins, const Vector& in maxs, int flagMask)

Finds entities in a box.

ArgumentPurpose
pArrayArray of entity handles. This array must be resized to the maximum number of entities you wish to find.
minsMinimum bounds.
maxsMaximum bounds.
flagMaskBit vector containing EdictFlags constants. Ignored if 0, if an entity does not have any of the flags contained in this mask, it is not added to the list.

Returns the number of entities it found.

TargetsInBox

int TargetsInBox(array<CBaseEntity@>@ pArray, const Vector& in mins, const Vector& in maxs)

Finds targets in a box. Anything that could be a target for a monster, like clients, monsters, or brush entities are considered.

ArgumentPurpose
pArrayArray of entity handles. This array must be resized to the maximum number of entities you wish to find.
minsMinimum bounds.
maxsMaximum bounds.

Returns the number of entities it found.

BrushEntsInBox

int BrushEntsInBox(array<CBaseEntity@>@ pArray, const Vector& in mins, const Vector& in maxs)

Finds brush entities in a box.

ArgumentPurpose
pArrayArray of entity handles. This array must be resized to the maximum number of entities you wish to find.
minsMinimum bounds.
maxsMaximum bounds.

Returns the number of entities it found.

DispatchSpawn

int DispatchSpawn(edict_t@ entity)

Dispatches the spawning of an entity.

Returns 0 if the entity was successfully spawned, -1 if it has been/should be deleted.

DispatchKeyValue

bool DispatchKeyValue(edict_t@ entity, const string& in szKeyName, const string& in szValue)

Dispatches the passing of a key value pair to an entity.

EntvarsKeyvalue

bool EntvarsKeyvalue(edict_t@ entity, const string& in szKeyName, const string& in szValue)

Handles the initialization of keyvalues located in the entity's entvars_t object.

ArgumentPurpose
entityEntity to initialize a keyvalue for.
szKeyNameKey to initialize.
szValueValue to initialize with.

Returns true if the key existed and was initialized.

DispatchObjectCollisionBox

void DispatchObjectCollisionBox(edict_t@ entity)

Dispatches the initialization of the collision box of an entity.

Instance

CBaseEntity@ Instance(edict_t@ edict)

Gets the entity instance of an edict instance.

CBaseEntity@ Instance(entvars_t@ vars)

Gets the entity instance of an entvars instance.

CBaseEntity@ Instance(int iEdictNum)

Gets the entity instance based on an edict number.

FireTargets

void FireTargets(const string& in szTargetName, CBaseEntity@ pActivator, CBaseEntity@ pCaller, USE_TYPE useType, float flValue = 0.0f, float flDelay = 0.0f)

Triggers targets. If flDelay is nonzero, causes a temporary entity to be spawned to trigger the target at the given time. The temporary entity becomes the caller, not the entity passed in.

ArgumentPurpose
szTargetNameName of the target(s) to trigger.
pActivatorActivator to pass to the target(s).
pCallerCurrent caller. If flDelay is 0, this will become the caller for the target(s).
useTypeUse type to pass to the target(s).
flValueValue to pass to the target(s).
flDelayDelay before fire.

IsMasterTriggered

bool IsMasterTriggered(const string& in szMaster, CBaseEntity@ pActivator)

Returns whether the master with the given name would be triggered if activated by the given entity.

Remove

void Remove(CBaseEntity@ pEntity)

Removes the given entity before the next frame starts.

IsValidEntity

bool IsValidEntity(edict_t@ pEntity)

Returns whether this is a valid entity.

EntIndex

int EntIndex(edict_t@ pEdict)

Gets the index for the given edict.

IndexEnt

edict_t@ IndexEnt(int iEdictNum)

Gets the edict for the given index.

EjectBrass

void EjectBrass(const Vector& in vecOrigin, const Vector& in vecVelocity, float flRotation, int iModel, TE_BOUNCE soundtype)

Tosses a brass shell from passed origin at passed velocity.

ArgumentPurpose
vecOriginOrigin in the world to place the shell at.
vecVelocityDirection and speed of the shell.
flRotationInitial yaw rotation.
iModelIndex of the model to use.
soundtypeSound type to use. See the TE_BOUNCE enum.

CastToScriptClass

ScriptClassInterface@ CastToScriptClass(CBaseEntity@ pEntity)

Casts an CBaseEntity@ representing a custom entity to the ScriptClassBaseClass type.

RandomTargetname

CBaseEntity@ RandomTargetname(const string& in szTargetname)

Returns a randomly selected entity that has the given target name.

PrecacheMaterialSounds

void PrecacheMaterialSounds(const Materials material)

Precaches the sounds used by a particular material. See the Materials enum.

Clone this wiki locally