-
Notifications
You must be signed in to change notification settings - Fork 4
EngineFuncs
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;
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.
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.
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.
float VecToYaw(const Vector& in vec)
Converts a vector to a yaw value.
void VecToAngles(const Vector& in vec, Vector& out angles)
Converts a vector to euler angles.
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 |
---|---|
pEntity | Entity to move. |
vecGoal | Destination origin. |
flDist | Number of units to move. |
iMoveType | Indicates how the entity should move. |
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
.
void ChangePitch(edict_t@ pEntity)
Change pitch. This updates entvars_t::angles[ 0 ]
to approach entvars_t::idealpitch
, at entvars_t::pitch_speed degrees speed. Not used by any game code. Replaced by [
CMath::ApproachAngle`](Math%23ApproachAngle#ApproachAngle).
int GetEntityIllum(edict_t@ pEntity)
Get entity illumination. This is a weighted value between 0 and 255, inclusive.
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.
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.
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.
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.
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.
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.
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.
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.
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 |
---|---|
pEntity | Entity to retrieve the aim vector for. |
flSpeed | Unused. |
vecReturn | Aim vector. |
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.
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.
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. |
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. |
int DecalIndex(const string& in szName)
Get decal index.
Returns a value greater than 0
on success, 0
otherwise.
CONTENTS PointContents(const Vector& in vecPoint)
Get the Contents type for a given point.
float CVarGetFloat(const string& in szCvar)
Get cvar float value. Returns 0
if the cvar doesn't exist.
string CVarGetString(const string& in szCvar)
Get cvar string value. Returns an empty string if the cvar doesn't exist.
void CVarSetFloat(const string& in szCvar, float flValue)
Set cvar float value.
void CVarSetString(const string& in szCvar, const string& in szValue)
Set cvar string value.
entvars_t@ GetVarsOfEnt(edict_t@ pEdict)
Gets entity variables of entity. Identical to pEdict.vars
.
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
.
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.
edict_t@ FindEntityByVars(entvars_t@ pVars)
Find entity by variables. Identical to pVars.pContainingEntity
, but also validates the pContainingEntity
field.
void AnimationAutomove(const edict_t@ pEdict, float flTime)
Animation auto move.
Note: Does nothing, remove from the API.
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. |
void ClientPrintf(CBasePlayer@ pPlayer, PRINT_TYPE printType, const string& in szMessage)
Prints text to the given player's console.
See the PRINT_TYPE
enum.
void ServerPrint(const string& in szMessage)
Unconditionally print text to the server console.
string Cmd_Args()
Get current command arguments as a string.
string Cmd_Argv(int iIndex)
Get current command argument by index.
int Cmd_Argc()
Gets the number of command arguments from the command that is currently being executed.
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. |
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.
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).
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.
string GetGameDir()
Get game directory. This is svencoop
for Sven Co-op, or the mod directory if run under any other mod.
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.
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. |
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.
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
.
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
.
bool IsMapValid(const string& in szMapName) const
Returns whether the given map is valid. A map is considered valid if the BSP exists.
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. |
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.
bool IsDedicatedServer() const
Returns whether this is a dedicated server (true
) or a listen server (false
).
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
.
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. |
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.
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. |
string GetPlayerAuthId(edict_t@ pEdict)
Get player auth id. (WON/Steam id).