VSLib
Simple, powerful VScript Library for L4D2
 All Classes Namespaces Files Functions Pages
VSLib.Entity Class Reference

Provides many helpful entity functions. More...

Inheritance diagram for VSLib.Entity:
VSLib.Player

Private Member Functions

bool IsEntityValid ()
 
int GetHealth ()
 
int GetRawHealth ()
 
void Hurt (int value, int dmgtype=0, string weapon="", Entity attacker=null, double radius=64.0)
 
void HurtAround (int value, int dmgtype=0, string weapon="", Entity attacker=null, double radius=64.0, object[] ignoreEntities=null)
 
void Input (string input, string value="", double delay=0, Entity activator=null)
 
void Break ()
 
void SetKeyValue (string key, object value)
 
void HurtTime (int value, int dmgtype, double interval, double time, string weapon="", Entity attacker=null, double radius=64.0)
 
void SetRawHealth (int value)
 
void SetHealth (int value)
 
void SetMaxHealth (int value)
 
void Vomit ()
 
string GetClassname ()
 
void SetGlobalName (string name)
 
void SetParentName (string name)
 
void SetSpeed (double value)
 
void SetRenderEffects (int value)
 
void SetRenderMode (int value)
 
void SetNextThinkTime (double value)
 
void SetEffects (int value)
 
void SetColor (int red, int green, int blue, int alpha)
 
void SetVisible (bool canSee)
 
void SetModelIndex (int value)
 
void SetResponseContext (object value)
 
void SetTarget (string value)
 
void SetDamageFilter (object value)
 
void SetShadowCastDistance (double value)
 
void Push (Vector vec)
 
void Spin (Vector vec)
 
void SetGravity (double value)
 
void SetFriction (double value)
 
Vector GetVelocity ()
 
void SetVelocity (Vector vec)
 
void SetVelocityKV (object vec)
 
void SetBaseVelocity (object vec)
 
void SetAngularVelocity (object vec)
 
void SetWaterLevel (int lvl)
 
void SetSpawnFlags (int flags)
 
QAngle GetEyeAngles ()
 
object GetBaseEntity ()
 
int GetIndex ()
 
Vector GetLocation ()
 
void SetLocation (vec)
 
void SetPosition (double x, double y, double z)
 
Vector GetPosition ()
 
void Teleport (Vector vec)
 
void TeleportTo (Entity otherEntity)
 
int GetTeam ()
 
void Kill ()
 
QAngle GetAngles ()
 
void SetAngles (double x, double y, double z)
 
void KillHierarchy ()
 
void Use (Entity otherEntity)
 
void UseOther (Entity otherEntity)
 
void UsedByOther (Entity otherEntity)
 
void SetAlpha (int value)
 
void InputColor (int red, int green, int blue)
 
void AttachOther (Entity otherEntity, bool teleportOther)
 
void SetAttachmentPoint (Entity otherEntity, string attachment, bool bShouldMaintainOffset)
 
void RemoveAttached (Entity otherEntity)
 
Vector GetEyePosition ()
 
Entity GetLookingEntity ()
 
int GetBaseIndex ()
 
void KillDelayed (double seconds)
 
Vector GetLookingLocation ()
 
void Ignite (double time)
 
Entity AttachParticle (string particleName, double duration)
 
bool IsPlayer ()
 
bool IsAlive ()
 
string GetName ()
 
double GetDistanceToGround ()
 
bool IsEntityInAir ()
 
int GetPressedButtons ()
 
bool IsPressingButton (int btn)
 
bool IsPressingAttack ()
 
bool IsPressingJump ()
 
bool IsPressingDuck ()
 
bool IsPressingForward ()
 
bool IsPressingBackward ()
 
bool IsPressingUse ()
 
bool IsPressingLeft ()
 
bool IsPressingRight ()
 
bool IsPressingShove ()
 
bool IsPressingReload ()
 
bool IsPressingWalk ()
 
bool IsPressingZoom ()
 
Entity GetOwnerEntity ()
 
void BotMoveToLocation (Vector newpos)
 
void BotMoveToOther (Entity otherEntity)
 
void BotMoveOtherToThis (Entity otherEntity)
 
void BotAttack (Entity otherEntity)
 
void BotRetreatFrom (Entity otherEntity)
 
void BotReset ()
 
bool IsBot ()
 
void SetSenseFlags (int flags)
 
void ChangeBotEyes (bool hasEyes)
 
int GetSenseFlags ()
 
bool IsHuman ()
 
void AddThinkFunction (function func)
 
object GetScriptScope ()
 
void ConnectOutput (string output, function func)
 
void SetEntityRenderAmt (int value)
 
bool CanTraceToOtherEntity (Entity otherEntity, double height=5.0)
 

Detailed Description

Provides many helpful entity functions.

The Entity class wraps many Valve functions as well as provide numerous helper functions that aid in the development of maps, mods, and mutations.

Member Function Documentation

void VSLib.Entity.AddThinkFunction ( function  func)
private

Adds to the entity's THINK function. You can use "this.ent" when you need to use the VSLib::Entity.

Parameters
funcA function to add to the think timer.
void VSLib.Entity.AttachOther ( Entity  otherEntity,
bool  teleportOther 
)
private

Parents an entity to this entity. In other words, attaches an entity to this entity. Cool for attaching bumper cars or other objects to players. If teleportOther is TRUE, the other entity is teleported to this entity. If it is FALSE, the entity is parented without teleporting.

Entity VSLib.Entity.AttachParticle ( string  particleName,
double  duration 
)
private

Attaches a particle to this entity. E.g. "gas_fireball" or "elevatorsparks". Internally spawns an info_particle_system, so all effects that can be shown with that entity can be shown with this function. This function will return the particle system that was created, so if you need to attach it to a specific attachment point or whatever, you can.

void VSLib.Entity.BotAttack ( Entity  otherEntity)
private

Commands this Entity to attack a particular entity (only applies to bots).

void VSLib.Entity.BotMoveOtherToThis ( Entity  otherEntity)
private

Commands the other bot entity to move to this entity's location (only applies to bots).

void VSLib.Entity.BotMoveToLocation ( Vector  newpos)
private

Commands this Entity to move to a particular location (only applies to bots).

void VSLib.Entity.BotMoveToOther ( Entity  otherEntity)
private

Commands this Entity to move to another entity's location (only applies to bots).

void VSLib.Entity.BotReset ( )
private

Returns the bot to normal after it is commanded.

void VSLib.Entity.BotRetreatFrom ( Entity  otherEntity)
private

Commands this Entity to retreat from a particular entity (only applies to bots).

void VSLib.Entity.Break ( )
private

Breaks the entity (if it is breakable)

bool VSLib.Entity.CanTraceToOtherEntity ( Entity  otherEntity,
double  height = 5.0 
)
private

Returns true if this entity can trace to another entity without hitting anything. I.e. if a line can be drawn from this entity to the other entity without any collision.

void VSLib.Entity.ChangeBotEyes ( bool  hasEyes)
private

Sets if the target can see.

void VSLib.Entity.ConnectOutput ( string  output,
function  func 
)
private

Connects an output to a function

Parameters
outputThe output name (string)
funcFunction to fire (pass in a function, not a string name)
QAngle VSLib.Entity.GetAngles ( )
private

Returns the base angles.

object VSLib.Entity.GetBaseEntity ( )
private

Returns the base entity (in case you need to access Valve's CBaseEntity/CBaseAnimating functions manually)

int VSLib.Entity.GetBaseIndex ( )
private

Returns the numerical index of the entity. Because Valve didn't provide a function to convert a base entity back to an index, we go the long way around by using an entity loop.

string VSLib.Entity.GetClassname ( )
private

Gets the entity's classname. If the entity is valid, the entity's class is returned; otherwise, null is returned. For example, "prop_dynamic" or "weapon_rifle_ak47"

double VSLib.Entity.GetDistanceToGround ( )
private

Returns the distance (in units) to the ground from the entity's origin.

QAngle VSLib.Entity.GetEyeAngles ( )
private

Gets the direction that the entity's eyes are facing.

Vector VSLib.Entity.GetEyePosition ( )
private

Estimates the eye position.

int VSLib.Entity.GetHealth ( )
private

Gets the entity's real health. If the entity is valid, the entity's health is returned; otherwise, null is returned. The health includes any adrenaline or pill health.

int VSLib.Entity.GetIndex ( )
private

Returns the initial index or name passed to the entity.

Vector VSLib.Entity.GetLocation ( )
private

Gets the entity's current location.

Entity VSLib.Entity.GetLookingEntity ( )
private

Gets the entity that this entity is pointing at, or null if this entity is not pointing at a valid entity. This is useful for things like detecting what entity a player may be looking at.

Vector VSLib.Entity.GetLookingLocation ( )
private

Returns a vector position of where the entity is looking.

string VSLib.Entity.GetName ( )
private

Returns the name of the entity.

Entity VSLib.Entity.GetOwnerEntity ( )
private

Returns the entity's owner, or null if the owner does not exist

Vector VSLib.Entity.GetPosition ( )
private

Gets the entity's current position (basically calls GetLocation() internally).

int VSLib.Entity.GetPressedButtons ( )
private

Returns the entity's button mask

int VSLib.Entity.GetRawHealth ( )
private

Gets the entity's raw health. If the entity is valid, the entity's health is returned; otherwise, null is returned. Raw health does not include temporary health.

object VSLib.Entity.GetScriptScope ( )
private

Returns the entity's script scope.

int VSLib.Entity.GetSenseFlags ( )
private

Gets the sense flags for this player.

int VSLib.Entity.GetTeam ( )
private

Tries to guess what team the player might be on. Returns either INFECTED or SURVIVORS.

Vector VSLib.Entity.GetVelocity ( )
private

Returns the entity's current velocity vector.

void VSLib.Entity.Hurt ( int  value,
int  dmgtype = 0,
string  weapon = "",
Entity  attacker = null,
double  radius = 64.0 
)
private

Hurts the entity.

Parameters
valueAmount of damage to inflict.
dmgtypeThe type of damage to inflict (e.g. DMG_GENERIC)
weaponThe classname of the weapon (if set, the point hurt will "pretend" to be the weapon)
attackerIf set, the damage will be done by the specified VSLib::Entity or VSLib::Player
radiusThe radius of damage
void VSLib.Entity.HurtAround ( int  value,
int  dmgtype = 0,
string  weapon = "",
Entity  attacker = null,
double  radius = 64.0,
object[]  ignoreEntities = null 
)
private

Hurts AROUND the entity without hurting the entity itself.

Parameters
valueAmount of damage to inflict.
dmgtypeThe type of damage to inflict (e.g. DMG_GENERIC)
weaponThe classname of the weapon (if set, the point hurt will "pretend" to be the weapon)
attackerIf set, the damage will be done by the specified VSLib::Entity or VSLib::Player
radiusThe radius of damage
ignoreEntitiesAn array of Entities to not damage
void VSLib.Entity.HurtTime ( int  value,
int  dmgtype,
double  interval,
double  time,
string  weapon = "",
Entity  attacker = null,
double  radius = 64.0 
)
private

Same as Hurt(), except it keeps hurting for the specified time. It hurts at the specified interval for the specified time.

void VSLib.Entity.Ignite ( double  time)
private

Ingites the entity for the specified time. Fractions can be used (e.g. 1.5 seconds).

void VSLib.Entity.Input ( string  input,
string  value = "",
double  delay = 0,
Entity  activator = null 
)
private

Fires a specific input

void VSLib.Entity.InputColor ( int  red,
int  green,
int  blue 
)
private

Inputs a color to an entity. This is an alternative to SetColor().

bool VSLib.Entity.IsAlive ( )
private

Returns true if the entity is alive. For players, once a player dies, it still reports alive. Use Player class for IsAlive().

To convert an Entity into a player, for example: local ent = Entity(...stuff here...); if (ent.IsPlayer()) local player = Player(ent); // do stuff with it

bool VSLib.Entity.IsBot ( )
private

Returns true if the entity is a bot.

bool VSLib.Entity.IsEntityInAir ( )
private

Returns true if the entity is in the air.

bool VSLib.Entity.IsEntityValid ( )
private

Returns true if the entity is valid or false otherwise. Sometimes, just because an entity or edict exists doesn't mean that it hasn't freed up or become invalidated. Luckily, you will rarely use this function since VSLib uses it automatically.

bool VSLib.Entity.IsHuman ( )
private

Returns true if the entity is a real human (non-bot).

bool VSLib.Entity.IsPlayer ( )
private

Returns true if the entity is a player.

bool VSLib.Entity.IsPressingAttack ( )
private

Returns true if this player is currently firing a weapon (either a gun, bat, etc). Note that it doesn't check if the gun has any ammo (just checks for key press).

bool VSLib.Entity.IsPressingBackward ( )
private

Returns true if this player is pressing backward (or pressing the S key for example).

bool VSLib.Entity.IsPressingButton ( int  btn)
private

Returns if the client is pressing the specified button. For a list of buttons, see the VSLib/Entity.nut file.

bool VSLib.Entity.IsPressingDuck ( )
private

Returns true if this player is ducking (or pressing the CTRL key for example).

bool VSLib.Entity.IsPressingForward ( )
private

Returns true if this player is pressing forward (or pressing the W key for example).

bool VSLib.Entity.IsPressingJump ( )
private

Returns true if this player is jumping (or pressing the space bar button for example).

bool VSLib.Entity.IsPressingLeft ( )
private

Returns true if this player is pressing the Left key (or pressing the A key for example).

bool VSLib.Entity.IsPressingReload ( )
private

Returns true if this player is pressing the reload key (or pressing the R key for example).

bool VSLib.Entity.IsPressingRight ( )
private

Returns true if this player is pressing the Right key (or pressing the D key for example).

bool VSLib.Entity.IsPressingShove ( )
private

Returns true if this player is pressing the shove key (or pressing right-click for example).

bool VSLib.Entity.IsPressingUse ( )
private

Returns true if this player is pressing the USE key (or pressing the E key for example).

bool VSLib.Entity.IsPressingWalk ( )
private

Returns true if this player is pressing the walk key (or pressing the shift key for example).

bool VSLib.Entity.IsPressingZoom ( )
private

Returns true if this player is pressing the zoom key.

void VSLib.Entity.Kill ( )
private

Kills/removes the entity from the map.

void VSLib.Entity.KillDelayed ( double  seconds)
private

Kills the entity after the specified delay in seconds; fractions may be used if needed (e.g. 1.5 seconds).

void VSLib.Entity.KillHierarchy ( )
private

Kills/removes the entity and associated/attached entities from the map.

void VSLib.Entity.Push ( Vector  vec)
private

Applies an absolute velocity impulse to an entity. An impulse is given to the entity. In this function, by setting a value negative to an entity's trajectory, the entity may or may not change paths depending on the scalar value of the vector. All we are doing is "pushing" an entity in the given direction. The higher the dimensional value, the stronger the "push" (to put it very simply). There are a lot of uses for this function.

void VSLib.Entity.RemoveAttached ( Entity  otherEntity)
private

Remove the parenting.

void VSLib.Entity.SetAlpha ( int  value)
private

Set the alpha value of the entity. Only seems to work for players.

void VSLib.Entity.SetAngles ( double  x,
double  y,
double  z 
)
private

Sets the base angles.

void VSLib.Entity.SetAngularVelocity ( object  vec)
private

Sets the entity's current angular velocity vector KV.

void VSLib.Entity.SetAttachmentPoint ( Entity  otherEntity,
string  attachment,
bool  bShouldMaintainOffset 
)
private

Attaches another entity to a specific point. Call this function after AttachOther() to parent at a specific attachment point. For example, if attachment equals "rhand", the object will be attached to the player's or entity's right hand. "forward" to attach to head etc. Search for player or entity attachment points on Google (i.e. "L4D2 survivor attachment points" or something along those lines). If ShouldMaintainOffset is true, then the initial distance between the object is maintained, and the angles usually point in the direction of the parent.

void VSLib.Entity.SetBaseVelocity ( object  vec)
private

Sets the entity's current base velocity vector KV.

void VSLib.Entity.SetColor ( int  red,
int  green,
int  blue,
int  alpha 
)
private

Sets the entity's render color. Changes the overall color of the entity. For example, a value of (255, 0, 0, 255) will give the entity a red hue. The alpha property really doesn't affect much unless the render mode also changes. If you are looking to change the visibility, use Entity.SetVisible() instead.

void VSLib.Entity.SetDamageFilter ( object  value)
private

Sets the damage filter name of the entity. Provided for completeness. This function sets the m_iszDamageFilterName KV, which is later used in InputSetDamageFilter() in the c++ backend to find the name stored in m_iszDamageFilterName to set m_hDamageFilter, which is later used in PassesDamageFilter() to see if the CTakeDamageInfo object passes the damage filter. In simple terms, this function is as good as useless for us.

void VSLib.Entity.SetEffects ( int  value)
private

Sets the entity's secondary effects. Depending on the value, effects like light projection (i.e. flashlight) can be enabled and disabled (for player entities). See Player class for a function already made for that purpose.

void VSLib.Entity.SetEntityRenderAmt ( int  value)
private

Sets the entity's alpha

Parameters
valueAn integer value between 0 and 255
void VSLib.Entity.SetFriction ( double  value)
private

Sets the entity's friction.

void VSLib.Entity.SetGlobalName ( string  name)
private

Sets the entity's global name. If the entity is valid, the global name of the entity is set. The global name of the entity corresponds to the "Global Name" field of the entity in the Property Window in Hammer. Global entities may carry over onto future maps in a campaign, so setting an entity's global name may be helpful in certain situations.

void VSLib.Entity.SetGravity ( double  value)
private

Sets the entity's gravity.

void VSLib.Entity.SetHealth ( int  value)
private

Sets the entity's health. If the entity is valid, the entity's health is set. This will also incapacitate the player if the input value is less than or equal to 0.

void VSLib.Entity.SetKeyValue ( string  key,
object  value 
)
private

Dispatches a keyvalue to the entity

void VSLib.Entity.SetLocation ( vec  )
private

Sets the entity's current location vector (i.e. teleports the entity).

void VSLib.Entity.SetMaxHealth ( int  value)
private

Sets the entity's maximum possible health without modifying the entity's current health. If the entity is valid, the entity's max health is set.

void VSLib.Entity.SetModelIndex ( int  value)
private

Sets the entity's model index. If the entity has more than one model associated with it (i.e. it has more than one model index), then you can instantly change the model index with this function. This function is useful for those who would like to have an entity have more than one model.

void VSLib.Entity.SetNextThinkTime ( double  value)
private

Sets the entity's next Think time. To be totally honest, I can't think of a reason for this function. Provided just for those who may need it.

void VSLib.Entity.SetParentName ( string  name)
private

Sets the entity's parent name. If the entity is valid, the name of the entity is set. Note that this function does NOT parent an entity; only the parent's targetname is set. This is equivalent to setting the "Parent" field in Hammer.

void VSLib.Entity.SetPosition ( double  x,
double  y,
double  z 
)
private

Sets the entity's current position (basically calls SetLocation() internally).

void VSLib.Entity.SetRawHealth ( int  value)
private

Sets the entity's raw health. If the entity is valid, the entity's health is set. Setting raw health removes any existing temp health.

void VSLib.Entity.SetRenderEffects ( int  value)
private

Sets the entity's render effect. The entity can be given a special effect (like fading, pulsing, etc). If the entity is valid, the render effect is set. Here are the possible values: 0 -> No effect 1 -> Slow pulse 2 -> Fast pulse 3 -> Slow, wide pulse 4 -> Fast, wide pulse 5 -> Slow fade 6 -> Fast fade 7 -> Slow solidify (no you can't make ice) 8 -> Fast solidify 9 -> Slow strobe 10 -> Fast strobe 11 -> Strobe even faster 12 -> Slow flicker 13 -> Fast flicker 14 -> No dissipation 15 -> Distort entity 16 -> Hologram effect 17 -> Super scale; become huge 18 -> Glowing shell 19 -> Clamp sprite (prevents sprites from getting smaller when increasing disatance) 20 -> Rain effect (for environments) 21 -> Snow effect (for environments again) 22 -> Valve's experimental spotlight effect 23 -> Ragdoll effect 24 -> Pulse faster and wider (dunno why Valve put the value all the way down here)

void VSLib.Entity.SetRenderMode ( int  value)
private

Sets the entity's render mode. The render mode allows you to change how an entity should render. With specific values, you can make entities invisible, change the object's buffer checks, blending, and more. Here are the possible values: 0 -> Normal (no render mode modification) 1 -> Transcolor 2 -> Transtexture 3 -> Glow 4 -> Transalpha 5 -> Transadd 6 -> Environmental 7 -> Transadd Frame Blend 8 -> Transalpha add 9 -> World glow 10 -> Rend None

void VSLib.Entity.SetResponseContext ( object  value)
private

Sets the entity's response context. This function deals more with AI criteria sets and dispatching responses. Practically useless for what we do, since the entity would need to be re-activated and there's no plausible way to do that via VScripts. If your mod needs to deal with m_iszResponseContext, use another scripting engine like SourceMod.

void VSLib.Entity.SetSenseFlags ( int  flags)
private

Sets the sense flags for this player.

void VSLib.Entity.SetShadowCastDistance ( double  value)
private

Sets the shadow cast distance. I honestly cannot think of any good use for this, unless you want to change the shadow distance over time or something. Granted, it may not even work. Provided for completeness.

void VSLib.Entity.SetSpawnFlags ( int  flags)
private

Sets the entity's spawn flags.

void VSLib.Entity.SetSpeed ( double  value)
private

Sets the entity's speed. If the entity is valid, the speed of the entity is set. The speed cannot be set for player entities.

void VSLib.Entity.SetTarget ( string  value)
private

Sets the m_target netprop of the entity. Provided for completeness, but the function doesn't seem to do much on L4D2. The prop has taken a back seat to m_iName from the looks of it.

void VSLib.Entity.SetVelocity ( Vector  vec)
private

Sets the entity's current velocity vector. This can be used to force an entity to move in a particular direction.

void VSLib.Entity.SetVelocityKV ( object  vec)
private

Sets the entity's current velocity vector KV.

void VSLib.Entity.SetVisible ( bool  canSee)
private

Changes the entity's visibility. If the visible parameter is true, the entity will become visible to all players. If the visible paramater is false, the entity will become invisible to all players.

void VSLib.Entity.SetWaterLevel ( int  lvl)
private

Sets the entity's current water level.

void VSLib.Entity.Spin ( Vector  vec)
private

Applies an angular velocity impulse to an entity. Using this function, we can make physics props spin around or rotate.

void VSLib.Entity.Teleport ( Vector  vec)
private

Does the same thing as SetLocation() in that it teleports the entity. Internally the function just calls SetLocation(). Provided for simplicity, as a lot of mappers seem to have difficulty understanding various terms.

void VSLib.Entity.TeleportTo ( Entity  otherEntity)
private

Teleports the entity to another VSLib.Entity.

void VSLib.Entity.Use ( Entity  otherEntity)
private

Attempts to "Use" or pick up another entity.

void VSLib.Entity.UsedByOther ( Entity  otherEntity)
private

Attempts to be "used" or picked up BY another entity.

void VSLib.Entity.UseOther ( Entity  otherEntity)
private

Attempts to "Use" or pick up another entity.

void VSLib.Entity.Vomit ( )
private

Vomits on the Entity


The documentation for this class was generated from the following file: