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

Many, many helpful misc functions. More...

Private Member Functions

string StringReplace (string str, string original, string replacement)
 
object SearchMainTables (string idx)
 
string CombineArray (object[] args, string delimiter=" ")
 
string BuildProgressBar (int width, int count, int goal, string fill="|", string empty=".")
 
void printf (string str, params string[] values)
 
void SayToAll (string str, params string[] values)
 
void SayToTeam (Player player, string str, params string[] values)
 
void SayToAllDel (string str, params string[] values)
 
void SayToTeamDel (Player player, string str, params string[] values)
 
Entity CreateEntity (string _classname, Vector pos=Vector(0, 0, 0), QAngle ang=QAngle(0, 0, 0), object[] keyvalues=null)
 
void SpawnL4D1Survivor (int survivor=4, Vector pos=Vector(0, 0, 0), QAngle ang=QAngle(0, 0, 0))
 
void SpawnZombie (Vector pos, string zombieType="default", bool attackOnSpawn=true)
 
bool SpawnZombieNearPlayer (Player player, int zombieNum, double maxDist=128.0, double minDist=32.0, bool checkVisibility=true, bool useAltSpawn=false)
 
void SpawnCommentaryZombie (string zombieModel="common_male_tshirt_cargos", Vector pos=Vector(0, 0, 0), QAngle ang=QAngle(0, 0, 0))
 
double CalculateDistance (Vector vec1, Vector vec2)
 
double VectorDotProduct (Vector a, Vector b)
 
Vector VectorCrossProduct (Vector a, Vector b)
 
Vector VectorFromQAngle (QAngle angles, double radius=1.0)
 
double GetDistBetweenEntities (Entity ent1, Entity ent2)
 
void DrawLine (Vector pos1, Vector pos2, double time=10.0, int red=255, int green=0, int blue=0)
 
void SlowTime (double desiredTimeScale=0.2, double re_Acceleration=2.0, double minBlendRate=1.0, double blendDeltaMultiplier=2.0, bool allowResumeTime=true)
 
void ResumeTime ()
 
void PlaySoundToAll (string sound)
 
void StopSoundOnAll (string sound)
 
Player GetVictimOfAttacker (Player attacker)
 
int GetRandNumber (int min, int max)
 
void ForcePanicEvent ()
 
object[] GetTimeTable (double time)
 
void BroadcastClientCommand (string command)
 
void PrecacheModel (string mdl)
 
void PrecacheCSSWeapons ()
 
Entity SpawnDynamicProp (string mdl, Vector pos, QAngle ang=QAngle(0, 0, 0), object[] keyvalues=null)
 
Entity SpawnPhysicsProp (string mdl, Vector pos, QAngle ang=QAngle(0, 0, 0), object[] keyvalues=null)
 
Entity SpawnRagdoll (string mdl, Vector pos, QAngle ang=QAngle(0, 0, 0), object[] keyvalues=null)
 
Entity SpawnCommentaryDummy (string mdl="models/survivors/survivor_gambler.mdl", string weps="weapon_pistol", string anim="Idle_Calm_Pistol", Vector pos=Vector(0, 0, 0), QAngle ang=QAngle(0, 0, 0), object[] keyvalues=null)
 
Entity SpawnMinigun (Vector pos, QAngle ang=QAngle(0, 0, 0), object[] keyvalues=null)
 
Entity SpawnL4D1Minigun (Vector pos, QAngle ang=QAngle(0, 0, 0), object[] keyvalues=null)
 
Entity SpawnWeapon (string weaponName, int Count=4, Vector pos=Vector(0, 0, 0), QAngle ang=QAngle(0, 0, 90), object[] keyvalues=null)
 
Entity SpawnAmmo (string mdl="models/props/terror/ammo_stack.mdl", Vector pos=Vector(0, 0, 0), QAngle ang=QAngle(0, 0, 0), object[] keyvalues=null)
 
Entity SpawnFuelBarrel (Vector pos, QAngle ang=QAngle(0, 0, 0), object[] keyvalues=null)
 
Entity SpawnDoor (string mdl="models/props_downtown/door_interior_112_01.mdl", Vector pos=Vector(0, 0, 0), QAngle ang=QAngle(0, 0, 0), object[] keyvalues=null)
 
void RemoveEntity (Entity ent)
 
Vector GetNearbyLocationRadius (Player player, double minDist, double maxDist)
 
Entity SpawnInventoryItem (string itemName, string mdl, Vector pos)
 
Entity SetEntityHint (Entity entity, string hinttext, string icon="icon_info", double range=0.0, bool parentEnt=false, double duration=0.0, bool noOffScreen=1)
 
bool AreVectorsEqual (Vector vec1, Vector vec2)
 
void ShakeScreen (Vector pos=null, double _amplitude=2, double _duration=5.0, double _frequency=35, double _radius=500)
 
void FadeScreen (Player player, int red=0, int green=0, int blue=0, int alpha=255, double _duration=5.0, double _holdtime=5.0, bool modulate=false, bool fadeFrom=false)
 
bool IsValidMeleeWeapon (string classname)
 
bool IsValidFireWeapon (string weapon)
 
bool IsValidWeapon (string classname)
 
object GetRandValueFromArray (object[] arr)
 
void SanitizeHeldWeapons ()
 
void SanitizeHeldPrimary ()
 
void SanitizeHeldSecondary ()
 
void SanitizeHeldItems ()
 
void SanitizeHeldMeds ()
 
void SanitizeUnheldWeapons ()
 
void SanitizeUnheldPrimary ()
 
void SanitizeUnheldSecondary ()
 
void SanitizeUnheldItems ()
 
void SanitizeUnheldMeds ()
 
void SanitizeMiniguns ()
 
void KillZombieSpawns ()
 
void DisableCarAlarms ()
 

Detailed Description

Many, many helpful misc functions.

Member Function Documentation

bool VSLib.Utils.AreVectorsEqual ( Vector  vec1,
Vector  vec2 
)
private

Manually compares two vectors and returns true if they are equal. Fix for vector instance overloaded == not firing properly

void VSLib.Utils.BroadcastClientCommand ( string  command)
private

Broadcasts a command to all clients. Currently doesn't work for other clients, only works for the host.

string VSLib.Utils.BuildProgressBar ( int  width,
int  count,
int  goal,
string  fill = "|",
string  empty = "." 
)
private

Returns a progress bar as a string.

For example: 30% ||||||-----------—

Parameters
widthThe length (number of chars) that this progress bar should have
countThe current value
goalThe maximum value possible
fillWhat character to fill in for a completed block
emptyWhat character to fill in for an incomplete block
Returns
A formatted progress bar as string
double VSLib.Utils.CalculateDistance ( Vector  vec1,
Vector  vec2 
)
private

Calculates the distance between two vectors.

string VSLib.Utils.CombineArray ( object[]  args,
string  delimiter = " " 
)
private

Combines all elements of an array into one string

Entity VSLib.Utils.CreateEntity ( string  _classname,
Vector  pos = Vector(0, 0, 0),
QAngle  ang = QAngle(0, 0, 0),
object[]  keyvalues = null 
)
private

Spawns a new entity and returns it as VSLib::Entity.

Parameters
_classnameThe classname of the entity
posWhere to spawn it (a Vector object)
angAngles it should spawn with
keyvaluesOther keyvalues you may want it to have
Returns
A VSLib entity object
void VSLib.Utils.DisableCarAlarms ( )
private

Disables car alarms.

void VSLib.Utils.DrawLine ( Vector  pos1,
Vector  pos2,
double  time = 10.0,
int  red = 255,
int  green = 0,
int  blue = 0 
)
private

Draws a debug line from one location to another (can only be seen by host)

void VSLib.Utils.FadeScreen ( Player  player,
int  red = 0,
int  green = 0,
int  blue = 0,
int  alpha = 255,
double  _duration = 5.0,
double  _holdtime = 5.0,
bool  modulate = false,
bool  fadeFrom = false 
)
private

Fades player's screen with the specified color, alpha, etc. Returns the env_fade entity. Note that the entity is automatically killed after its use is done.

void VSLib.Utils.ForcePanicEvent ( )
private

Forces a panic event

double VSLib.Utils.GetDistBetweenEntities ( Entity  ent1,
Entity  ent2 
)
private

Calculates the distance between two entities.

Vector VSLib.Utils.GetNearbyLocationRadius ( Player  player,
double  minDist,
double  maxDist 
)
private

Returns a Vector position that is between the min and max radius, or null if not found.

int VSLib.Utils.GetRandNumber ( int  min,
int  max 
)
private

Returns a pseudorandom number from min to max

object VSLib.Utils.GetRandValueFromArray ( object[]  arr)
private

Gets a random value from an array

object [] VSLib.Utils.GetTimeTable ( double  time)
private

Returns a table with the hours, minutes, and seconds provided the total seconds (e.g. Time())

Example: local t = GetTimeTable ( Time() ); printf("Hours: %i, Minutes: %i, Seconds: %i", t.hours, t.minutes, t.seconds);

Player VSLib.Utils.GetVictimOfAttacker ( Player  attacker)
private

Returns the victim of the attacker player or null if there is no victim

bool VSLib.Utils.IsValidFireWeapon ( string  weapon)
private

Returns true if the specified classname is a valid fire weapon (does not include melee weapons).

bool VSLib.Utils.IsValidMeleeWeapon ( string  classname)
private

Returns true if the specified classname is a valid melee weapon.

bool VSLib.Utils.IsValidWeapon ( string  classname)
private

Returns true if the specified classname is a valid weapon (includes melee and fire weapons).

void VSLib.Utils.KillZombieSpawns ( )
private

Kills common spawn locations.

void VSLib.Utils.PlaySoundToAll ( string  sound)
private

Plays a sound to all clients

void VSLib.Utils.PrecacheCSSWeapons ( )
private

Precaches the CS:S weapons, making them usable

void VSLib.Utils.PrecacheModel ( string  mdl)
private

Precaches a model

void VSLib.Utils.printf ( string  str,
params string[]  values 
)
private

Add printf helper to global table. Works just like C++ printf().

Supports up to 12 inputs.

void VSLib.Utils.RemoveEntity ( Entity  ent)
private

Kills the given entity. Useful to use with timers.

void VSLib.Utils.ResumeTime ( )
private

Resumes time that is slowed by SlowTime().

See also
SlowTime
void VSLib.Utils.SanitizeHeldItems ( )
private

Removes all held items from the map.

void VSLib.Utils.SanitizeHeldMeds ( )
private

Removes all held meds from the map.

void VSLib.Utils.SanitizeHeldPrimary ( )
private

Removes all held primary weapons from the map.

void VSLib.Utils.SanitizeHeldSecondary ( )
private

Removes all held secondary weapons from the map.

void VSLib.Utils.SanitizeHeldWeapons ( )
private

Removes all held weapons from the map.

void VSLib.Utils.SanitizeMiniguns ( )
private

Removes all miniguns from the map.

void VSLib.Utils.SanitizeUnheldItems ( )
private

Removes all unheld items from the map.

void VSLib.Utils.SanitizeUnheldMeds ( )
private

Removes all unheld meds from the map.

void VSLib.Utils.SanitizeUnheldPrimary ( )
private

Removes all unheld primary weapons from the map.

void VSLib.Utils.SanitizeUnheldSecondary ( )
private

Removes all unheld secondary weapons from the map.

void VSLib.Utils.SanitizeUnheldWeapons ( )
private

Removes all unheld weapons from the map.

void VSLib.Utils.SayToAll ( string  str,
params string[]  values 
)
private

Wraps Say() to make it easier to read. This will Say to all into chatbox. Similar to C++ printf().

void VSLib.Utils.SayToAllDel ( string  str,
params string[]  values 
)
private

Says some text into chatbox after a delay. Similar to C++ printf().

void VSLib.Utils.SayToTeam ( Player  player,
string  str,
params string[]  values 
)
private

Wraps Say() to make it easier to read. This will Say to the player's current team only (incl. the player). Similar to C++ printf().

void VSLib.Utils.SayToTeamDel ( Player  player,
string  str,
params string[]  values 
)
private

Says some text into chatbox after a delay to the player's team. Similar to C++ printf().

object VSLib.Utils.SearchMainTables ( string  idx)
private

Searches in the Vars and RoundVars tables if not found in the root table.

Entity VSLib.Utils.SetEntityHint ( Entity  entity,
string  hinttext,
string  icon = "icon_info",
double  range = 0.0,
bool  parentEnt = false,
double  duration = 0.0,
bool  noOffScreen = 1 
)
private

Creates a hint on the specified entity, optionally "parenting" the hint.

Parameters
entityThe VSLib Entity or Player to set a hint to
hinttextThe hint to display
iconThe icon to show, see a list of icons here: https://developer.valvesoftware.com/wiki/Env_instructor_hint#Icons
rangeThe maximum range to display this icon. Enter 0 for infinite range
parentEntSet to true to make the hint "follow" the entity
durationHow long to show the hint. Enter 0 for infinite time.
Returns
The actual hint object's VSLib::Entity
void VSLib.Utils.ShakeScreen ( Vector  pos = null,
double  _amplitude = 2,
double  _duration = 5.0,
double  _frequency = 35,
double  _radius = 500 
)
private

Shakes the screen with the specified amplitude at the specified location. If the location specified is null, then the map is shaken globally. Returns the env_shake entity. Note that the returned entity is automatically killed after its use is done.

void VSLib.Utils.SlowTime ( double  desiredTimeScale = 0.2,
double  re_Acceleration = 2.0,
double  minBlendRate = 1.0,
double  blendDeltaMultiplier = 2.0,
bool  allowResumeTime = true 
)
private

Slows down time.

Entity VSLib.Utils.SpawnAmmo ( string  mdl = "models/props/terror/ammo_stack.mdl",
Vector  pos = Vector(0, 0, 0),
QAngle  ang = QAngle(0, 0, 0),
object[]  keyvalues = null 
)
private

Spawns an ammo pile at the specified location

Entity VSLib.Utils.SpawnCommentaryDummy ( string  mdl = "models/survivors/survivor_gambler.mdl",
string  weps = "weapon_pistol",
string  anim = "Idle_Calm_Pistol",
Vector  pos = Vector(0, 0, 0),
QAngle  ang = QAngle(0, 0, 0),
object[]  keyvalues = null 
)
private

Spawns a commentary dummy model at the specified location

void VSLib.Utils.SpawnCommentaryZombie ( string  zombieModel = "common_male_tshirt_cargos",
Vector  pos = Vector(0, 0, 0),
QAngle  ang = QAngle(0, 0, 0) 
)
private

Spawns the requested commentary zombie at the location you want.

Entity VSLib.Utils.SpawnDoor ( string  mdl = "models/props_downtown/door_interior_112_01.mdl",
Vector  pos = Vector(0, 0, 0),
QAngle  ang = QAngle(0, 0, 0),
object[]  keyvalues = null 
)
private

Spawns a door at the specified location

Entity VSLib.Utils.SpawnDynamicProp ( string  mdl,
Vector  pos,
QAngle  ang = QAngle(0, 0, 0),
object[]  keyvalues = null 
)
private

Spawns a dynamic model at the specified location

Entity VSLib.Utils.SpawnFuelBarrel ( Vector  pos,
QAngle  ang = QAngle(0, 0, 0),
object[]  keyvalues = null 
)
private

Spawns a fuel barrel at the specified location

Entity VSLib.Utils.SpawnInventoryItem ( string  itemName,
string  mdl,
Vector  pos 
)
private

Spawns an inventory item that can be picked up by players. Returns the spawned item.

See also
Player::GetInventory()
Entity VSLib.Utils.SpawnL4D1Minigun ( Vector  pos,
QAngle  ang = QAngle(0, 0, 0),
object[]  keyvalues = null 
)
private

Spawns a L4D1 minigun at the specified location

void VSLib.Utils.SpawnL4D1Survivor ( int  survivor = 4,
Vector  pos = Vector(0, 0, 0),
QAngle  ang = QAngle(0, 0, 0) 
)
private

Spawns the requested L4D1 Survivor at the location you want.

Entity VSLib.Utils.SpawnMinigun ( Vector  pos,
QAngle  ang = QAngle(0, 0, 0),
object[]  keyvalues = null 
)
private

Spawns a minigun at the specified location

Entity VSLib.Utils.SpawnPhysicsProp ( string  mdl,
Vector  pos,
QAngle  ang = QAngle(0, 0, 0),
object[]  keyvalues = null 
)
private

Spawns a physics model at the specified location

Entity VSLib.Utils.SpawnRagdoll ( string  mdl,
Vector  pos,
QAngle  ang = QAngle(0, 0, 0),
object[]  keyvalues = null 
)
private

Spawns a ragdoll model at the specified location

Entity VSLib.Utils.SpawnWeapon ( string  weaponName,
int  Count = 4,
Vector  pos = Vector(0, 0, 0),
QAngle  ang = QAngle(0, 0, 90),
object[]  keyvalues = null 
)
private

Spawns the requested weapon at the specified location

void VSLib.Utils.SpawnZombie ( Vector  pos,
string  zombieType = "default",
bool  attackOnSpawn = true 
)
private

Spawns the requested zombie via the Director at the specified location.

bool VSLib.Utils.SpawnZombieNearPlayer ( Player  player,
int  zombieNum,
double  maxDist = 128.0,
double  minDist = 32.0,
bool  checkVisibility = true,
bool  useAltSpawn = false 
)
private

Spawns the requested zombie near a player and also checks to make sure that the spawn point is not visible to any survivor. Attempts to locate a position 50 times. If it can't find a suitable spawn location, it'll return false. Keep in mind that the closer the min and max distances are to each other, the lesser the chance that a suitable spawn will be found. For a good spawn chance, keep the min and max dist far apart. If by chance the survivors are looking everywhere at once, the infected prob won't spawn!

void VSLib.Utils.StopSoundOnAll ( string  sound)
private

Stops a sound on all clients

string VSLib.Utils.StringReplace ( string  str,
string  original,
string  replacement 
)
private

Replaces parts of a string with another string. The "original" param can be anything, but internally uses RegEx.

Parameters
strThe full string
originalThe string to replace
replacementThe string to replace "original" with
Returns
The modified string
Vector VSLib.Utils.VectorCrossProduct ( Vector  a,
Vector  b 
)
private

Calculates the cross product of two vectors.

double VSLib.Utils.VectorDotProduct ( Vector  a,
Vector  b 
)
private

Calculates the dot product of two vectors.

Vector VSLib.Utils.VectorFromQAngle ( QAngle  angles,
double  radius = 1.0 
)
private

Converts QAngles into vectors, with an optional vector length.


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