Difference between revisions of "CEngineFuncs"

From Sven Co-op
Jump to navigation Jump to search
(Created page with "The class <code>CEngineFuncs</code> provides an interface that can be used to access some of the engine’s features. HTML documentation can be found [http://baso88.github.io...")
 
 
(30 intermediate revisions by the same user not shown)
Line 3: Line 3:
 
HTML documentation can be found [http://baso88.github.io/SC_AngelScript/docs/CEngineFuncs.htm here].
 
HTML documentation can be found [http://baso88.github.io/SC_AngelScript/docs/CEngineFuncs.htm here].
  
A single global instance exists:
+
A single global instance exists: <code>CEngineFuncs g_EngineFuncs;</code>
<pre>CEngineFuncs g_EngineFuncs;</pre>
+
 
 +
This class only contains methods.
 
<span id="methods"></span>
 
<span id="methods"></span>
=== Methods ===
+
== Physics ==
 
 
<span id="modelindex"></span>
 
==== <code>ModelIndex</code> ====
 
 
 
<pre>int ModelIndex(const string&amp; in szModelName)</pre>
 
Gets the model index of a model. This index should be considered to be an opaque handle to the model. It does not represent an index into an array.
 
 
 
If the model was not precached, if it’s a dedicated server, it will be shut down, if it’s a listen server, it will [[Debugging-Scripts#host-errors-and-their-interaction-with-angelscript|throw you back into the main menu and corrupt the Angelscript context]].
 
 
 
<span id="modelframes"></span>
 
==== <code>ModelFrames</code> ====
 
 
 
<pre>int ModelFrames(int iModelIndex)</pre>
 
Gets the number of frames in a model.
 
 
 
For brush models, this is always 2: a regular and alternate (+A) texture. For studio models, this is all of the submodels in each body part multiplied with each-other. It represents the number of variations that can be created by changing submodels (e.g. heads, weapons, etc). For sprite models, this is the number of frames.
 
 
 
<span id="changelevel"></span>
 
==== <code>ChangeLevel</code> ====
 
 
 
<pre>void ChangeLevel(const string&amp; in szLevelName)</pre>
 
Changes the current level to the one specified. Warning: this will change the level right away. Be careful when using this in scripts as it may result in the script being invalidated before it returns.
 
 
 
 
<span id="vectoyaw"></span>
 
<span id="vectoyaw"></span>
 
==== <code>VecToYaw</code> ====
 
==== <code>VecToYaw</code> ====
Line 41: Line 19:
 
<pre>void VecToAngles(const Vector&amp; in vec, Vector&amp; out angles)</pre>
 
<pre>void VecToAngles(const Vector&amp; in vec, Vector&amp; out angles)</pre>
 
Converts a vector to euler angles.
 
Converts a vector to euler angles.
 +
 +
<span id="makevectors"></span>
 +
==== <code>MakeVectors</code> ====
 +
 +
<pre>void MakeVectors(const Vector&amp; in vec)</pre>
 +
Make direction vectors from angles. The results are stored in <code>g_Engine::v_forward</code>, <code>v_right</code>, and <code>v_up</code>. Each vector represents a direction in one of 3 axes.
 +
 +
<span id="anglevectors"></span>
 +
==== <code>AngleVectors</code> ====
 +
 +
<pre>void AngleVectors(const Vector&amp; in vecIn, Vector&amp; out vecForward, Vector&amp; out vecRight, Vector&amp; out vecUp)</pre>
 +
Make direction vectors from angles. This returns the same results as [[#makevectors|<code>MakeVectors</code>]], except the destination vectors can be provided by you.
  
 
<span id="movetoorigin"></span>
 
<span id="movetoorigin"></span>
Line 53: Line 43:
 
! Purpose
 
! Purpose
 
|-
 
|-
| pEntity
+
| <code>entity
 
| Entity to move.
 
| Entity to move.
 
|-
 
|-
| vecGoal
+
| <code>vecGoal
 
| Destination origin.
 
| Destination origin.
 
|-
 
|-
| flDist
+
| <code>flDist
 
| Number of units to move.
 
| Number of units to move.
 
|-
 
|-
| iMoveType
+
| <code>iMoveType
 
| Indicates how the entity should move.
 
| Indicates how the entity should move.
 
|}
 
|}
  
 
<span id="changeyaw"></span>
 
<span id="changeyaw"></span>
 +
 
==== <code>ChangeYaw</code> ====
 
==== <code>ChangeYaw</code> ====
  
Line 77: Line 68:
 
<pre>void ChangePitch(edict_t@ pEntity)</pre>
 
<pre>void ChangePitch(edict_t@ pEntity)</pre>
 
Change pitch. This updates <code>entvars_t::angles[ 0 ]</code> to approach <code>entvars_t::idealpitch</code>, at entvars_t::pitch_speed<code>degrees speed. Not used by any game code. Replaced by [</code>CMath::ApproachAngle`](Math%23ApproachAngle#ApproachAngle).
 
Change pitch. This updates <code>entvars_t::angles[ 0 ]</code> to approach <code>entvars_t::idealpitch</code>, at entvars_t::pitch_speed<code>degrees speed. Not used by any game code. Replaced by [</code>CMath::ApproachAngle`](Math%23ApproachAngle#ApproachAngle).
 +
 +
<span id="getaimvector"></span>
 +
==== <code>GetAimVector</code> ====
 +
 +
<pre>void GetAimVector(edict_t@ pEntity, float flSpeed, Vector&amp; out vecReturn)</pre>
 +
Get the aim vector for the given entity. Assumes [[#makevectors|<code>MakeVectors</code>]] was called with <code>pEntity.vars.angles</code> beforehand.
 +
 +
The aim vector is the autoaim vector used when <code>sv_aim</code> is enabled. It will snap to entities that are close to the entity’s forward vector axis.
 +
 +
{| class="wikitable"
 +
|-
 +
! Argument
 +
! Purpose
 +
|-
 +
| <code>entity
 +
| Entity to retrieve the aim vector for.
 +
|-
 +
| <code>flSpeed
 +
| Unused.
 +
|-
 +
| <code>vecReturn
 +
| Aim vector.
 +
|}
  
 
<span id="getentityillum"></span>
 
<span id="getentityillum"></span>
==== [[#getentityillum|]]<code>GetEntityIllum</code> ====
+
 
 +
==== <code>GetEntityIllum</code> ====
  
 
<pre>int GetEntityIllum(edict_t@ pEntity)</pre>
 
<pre>int GetEntityIllum(edict_t@ pEntity)</pre>
 
Get entity illumination. This is a weighted value between 0 and 255, inclusive.
 
Get entity illumination. This is a weighted value between 0 and 255, inclusive.
  
 +
== Entity Methods ==
 
<span id="findclientinpvs"></span>
 
<span id="findclientinpvs"></span>
==== [[#findclientinpvs|]]<code>FindClientInPVS</code> ====
+
==== <code>FindClientInPVS</code> ====
  
 
<pre>edict_t@ FindClientInPVS(edict_t@ pStartEntity)</pre>
 
<pre>edict_t@ FindClientInPVS(edict_t@ pStartEntity)</pre>
Line 91: Line 107:
  
 
<span id="entitiesinpvs"></span>
 
<span id="entitiesinpvs"></span>
==== [[#entitiesinpvs|]]<code>EntitiesInPVS</code> ====
+
==== <code>EntitiesInPVS</code> ====
  
 
<pre>edict_t@ EntitiesInPVS(edict_t@ pStartEntity)</pre>
 
<pre>edict_t@ EntitiesInPVS(edict_t@ pStartEntity)</pre>
Line 98: Line 114:
 
'''Note:''' This operation is expensive as it checks every entity. Avoid using this unless it is absolutely necessary.
 
'''Note:''' This operation is expensive as it checks every entity. Avoid using this unless it is absolutely necessary.
  
<span id="makevectors"></span>
+
<span id="getvarsofent"></span>
==== [[#makevectors|]]<code>MakeVectors</code> ====
+
==== <code>GetVarsOfEnt</code> ====
 +
 
 +
<pre>entvars_t@ GetVarsOfEnt(edict_t@ pEdict)</pre>
 +
Gets entity variables of entity. Identical to <code>pEdict.vars</code>.
 +
 
 +
<span id="indexofedict"></span>
 +
==== <code>IndexOfEdict</code> ====
 +
 
 +
<pre>int IndexOfEdict(const edict_t@ pEdict)</pre>
 +
Get entity index of edict. The world is <code>0</code>, players are <code>1</code> through <code>g_Engine.maxClients</code>. Regular entities start at <code>g_Engine.maxClients + 1</code>.
 +
 
 +
<span id="pentityofentindex"></span>
 +
==== <code>PEntityOfEntIndex</code> ====
  
<pre>void MakeVectors(const Vector&amp; in vec)</pre>
+
<pre>edict_t@ PEntityOfEntIndex(int iIndex)</pre>
Make direction vectors from angles. The results are stored in <code>g_Engine::v_forward</code>, <code>v_right</code>, and <code>v_up</code>. Each vector represents a direction in one of 3 axes.
+
Get entity by entity index. Returns <code>null</code> if no edict exists at that index. The returned edict does not necessarily have a valid entity attached to it.
  
<span id="anglevectors"></span>
+
<span id="findentitybyvars"></span>
==== [[#anglevectors|]]<code>AngleVectors</code> ====
+
==== <code>FindEntityByVars</code> ====
  
<pre>void AngleVectors(const Vector&amp; in vecIn, Vector&amp; out vecForward, Vector&amp; out vecRight, Vector&amp; out vecUp)</pre>
+
<pre>edict_t@ FindEntityByVars(entvars_t@ pVars)</pre>
Make direction vectors from angles. This returns the same results as [[#makevectors|<code>MakeVectors</code>]], except the destination vectors can be provided by you.
+
Find entity by variables. Identical to <code>pVars.pContainingEntity</code>, but also validates the <code>pContainingEntity</code> field.
  
 
<span id="makestatic"></span>
 
<span id="makestatic"></span>
==== [[#makestatic|]]<code>MakeStatic</code> ====
+
==== <code>MakeStatic</code> ====
  
 
<pre>void MakeStatic(edict_t@ pEntity)</pre>
 
<pre>void MakeStatic(edict_t@ pEntity)</pre>
Line 119: Line 147:
  
 
<span id="entisonfloor"></span>
 
<span id="entisonfloor"></span>
==== [[#entisonfloor|]]<code>EntIsOnFloor</code> ====
+
==== <code>EntIsOnFloor</code> ====
  
 
<pre>int EntIsOnFloor(edict_t@ pEntity)</pre>
 
<pre>int EntIsOnFloor(edict_t@ pEntity)</pre>
Line 125: Line 153:
  
 
<span id="droptofloor"></span>
 
<span id="droptofloor"></span>
==== [[#droptofloor|]]<code>DropToFloor</code> ====
+
==== <code>DropToFloor</code> ====
  
 
<pre>int DropToFloor(edict_t@ pEntity)</pre>
 
<pre>int DropToFloor(edict_t@ pEntity)</pre>
Line 135: Line 163:
  
 
<span id="walkmove"></span>
 
<span id="walkmove"></span>
==== [[#walkmove|]]<code>WalkMove</code> ====
+
==== <code>WalkMove</code> ====
  
 
<pre>int WalkMove(edict_t@ pEntity, float flYaw, float flDist, int iMove)</pre>
 
<pre>int WalkMove(edict_t@ pEntity, float flYaw, float flDist, int iMove)</pre>
Line 147: Line 175:
 
! Purpose
 
! Purpose
 
|-
 
|-
| pEntity
+
| <code>pEntity
 
| Entity to move.
 
| Entity to move.
 
|-
 
|-
| flYaw
+
| <code>flYaw
 
| Yaw distance. This is the entity’s current movement direction in the XY plane.
 
| Yaw distance. This is the entity’s current movement direction in the XY plane.
 
|-
 
|-
| flDist
+
| <code>flDist
 
| Distance to move, in units.
 
| Distance to move, in units.
 
|-
 
|-
| iMove
+
| <code>iMove
 
| Movement type. See the [[WALKMOVE]] enum.
 
| Movement type. See the [[WALKMOVE]] enum.
 
|}
 
|}
Line 162: Line 190:
 
Returns <code>1</code> if the move succeeded (no obstacles in the way), <code>0</code> otherwise.
 
Returns <code>1</code> if the move succeeded (no obstacles in the way), <code>0</code> otherwise.
  
<span id="getaimvector"></span>
+
<span id="numberofentities"></span>
==== [[#getaimvector|]]<code>GetAimVector</code> ====
+
 
 +
==== <code>NumberOfEntities</code> ====
 +
 
 +
<pre>int NumberOfEntities()</pre>
 +
Gets the number of entities. Note: this will calculate the number of entities in real-time. May be expensive if called many times.
 +
 
 +
<span id="getinfokeybuffer"></span>
 +
==== <code>GetInfoKeyBuffer</code> ====
 +
 
 +
<pre>KeyValueBuffer@ GetInfoKeyBuffer(edict_t@ pEdict)</pre>
 +
Get the given client’s info key buffer. This buffer contains settings sent from the client to the server. Returns <code>null</code> if the given edict is not a client or not connected.
  
<pre>void GetAimVector(edict_t@ pEntity, float flSpeed, Vector&amp; out vecReturn)</pre>
+
'''Note:''' Do not store a handle to this instance, it is temporary and may become invalid.
Get the aim vector for the given entity. Assumes [[#makevectors|<code>MakeVectors</code>]] was called with <code>pEntity.vars.angles</code> beforehand.
 
  
The aim vector is the autoaim vector used when <code>sv_aim</code> is enabled. It will snap to entities that are close to the entity’s forward vector axis.
+
See [[KeyValueBuffer|<code>KeyValueBuffer</code>]].
  
{| class="wikitable"
+
<span id="getphysicskeybuffer"></span>
|-
+
==== <code>GetPhysicsKeyBuffer</code> ====
! Argument
 
! Purpose
 
|-
 
| pEntity
 
| Entity to retrieve the aim vector for.
 
|-
 
| flSpeed
 
| Unused.
 
|-
 
| vecReturn
 
| Aim vector.
 
|}
 
  
<span id="servercommand"></span>
+
<pre>KeyValueBuffer@ GetPhysicsKeyBuffer(edict_t@ pEdict)</pre>
==== [[#servercommand|]]<code>ServerCommand</code> ====
+
Get the given client’s physics key buffer. This buffer contains settings that the physics code can access. Returns <code>null</code> if the given edict is not a client or not connected.
  
<pre>void ServerCommand(const string&amp; in szCommand)</pre>
+
'''Note:''' Do not store a handle to this instance, it is temporary and may become invalid.
Issues a command to the server. The command must end with either a newline (<code>\n</code>) or a semicolon (<code>;</code>) in order to be considered valid by the engine.
 
  
Plugins only.
+
See [[KeyValueBuffer|<code>KeyValueBuffer</code>]].
  
<span id="serverexecute"></span>
+
== Server ==
==== [[#serverexecute|]]<code>ServerExecute</code> ====
+
<span id="getgamedir"></span>
 +
==== <code>GetGameDir</code> ====
  
<pre>void ServerExecute()</pre>
+
<pre>string GetGameDir()</pre>
Executes all pending server commands. Note that commands that end the current map may cause data corruption in scripts. Avoid using this unless absolutely necessary.
+
Get game directory. This is <code>svencoop</code> for Sven Co-op, or the mod directory if run under any other mod.
  
Plugins only.
+
<span id="ismapvalid"></span>
 +
==== IsMapValid ====
  
<span id="particleeffect"></span>
+
<pre>bool IsMapValid(const string&amp; in szMapName) const</pre>
==== [[#particleeffect|]]<code>ParticleEffect</code> ====
+
Returns whether the given map is valid. A map is considered valid if the BSP exists.
  
<pre>void ParticleEffect(const Vector&amp; in vecOrigin, const Vector&amp; in vecDir, float flColor, float flCount)</pre>
+
<span id="changelevel"></span>
Emit a particle effect.
+
==== <code>ChangeLevel</code> ====
  
{| class="wikitable"
+
<pre>void ChangeLevel(const string&amp; in szLevelName)</pre>
|-
+
Changes the current level to the one specified. Warning: this will change the level right away. Be careful when using this in scripts as it may result in the script being invalidated before it returns.
! Argument
 
! Purpose
 
|-
 
| vecOrigin
 
| Origin in the world to emit the effect at.
 
|-
 
| vecDir
 
| Direction that the effect will move in.
 
|-
 
| flColor
 
| Color of the effect.
 
|-
 
| flCount
 
| Number of particles to create.
 
|}
 
  
<span id="lightstyle"></span>
+
<span id="servercommand"></span>
==== [[#lightstyle|]]<code>LightStyle</code> ====
+
==== <code>ServerCommand</code> ====
  
<pre>void LightStyle(int iStyle, const string&amp; in szVal)</pre>
+
<pre>void ServerCommand(const string&amp; in szCommand)</pre>
Set a light style.
+
Issues a command to the server. The command must end with either a newline (<code>\n</code>) or a semicolon (<code>;</code>) in order to be considered valid by the engine.
  
{| class="wikitable"
+
Plugins only.
|-
 
! Argument
 
! Purpose
 
|-
 
| iStyle
 
| Light style index. Normally, values below 32 are used for built-in styles, so avoid using them. Half-Life supports up to 64 styles (determined by reverse engineering).
 
|-
 
| szVal
 
| Light pattern. See light entity documentation for custom appearance.
 
|}
 
  
<span id="decalindex"></span>
+
<span id="serverexecute"></span>
==== [[#decalindex|]]<code>DecalIndex</code> ====
+
==== <code>ServerExecute</code> ====
  
<pre>int DecalIndex(const string&amp; in szName)</pre>
+
<pre>void ServerExecute()</pre>
Get decal index.
+
Executes all pending server commands. Note that commands that end the current map may cause data corruption in scripts. Avoid using this unless absolutely necessary.
  
Returns a value greater than <code>0</code> on success, <code>0</code> otherwise.
+
Plugins only.
  
<span id="pointcontents"></span>
+
==== <code>IsDedicatedServer</code> ====
==== [[#pointcontents|]]<code>PointContents</code> ====
 
  
<pre>CONTENTS PointContents(const Vector&amp; in vecPoint)</pre>
+
<pre>bool IsDedicatedServer() const</pre>
Get the [[CONTENTS|Contents]] type for a given point.
+
Returns whether this is a dedicated server (<code>true</code>) or a listen server (<code>false</code>).
  
 
<span id="cvargetfloat"></span>
 
<span id="cvargetfloat"></span>
==== [[#cvargetfloat|]]<code>CVarGetFloat</code> ====
+
==== <code>CVarGetFloat</code> ====
  
 
<pre>float CVarGetFloat(const string&amp; in szCvar)</pre>
 
<pre>float CVarGetFloat(const string&amp; in szCvar)</pre>
Line 264: Line 264:
  
 
<span id="cvargetstring"></span>
 
<span id="cvargetstring"></span>
==== [[#cvargetstring|]]<code>CVarGetString</code> ====
+
==== <code>CVarGetString</code> ====
  
 
<pre>string CVarGetString(const string&amp; in szCvar)</pre>
 
<pre>string CVarGetString(const string&amp; in szCvar)</pre>
Line 270: Line 270:
  
 
<span id="cvarsetfloat"></span>
 
<span id="cvarsetfloat"></span>
==== [[#cvarsetfloat|]]<code>CVarSetFloat</code> ====
+
==== <code>CVarSetFloat</code> ====
  
 
<pre>void CVarSetFloat(const string&amp; in szCvar, float flValue)</pre>
 
<pre>void CVarSetFloat(const string&amp; in szCvar, float flValue)</pre>
Line 276: Line 276:
  
 
<span id="cvarsetstring"></span>
 
<span id="cvarsetstring"></span>
==== [[#cvarsetstring|]]<code>CVarSetString</code> ====
+
==== <code>CVarSetString</code> ====
  
 
<pre>void CVarSetString(const string&amp; in szCvar, const string&amp; in szValue)</pre>
 
<pre>void CVarSetString(const string&amp; in szCvar, const string&amp; in szValue)</pre>
 
Set cvar string value.
 
Set cvar string value.
  
<span id="getvarsofent"></span>
+
<span id="cvargetpointer"></span>
==== [[#getvarsofent|]]<code>GetVarsOfEnt</code> ====
+
==== <code>CVarGetPointer</code> ====
 +
 
 +
<pre>const Cvar@ CVarGetPointer(const string&amp; in szCvar) const</pre>
 +
Gets a pointer to a cvar. Returns <code>null</code> if no cvar by that name exists.
 +
 
 +
See [[Cvar|<code>Cvar</code>]].
  
<pre>entvars_t@ GetVarsOfEnt(edict_t@ pEdict)</pre>
+
== Animation ==
Gets entity variables of entity. Identical to <code>pEdict.vars</code>.
 
  
<span id="indexofedict"></span>
+
<span id="modelindex"></span>
==== [[#indexofedict|]]<code>IndexOfEdict</code> ====
+
==== <code>ModelIndex</code> ====
  
<pre>int IndexOfEdict(const edict_t@ pEdict)</pre>
+
<pre>int ModelIndex(const string&amp; in szModelName)</pre>
Get entity index of edict. The world is <code>0</code>, players are <code>1</code> through <code>g_Engine.maxClients</code>. Regular entities start at <code>g_Engine.maxClients + 1</code>.
+
Gets the model index of a model. This index should be considered to be an opaque handle to the model. It does not represent an index into an array.
  
<span id="pentityofentindex"></span>
+
If the model was not precached, if it’s a dedicated server, it will be shut down, if it’s a listen server, it will [[Debugging-Scripts#host-errors-and-their-interaction-with-angelscript|throw you back into the main menu and corrupt the Angelscript context]].
==== [[#pentityofentindex|]]<code>PEntityOfEntIndex</code> ====
 
  
<pre>edict_t@ PEntityOfEntIndex(int iIndex)</pre>
+
<span id="modelframes"></span>
Get entity by entity index. Returns <code>null</code> if no edict exists at that index. The returned edict does not necessarily have a valid entity attached to it.
+
==== <code>ModelFrames</code> ====
  
<span id="findentitybyvars"></span>
+
<pre>int ModelFrames(int iModelIndex)</pre>
==== [[#findentitybyvars|]]<code>FindEntityByVars</code> ====
+
Gets the number of frames in a model.
  
<pre>edict_t@ FindEntityByVars(entvars_t@ pVars)</pre>
+
For brush models, this is always 2: a regular and alternate (+A) texture. For studio models, this is all of the submodels in each body part multiplied with each-other. It represents the number of variations that can be created by changing submodels (e.g. heads, weapons, etc). For sprite models, this is the number of frames.
Find entity by variables. Identical to <code>pVars.pContainingEntity</code>, but also validates the <code>pContainingEntity</code> field.
 
  
 
<span id="animationautomove"></span>
 
<span id="animationautomove"></span>
==== [[#animationautomove|]]<code>AnimationAutomove</code> ====
+
==== <code>AnimationAutomove</code> ====
  
 
<pre>void AnimationAutomove(const edict_t@ pEdict, float flTime)</pre>
 
<pre>void AnimationAutomove(const edict_t@ pEdict, float flTime)</pre>
Line 314: Line 316:
  
 
<span id="getboneposition"></span>
 
<span id="getboneposition"></span>
==== [[#getboneposition|]]<code>GetBonePosition</code> ====
+
==== <code>GetBonePosition</code> ====
  
 
<pre>void GetBonePosition(const edict_t@ pEdict, int iBone, Vector&amp; out vecOrigin, Vector&amp; out vecAngles)</pre>
 
<pre>void GetBonePosition(const edict_t@ pEdict, int iBone, Vector&amp; out vecOrigin, Vector&amp; out vecAngles)</pre>
Line 324: Line 326:
 
! Purpose
 
! Purpose
 
|-
 
|-
| pEdict
+
| <code>pEdict
 
| Entity whose bone position should be retrieved.
 
| Entity whose bone position should be retrieved.
 
|-
 
|-
| iBone
+
| <code>iBone
 
| Bone index.
 
| Bone index.
 
|-
 
|-
| vecOrigin
+
| <code>vecOrigin
 
| Bone position.
 
| Bone position.
 
|-
 
|-
| vecAngles
+
| <code>vecAngles
 
| Bone angles.
 
| Bone angles.
 
|}
 
|}
  
 +
==== <code>GetAttachment</code> ====
 +
 +
<pre>void GetAttachment(const edict_t@ pEdict, int iAttachment, Vector&amp; out vecOrigin, Vector&amp; out vecAngles)</pre>
 +
Get attachment position and angles. The position is an absolute world position, the angles are absolute angles in the world.
 +
 +
{| class="wikitable"
 +
|-
 +
! Argument
 +
! Purpose
 +
|-
 +
| <code>pEdict
 +
| Entity whose model will be queried for the attachment position.
 +
|-
 +
| <code>iAttachment
 +
| Attachment index.
 +
|-
 +
| <code>vecOrigin
 +
| Attachment origin.
 +
|-
 +
| <code>vecAngles
 +
| Attachment angles.
 +
|}
 +
 +
== Text I/O ==
 
<span id="clientprintf"></span>
 
<span id="clientprintf"></span>
==== [[#clientprintf|]]<code>ClientPrintf</code> ====
+
==== <code>ClientPrintf</code> ====
  
 
<pre>void ClientPrintf(CBasePlayer@ pPlayer, PRINT_TYPE printType, const string&amp; in szMessage)</pre>
 
<pre>void ClientPrintf(CBasePlayer@ pPlayer, PRINT_TYPE printType, const string&amp; in szMessage)</pre>
Line 346: Line 372:
  
 
<span id="serverprint"></span>
 
<span id="serverprint"></span>
==== [[#serverprint|]]<code>ServerPrint</code> ====
+
==== <code>ServerPrint</code> ====
  
 
<pre>void ServerPrint(const string&amp; in szMessage)</pre>
 
<pre>void ServerPrint(const string&amp; in szMessage)</pre>
Line 352: Line 378:
  
 
<span id="cmd_args"></span>
 
<span id="cmd_args"></span>
==== [[#cmd_args|]]<code>Cmd_Args</code> ====
+
==== <code>Cmd_Args</code> ====
  
 
<pre>string Cmd_Args()</pre>
 
<pre>string Cmd_Args()</pre>
Line 358: Line 384:
  
 
<span id="cmd_argv"></span>
 
<span id="cmd_argv"></span>
==== [[#cmd_argv|]]<code>Cmd_Argv</code> ====
+
==== <code>Cmd_Argv</code> ====
  
 
<pre>string Cmd_Argv(int iIndex)</pre>
 
<pre>string Cmd_Argv(int iIndex)</pre>
Line 364: Line 390:
  
 
<span id="cmd_argc"></span>
 
<span id="cmd_argc"></span>
==== [[#cmd_argc|]]<code>Cmd_Argc</code> ====
+
==== <code>Cmd_Argc</code> ====
  
 
<pre>int Cmd_Argc()</pre>
 
<pre>int Cmd_Argc()</pre>
 
Gets the number of command arguments from the command that is currently being executed.
 
Gets the number of command arguments from the command that is currently being executed.
  
<span id="getattachment"></span>
+
== Client ==
==== [[#getattachment|]]<code>GetAttachment</code> ====
 
 
 
<pre>void GetAttachment(const edict_t@ pEdict, int iAttachment, Vector&amp; out vecOrigin, Vector&amp; out vecAngles)</pre>
 
Get attachment position and angles. The position is an absolute world position, the angles are absolute angles in the world.
 
 
 
{| class="wikitable"
 
|-
 
! Argument
 
! Purpose
 
|-
 
| pEdict
 
| Entity whose model will be queried for the attachment position.
 
|-
 
| iAttachment
 
| Attachment index.
 
|-
 
| vecOrigin
 
| Attachment origin.
 
|-
 
| vecAngles
 
| Attachment angles.
 
|}
 
 
 
 
<span id="setview"></span>
 
<span id="setview"></span>
==== [[#setview|]]<code>SetView</code> ====
+
==== <code>SetView</code> ====
  
 
<pre>void SetView(const edict_t@ pEdict, const edict_t@ pViewEntity)</pre>
 
<pre>void SetView(const edict_t@ pEdict, const edict_t@ pViewEntity)</pre>
 
Set player view to a given entity. Pass pEdict as the view entity to reset it to the player’s view.
 
Set player view to a given entity. Pass pEdict as the view entity to reset it to the player’s view.
 
<span id="time"></span>
 
==== [[#time|]]<code>Time</code> ====
 
 
<pre>float Time()</pre>
 
Returns the time since the first call to <code>Time</code>. Used for delta operations that operate in real world time, as opposed to game world time (which will advance frame by frame, and can be paused).
 
  
 
<span id="crosshairangle"></span>
 
<span id="crosshairangle"></span>
==== [[#crosshairangle|]]<code>CrosshairAngle</code> ====
+
==== <code>CrosshairAngle</code> ====
  
 
<pre>void CrosshairAngle(const edict_t@ pEdict, float flPitch, float flYaw)</pre>
 
<pre>void CrosshairAngle(const edict_t@ pEdict, float flPitch, float flYaw)</pre>
 
Sets the angles of the given player’s crosshairs to the given settings. Set both to <code>0</code> to disable. May not have any effect in Sven Co-op.
 
Sets the angles of the given player’s crosshairs to the given settings. Set both to <code>0</code> to disable. May not have any effect in Sven Co-op.
 
<span id="getgamedir"></span>
 
==== [[#getgamedir|]]<code>GetGameDir</code> ====
 
 
<pre>string GetGameDir()</pre>
 
Get game directory. This is <code>svencoop</code> for Sven Co-op, or the mod directory if run under any other mod.
 
  
 
<span id="setclientmaxspeed"></span>
 
<span id="setclientmaxspeed"></span>
==== [[#setclientmaxspeed|]]<code>SetClientMaxspeed</code> ====
+
==== <code>SetClientMaxspeed</code> ====
  
 
<pre>void SetClientMaxspeed(const edict_t@ pEdict, float flNewMaxSpeed)</pre>
 
<pre>void SetClientMaxspeed(const edict_t@ pEdict, float flNewMaxSpeed)</pre>
Line 424: Line 415:
  
 
<span id="runplayermove"></span>
 
<span id="runplayermove"></span>
==== [[#runplayermove|]]<code>RunPlayerMove</code> ====
+
==== <code>RunPlayerMove</code> ====
  
 
<pre>void RunPlayerMove(edict_t@ pEdict, const Vector&amp; in vecViewAngles, float flForwardMove, float flSideMove, float flUpMove, uint16 iButtons, uint8 iImpulse, uint8 iMsec)</pre>
 
<pre>void RunPlayerMove(edict_t@ pEdict, const Vector&amp; in vecViewAngles, float flForwardMove, float flSideMove, float flUpMove, uint16 iButtons, uint8 iImpulse, uint8 iMsec)</pre>
Line 434: Line 425:
 
! Purpose
 
! Purpose
 
|-
 
|-
| pEdict
+
| <code>pEdict
 
| client to move. Must be a fake client.
 
| client to move. Must be a fake client.
 
|-
 
|-
| vecViewAngles
+
| <code>vecViewAngles
 
| Client view angles.
 
| Client view angles.
 
|-
 
|-
| flForwardMove
+
| <code>flForwardMove
 
| Velocity X value.
 
| Velocity X value.
 
|-
 
|-
| flSideMove
+
| <code>flSideMove
 
| Velocity Y value.
 
| Velocity Y value.
 
|-
 
|-
| flUpMove
+
| <code>flUpMove
 
| Velocity Z value.
 
| Velocity Z value.
 
|-
 
|-
| iButtons
+
| <code>iButtons
 
| Buttons that are currently pressed in. Equivalent to player pev.button.
 
| Buttons that are currently pressed in. Equivalent to player pev.button.
 
|-
 
|-
| iImpulse
+
| <code>iImpulse
 
| Impulse commands to execute. Equivalent to player pev.impulse.
 
| Impulse commands to execute. Equivalent to player pev.impulse.
 
|-
 
|-
| iMsec
+
| <code>iMsec
 
| Time between now and previous RunPlayerMove call.
 
| Time between now and previous RunPlayerMove call.
 
|}
 
|}
  
<span id="numberofentities"></span>
+
<span id="getplayeruserid"></span>
==== [[#numberofentities|]]<code>NumberOfEntities</code> ====
 
 
 
<pre>int NumberOfEntities()</pre>
 
Gets the number of entities. Note: this will calculate the number of entities in real-time. May be expensive if called many times.
 
 
 
<span id="getinfokeybuffer"></span>
 
==== [[#getinfokeybuffer|]]<code>GetInfoKeyBuffer</code> ====
 
 
 
<pre>KeyValueBuffer@ GetInfoKeyBuffer(edict_t@ pEdict)</pre>
 
Get the given client’s info key buffer. This buffer contains settings sent from the client to the server. Returns <code>null</code> if the given edict is not a client or not connected.
 
 
 
'''Note:''' Do not store a handle to this instance, it is temporary and may become invalid.
 
 
 
See [[KeyValueBuffer|<code>KeyValueBuffer</code>]].
 
 
 
<span id="getphysicskeybuffer"></span>
 
==== [[#getphysicskeybuffer|]]<code>GetPhysicsKeyBuffer</code> ====
 
 
 
<pre>KeyValueBuffer@ GetPhysicsKeyBuffer(edict_t@ pEdict)</pre>
 
Get the given client’s physics key buffer. This buffer contains settings that the physics code can access. Returns <code>null</code> if the given edict is not a client or not connected.
 
 
 
'''Note:''' Do not store a handle to this instance, it is temporary and may become invalid.
 
 
 
See [[KeyValueBuffer|<code>KeyValueBuffer</code>]].
 
 
 
<span id="ismapvalid"></span>
 
==== [[#ismapvalid|]]IsMapValid ====
 
 
 
<pre>bool IsMapValid(const string&amp; in szMapName) const</pre>
 
Returns whether the given map is valid. A map is considered valid if the BSP exists.
 
 
 
<span id="staticdecal"></span>
 
==== [[#staticdecal|]]<code>StaticDecal</code> ====
 
 
 
<pre>void StaticDecal(const Vector&amp; in vecOrigin, int iDecalIndex, int iEntityIndex, int iModelIndex)</pre>
 
Project a static decal. Only allowed while the map is loading. Only works on brush models.
 
 
 
{| class="wikitable"
 
|-
 
! Argument
 
! Purpose
 
|-
 
| vecOrigin
 
| Origin in the world to project the decal at.
 
|-
 
| iDecalIndex
 
| Index of the decal. Must be retrieved using DecalIndex.
 
|-
 
| iEntityIndex
 
| Index of the entity to project the decal onto.
 
|-
 
| iModelIndex
 
| Index of the model to project the decal onto.
 
|}
 
  
<span id="getplayeruserid"></span>
+
==== <code>GetPlayerUserId</code> ====
==== [[#getplayeruserid|]]<code>GetPlayerUserId</code> ====
 
  
 
<pre>int GetPlayerUserId(edict_t@ pEdict)</pre>
 
<pre>int GetPlayerUserId(edict_t@ pEdict)</pre>
 
Get player user ID. This is a unique id generated when a player connects. It remains valid as long as the player stays connected to the server.
 
Get player user ID. This is a unique id generated when a player connects. It remains valid as long as the player stays connected to the server.
 
<span id="isdedicatedserver"></span>
 
==== [[#isdedicatedserver|]]<code>IsDedicatedServer</code> ====
 
 
<pre>bool IsDedicatedServer() const</pre>
 
Returns whether this is a dedicated server (<code>true</code>) or a listen server (<code>false</code>).
 
 
<span id="cvargetpointer"></span>
 
==== [[#cvargetpointer|]]<code>CVarGetPointer</code> ====
 
 
<pre>const Cvar@ CVarGetPointer(const string&amp; in szCvar) const</pre>
 
Gets a pointer to a cvar. Returns <code>null</code> if no cvar by that name exists.
 
 
See [[Cvar|<code>Cvar</code>]].
 
  
 
<span id="getplayerstats"></span>
 
<span id="getplayerstats"></span>
==== [[#getplayerstats|]]<code>GetPlayerStats</code> ====
+
==== <code>GetPlayerStats</code> ====
  
 
<pre>void GetPlayerStats(const edict_t@ pEdict, int&amp; out iPing, int&amp; out iPacketLoss)</pre>
 
<pre>void GetPlayerStats(const edict_t@ pEdict, int&amp; out iPing, int&amp; out iPacketLoss)</pre>
Line 546: Line 468:
 
! Purpose
 
! Purpose
 
|-
 
|-
| pEdict
+
| <code>pEdict
 
| Client to get stats from.
 
| Client to get stats from.
 
|-
 
|-
| iPing
+
| <code>iPing
 
| Current ping.
 
| Current ping.
 
|-
 
|-
| iPacketLoss
+
| <code>iPacketLoss
 
| Current packet loss, measured in percentage.
 
| Current packet loss, measured in percentage.
 
|}
 
|}
  
 
<span id="voice_getclientlistening"></span>
 
<span id="voice_getclientlistening"></span>
==== [[#voice_getclientlistening|]]<code>Voice_GetClientListening</code> ====
+
 
 +
==== <code>Voice_GetClientListening</code> ====
  
 
<pre>void Voice_GetClientListening(int iReceiver, int iSender)</pre>
 
<pre>void Voice_GetClientListening(int iReceiver, int iSender)</pre>
Line 567: Line 490:
 
! Purpose
 
! Purpose
 
|-
 
|-
| iReceiver
+
| <code>iReceiver
 
| Entity index of the receiving client.
 
| Entity index of the receiving client.
 
|-
 
|-
| iSender
+
| <code>iSender
 
| Entity index of the sending client.
 
| Entity index of the sending client.
 
|}
 
|}
Line 577: Line 500:
  
 
<span id="voice_setclientlistening"></span>
 
<span id="voice_setclientlistening"></span>
==== [[#voice_setclientlistening|]]<code>Voice_SetClientListening</code> ====
+
 
 +
==== <code>Voice_SetClientListening</code> ====
  
 
<pre>void Voice_SetClientListening(int iReceiver, int iSender, bool fListen)</pre>
 
<pre>void Voice_SetClientListening(int iReceiver, int iSender, bool fListen)</pre>
Line 589: Line 513:
 
! Purpose
 
! Purpose
 
|-
 
|-
| iReceiver
+
| <code>iReceiver
 
| Entity index of the receiving client.
 
| Entity index of the receiving client.
 
|-
 
|-
| iSender
+
| <code>iSender
 
| Entity index of the sending client.
 
| Entity index of the sending client.
 
|-
 
|-
| fListen
+
| <code>fListen
 
| Whether or not the receiver should be able to hear the sender.
 
| Whether or not the receiver should be able to hear the sender.
 
|}
 
|}
  
 
<span id="getplayerauthid"></span>
 
<span id="getplayerauthid"></span>
==== [[#getplayerauthid|]]<code>GetPlayerAuthId</code> ====
+
 
 +
==== <code>GetPlayerAuthId</code> ====
  
 
<pre>string GetPlayerAuthId(edict_t@ pEdict)</pre>
 
<pre>string GetPlayerAuthId(edict_t@ pEdict)</pre>
 
Get player auth id. (WON/Steam id).
 
Get player auth id. (WON/Steam id).
 +
 +
== Misc ==
 +
 +
<span id="particleeffect"></span>
 +
==== <code>ParticleEffect</code> ====
 +
 +
<pre>void ParticleEffect(const Vector&amp; in vecOrigin, const Vector&amp; in vecDir, float flColor, float flCount)</pre>
 +
Emit a particle effect.
 +
 +
{| class="wikitable"
 +
|-
 +
! Argument
 +
! Purpose
 +
|-
 +
| <code>vecOrigin
 +
| Origin in the world to emit the effect at.
 +
|-
 +
| <code>vecDir
 +
| Direction that the effect will move in.
 +
|-
 +
| <code>flColor
 +
| Color of the effect.
 +
|-
 +
| <code>flCount
 +
| Number of particles to create.
 +
|}
 +
 +
==== <code>StaticDecal</code> ====
 +
 +
<pre>void StaticDecal(const Vector&amp; in vecOrigin, int iDecalIndex, int iEntityIndex, int iModelIndex)</pre>
 +
Project a static decal. Only allowed while the map is loading. Only works on brush models.
 +
 +
{| class="wikitable"
 +
|-
 +
! Argument
 +
! Purpose
 +
|-
 +
| <code>vecOrigin
 +
| Origin in the world to project the decal at.
 +
|-
 +
| <code>iDecalIndex
 +
| Index of the decal. Must be retrieved using DecalIndex.
 +
|-
 +
| <code>iEntityIndex
 +
| Index of the entity to project the decal onto.
 +
|-
 +
| <code>iModelIndex
 +
| Index of the model to project the decal onto.
 +
|}
 +
 +
==== <code>DecalIndex</code> ====
 +
 +
<pre>int DecalIndex(const string&amp; in szName)</pre>
 +
Get decal index.
 +
 +
Returns a value greater than <code>0</code> on success, <code>0</code> otherwise.
 +
 +
<span id="lightstyle"></span>
 +
==== <code>LightStyle</code> ====
 +
 +
<pre>void LightStyle(int iStyle, const string&amp; in szVal)</pre>
 +
Set a light style.
 +
 +
{| class="wikitable"
 +
|-
 +
! Argument
 +
! Purpose
 +
|-
 +
| <code>iStyle
 +
| Light style index. Normally, values below 32 are used for built-in styles, so avoid using them. Half-Life supports up to 64 styles (determined by reverse engineering).
 +
|-
 +
| <code>szVal
 +
| Light pattern. See light entity documentation for custom appearance.
 +
|}
 +
 +
<span id="pointcontents"></span>
 +
 +
==== <code>PointContents</code> ====
 +
 +
<pre>CONTENTS PointContents(const Vector&amp; in vecPoint)</pre>
 +
Get the [[CONTENTS|Contents]] type for a given point.
 +
 +
<span id="time"></span>
 +
==== <code>Time</code> ====
 +
 +
<pre>float Time()</pre>
 +
Returns the time since the first call to <code>Time</code>. Used for delta operations that operate in real world time, as opposed to game world time (which will advance frame by frame, and can be paused).
 +
[[Category:Scripting]]

Latest revision as of 20:01, 16 February 2025

The class CEngineFuncs provides an interface that can be used to access some of the engine’s features.

HTML documentation can be found here.

A single global instance exists: CEngineFuncs g_EngineFuncs;

This class only contains methods.

1 Physics

1.1 VecToYaw

float VecToYaw(const Vector& in vec)

Converts a vector to a yaw value.

1.2 VecToAngles

void VecToAngles(const Vector& in vec, Vector& out angles)

Converts a vector to euler angles.

1.3 MakeVectors

void MakeVectors(const Vector& in vec)

Make direction vectors from angles. The results are stored in g_Engine::v_forward, v_right, and v_up. Each vector represents a direction in one of 3 axes.

1.4 AngleVectors

void AngleVectors(const Vector& in vecIn, Vector& out vecForward, Vector& out vecRight, Vector& out vecUp)

Make direction vectors from angles. This returns the same results as MakeVectors, except the destination vectors can be provided by you.

1.5 MoveToOrigin

void MoveToOrigin(edict_t@ pEntity, const Vector& in vecGoal, float flDist, int iMoveType)

Moves an entity that can fly (pev.flags & FL_FLY), swim (pev.flags & FL_SWIM), or is on ground (pev.flags & FL_ONGROUND) to a location in the world.

Argument Purpose
entity Entity to move.
vecGoal Destination origin.
flDist Number of units to move.
iMoveType Indicates how the entity should move.

1.6 ChangeYaw

void ChangeYaw(edict_t@ pEntity)

Change yaw. This updates entvars_t::angles[ 1 ] to approach entvars_t::ideal_yaw, at entvars_t::yaw_speed degrees speed. Not used by any game code. Replaced by CMath::ApproachAngle.

1.7 ChangePitch

void ChangePitch(edict_t@ pEntity)

Change pitch. This updates entvars_t::angles[ 0 ] to approach entvars_t::idealpitch, at entvars_t::pitch_speeddegrees speed. Not used by any game code. Replaced by [CMath::ApproachAngle`](Math%23ApproachAngle#ApproachAngle).

1.8 GetAimVector

void GetAimVector(edict_t@ pEntity, float flSpeed, Vector& out vecReturn)

Get the aim vector for the given entity. Assumes MakeVectors was called with pEntity.vars.angles beforehand.

The aim vector is the autoaim vector used when sv_aim is enabled. It will snap to entities that are close to the entity’s forward vector axis.

Argument Purpose
entity Entity to retrieve the aim vector for.
flSpeed Unused.
vecReturn Aim vector.

1.9 GetEntityIllum

int GetEntityIllum(edict_t@ pEntity)

Get entity illumination. This is a weighted value between 0 and 255, inclusive.

2 Entity Methods

2.1 FindClientInPVS

edict_t@ FindClientInPVS(edict_t@ pStartEntity)

Find client in Potentially Visible Set. Returns the world if no client could be found in the entity’s PVS. This function’s behaviour is unexpected: it will get the next client every 0.1 seconds, and check if the entity can see it. If so, the client is returned. Otherwise, the world is returned. Use FNullEnt to check if the result is a valid client.

2.2 EntitiesInPVS

edict_t@ EntitiesInPVS(edict_t@ pStartEntity)

Find entities in Potentially Visible Set. This builds a list of entities using edict_t::vars::chain. This list is temporary, so store its results elsewhere if it is needed later on.

Note: This operation is expensive as it checks every entity. Avoid using this unless it is absolutely necessary.

2.3 GetVarsOfEnt

entvars_t@ GetVarsOfEnt(edict_t@ pEdict)

Gets entity variables of entity. Identical to pEdict.vars.

2.4 IndexOfEdict

int IndexOfEdict(const edict_t@ pEdict)

Get entity index of edict. The world is 0, players are 1 through g_Engine.maxClients. Regular entities start at g_Engine.maxClients + 1.

2.5 PEntityOfEntIndex

edict_t@ PEntityOfEntIndex(int iIndex)

Get entity by entity index. Returns null if no edict exists at that index. The returned edict does not necessarily have a valid entity attached to it.

2.6 FindEntityByVars

edict_t@ FindEntityByVars(entvars_t@ pVars)

Find entity by variables. Identical to pVars.pContainingEntity, but also validates the pContainingEntity field.

2.7 MakeStatic

void MakeStatic(edict_t@ pEntity)

Make entity static. This moves the entity to the client. Its current visual state is copied over, and the entity is removed on the server side. Only valid while the level is loading.

Note: Creating too many static entities may cause clients to overflow on connect.

2.8 EntIsOnFloor

int EntIsOnFloor(edict_t@ pEntity)

Returns whether the entity is on the floor. This will perform traces to see if there is a floor under the entity, which can be costly if used often.

2.9 DropToFloor

int DropToFloor(edict_t@ pEntity)

Drops the entity to the floor. The entity will be moved down to the floor, effectively being teleported.

Note: maximum drop distance is 256 units.

Returns -1 if the entity is stuck inside a solid object. Returns 0 if the floor is further than 256 units away. Returns 1 if the entity was dropped to the floor.

2.10 WalkMove

int WalkMove(edict_t@ pEntity, float flYaw, float flDist, int iMove)

Make entity walk.

The entity must be capable of flying (FL_FLY) or swimming (FL_SWIM), or be on the ground (FL_ONGROUND).

Argument Purpose
pEntity Entity to move.
flYaw Yaw distance. This is the entity’s current movement direction in the XY plane.
flDist Distance to move, in units.
iMove Movement type. See the WALKMOVE enum.

Returns 1 if the move succeeded (no obstacles in the way), 0 otherwise.

2.11 NumberOfEntities

int NumberOfEntities()

Gets the number of entities. Note: this will calculate the number of entities in real-time. May be expensive if called many times.

2.12 GetInfoKeyBuffer

KeyValueBuffer@ GetInfoKeyBuffer(edict_t@ pEdict)

Get the given client’s info key buffer. This buffer contains settings sent from the client to the server. Returns null if the given edict is not a client or not connected.

Note: Do not store a handle to this instance, it is temporary and may become invalid.

See KeyValueBuffer.

2.13 GetPhysicsKeyBuffer

KeyValueBuffer@ GetPhysicsKeyBuffer(edict_t@ pEdict)

Get the given client’s physics key buffer. This buffer contains settings that the physics code can access. Returns null if the given edict is not a client or not connected.

Note: Do not store a handle to this instance, it is temporary and may become invalid.

See KeyValueBuffer.

3 Server

3.1 GetGameDir

string GetGameDir()

Get game directory. This is svencoop for Sven Co-op, or the mod directory if run under any other mod.

3.2 IsMapValid

bool IsMapValid(const string& in szMapName) const

Returns whether the given map is valid. A map is considered valid if the BSP exists.

3.3 ChangeLevel

void ChangeLevel(const string& in szLevelName)

Changes the current level to the one specified. Warning: this will change the level right away. Be careful when using this in scripts as it may result in the script being invalidated before it returns.

3.4 ServerCommand

void ServerCommand(const string& in szCommand)

Issues a command to the server. The command must end with either a newline (\n) or a semicolon (;) in order to be considered valid by the engine.

Plugins only.

3.5 ServerExecute

void ServerExecute()

Executes all pending server commands. Note that commands that end the current map may cause data corruption in scripts. Avoid using this unless absolutely necessary.

Plugins only.

3.6 IsDedicatedServer

bool IsDedicatedServer() const

Returns whether this is a dedicated server (true) or a listen server (false).

3.7 CVarGetFloat

float CVarGetFloat(const string& in szCvar)

Get cvar float value. Returns 0 if the cvar doesn’t exist.

3.8 CVarGetString

string CVarGetString(const string& in szCvar)

Get cvar string value. Returns an empty string if the cvar doesn’t exist.

3.9 CVarSetFloat

void CVarSetFloat(const string& in szCvar, float flValue)

Set cvar float value.

3.10 CVarSetString

void CVarSetString(const string& in szCvar, const string& in szValue)

Set cvar string value.

3.11 CVarGetPointer

const Cvar@ CVarGetPointer(const string& in szCvar) const

Gets a pointer to a cvar. Returns null if no cvar by that name exists.

See Cvar.

4 Animation

4.1 ModelIndex

int ModelIndex(const string& in szModelName)

Gets the model index of a model. This index should be considered to be an opaque handle to the model. It does not represent an index into an array.

If the model was not precached, if it’s a dedicated server, it will be shut down, if it’s a listen server, it will throw you back into the main menu and corrupt the Angelscript context.

4.2 ModelFrames

int ModelFrames(int iModelIndex)

Gets the number of frames in a model.

For brush models, this is always 2: a regular and alternate (+A) texture. For studio models, this is all of the submodels in each body part multiplied with each-other. It represents the number of variations that can be created by changing submodels (e.g. heads, weapons, etc). For sprite models, this is the number of frames.

4.3 AnimationAutomove

void AnimationAutomove(const edict_t@ pEdict, float flTime)

Animation auto move.

Note: Does nothing, remove from the API.

4.4 GetBonePosition

void GetBonePosition(const edict_t@ pEdict, int iBone, Vector& out vecOrigin, Vector& out vecAngles)

Get the bone position of the given entity’s model.

Argument Purpose
pEdict Entity whose bone position should be retrieved.
iBone Bone index.
vecOrigin Bone position.
vecAngles Bone angles.

4.5 GetAttachment

void GetAttachment(const edict_t@ pEdict, int iAttachment, Vector& out vecOrigin, Vector& out vecAngles)

Get attachment position and angles. The position is an absolute world position, the angles are absolute angles in the world.

Argument Purpose
pEdict Entity whose model will be queried for the attachment position.
iAttachment Attachment index.
vecOrigin Attachment origin.
vecAngles Attachment angles.

5 Text I/O

5.1 ClientPrintf

void ClientPrintf(CBasePlayer@ pPlayer, PRINT_TYPE printType, const string& in szMessage)

Prints text to the given player’s console.

See the PRINT_TYPE enum.

5.2 ServerPrint

void ServerPrint(const string& in szMessage)

Unconditionally print text to the server console.

5.3 Cmd_Args

string Cmd_Args()

Get current command arguments as a string.

5.4 Cmd_Argv

string Cmd_Argv(int iIndex)

Get current command argument by index.

5.5 Cmd_Argc

int Cmd_Argc()

Gets the number of command arguments from the command that is currently being executed.

6 Client

6.1 SetView

void SetView(const edict_t@ pEdict, const edict_t@ pViewEntity)

Set player view to a given entity. Pass pEdict as the view entity to reset it to the player’s view.

6.2 CrosshairAngle

void CrosshairAngle(const edict_t@ pEdict, float flPitch, float flYaw)

Sets the angles of the given player’s crosshairs to the given settings. Set both to 0 to disable. May not have any effect in Sven Co-op.

6.3 SetClientMaxspeed

void SetClientMaxspeed(const edict_t@ pEdict, float flNewMaxSpeed)

Set client max speed. Bounded by sv_maxspeed. Sets pEdict.vars.maxspeed, and the physics info maxspd key.

6.4 RunPlayerMove

void RunPlayerMove(edict_t@ pEdict, const Vector& in vecViewAngles, float flForwardMove, float flSideMove, float flUpMove, uint16 iButtons, uint8 iImpulse, uint8 iMsec)

Run player move. Used to move bots.

Argument Purpose
pEdict client to move. Must be a fake client.
vecViewAngles Client view angles.
flForwardMove Velocity X value.
flSideMove Velocity Y value.
flUpMove Velocity Z value.
iButtons Buttons that are currently pressed in. Equivalent to player pev.button.
iImpulse Impulse commands to execute. Equivalent to player pev.impulse.
iMsec Time between now and previous RunPlayerMove call.

6.5 GetPlayerUserId

int GetPlayerUserId(edict_t@ pEdict)

Get player user ID. This is a unique id generated when a player connects. It remains valid as long as the player stays connected to the server.

6.6 GetPlayerStats

void GetPlayerStats(const edict_t@ pEdict, int& out iPing, int& out iPacketLoss)

Get player stats.

Argument Purpose
pEdict Client to get stats from.
iPing Current ping.
iPacketLoss Current packet loss, measured in percentage.

6.7 Voice_GetClientListening

void Voice_GetClientListening(int iReceiver, int iSender)

Returns whether the given client receives voice data sent by the given sender (voice muting).

Argument Purpose
iReceiver Entity index of the receiving client.
iSender Entity index of the sending client.

Note: return type is currently incorrect.

6.8 Voice_SetClientListening

void Voice_SetClientListening(int iReceiver, int iSender, bool fListen)

Sets whether the given client receives voice data sent by the given sender (voice muting).

Note: The game will override these settings.

Argument Purpose
iReceiver Entity index of the receiving client.
iSender Entity index of the sending client.
fListen Whether or not the receiver should be able to hear the sender.

6.9 GetPlayerAuthId

string GetPlayerAuthId(edict_t@ pEdict)

Get player auth id. (WON/Steam id).

7 Misc

7.1 ParticleEffect

void ParticleEffect(const Vector& in vecOrigin, const Vector& in vecDir, float flColor, float flCount)

Emit a particle effect.

Argument Purpose
vecOrigin Origin in the world to emit the effect at.
vecDir Direction that the effect will move in.
flColor Color of the effect.
flCount Number of particles to create.

7.2 StaticDecal

void StaticDecal(const Vector& in vecOrigin, int iDecalIndex, int iEntityIndex, int iModelIndex)

Project a static decal. Only allowed while the map is loading. Only works on brush models.

Argument Purpose
vecOrigin Origin in the world to project the decal at.
iDecalIndex Index of the decal. Must be retrieved using DecalIndex.
iEntityIndex Index of the entity to project the decal onto.
iModelIndex Index of the model to project the decal onto.

7.3 DecalIndex

int DecalIndex(const string& in szName)

Get decal index.

Returns a value greater than 0 on success, 0 otherwise.

7.4 LightStyle

void LightStyle(int iStyle, const string& in szVal)

Set a light style.

Argument Purpose
iStyle Light style index. Normally, values below 32 are used for built-in styles, so avoid using them. Half-Life supports up to 64 styles (determined by reverse engineering).
szVal Light pattern. See light entity documentation for custom appearance.

7.5 PointContents

CONTENTS PointContents(const Vector& in vecPoint)

Get the Contents type for a given point.

7.6 Time

float Time()

Returns the time since the first call to Time. Used for delta operations that operate in real world time, as opposed to game world time (which will advance frame by frame, and can be paused).