List of Contagion Script Functions

From Valve Developer Community
Jump to: navigation, search

Squirrel This list contains engine-related Squirrel variables, functions, and constants available for Contagion Contagion VScripts. These are mostly copied over from the L4D2 list, as well as data-mined. The VICE encryption key for the official scripts is: 5!rrFz6p


Variables

Instance Type Description
Entities CEntities Provides access to currently spawned entities.
NetProps CNetPropManager Allows reading and updating the network properties of an entity.
ThePresident CPresident Provides a interface to the President.


Constants

Instance Type Description
_charsize_ integer
_floatsize_ integer
_intsize_ integer
_version_ string The version of squirrel.
RAND_MAX integer
PI float


Classes

CBaseEntity

This is a script handle class for entities. All (server side) entities spawned have a script handle using this.

All script handles in-game are accessible from Entities. Entity Scripts can use self to access their own script handle.

Methods

Function Signature Description
__KeyValueFromInt void __KeyValueFromInt(string key,int value) Sets a keyvalue from an integer, the keys available for all __KeyValue are from the DEFINE_KEYFIELD in baseentity.cpp (classname,rendermode, renderfx, etc.).
__KeyValueFromString void __KeyValueFromString(string key,string value) Sets a keyvalue from a string, the keys available for all __KeyValue are from the DEFINE_KEYFIELD in baseentity.cpp (classname,rendermode, renderfx, etc.).
__KeyValueFromVector void __KeyValueFromVector(string key,Vector value) Sets a keyvalue from a vector, the keys available for all __KeyValue are from the DEFINE_KEYFIELD in baseentity.cpp (classname,rendermode, renderfx, etc.).
ConnectOutput void ConnectOutput(string output, string function) Adds an I/O connection that will call the named function when the specified output fires.
DisconnectOutput void DisconnectOutput(string output, string function) Removes a connected script function from an I/O event.
FirstMoveChild handle FirstMoveChild()
GetClassname string GetClassname() Returns the entity class. This includes player.
GetForwardVector Vector GetForwardVector() Get the forward vector of the entity.
GetHealth int GetHealth() Returns the current health of the entity (does not include survivor temporary health).
GetMoveParent handle GetMoveParent() If in hierarchy, retrieves the entity's parent
GetName string GetName() Returns the targetname of the entity.
GetOrigin Vector GetOrigin() Returns the origin of the entity in the world.
GetRootMoveParent handle GetRootMoveParent() If in hierarchy, walks up the hierarchy to find the root parent.
GetScriptId string GetScriptId() Retrieve the unique identifier used to refer to the entity within the scripting system.
GetScriptScope handle GetScriptScope() Retrieve the table storing the Entity Script associated with this entity.
GetVelocity Vector GetVelocity() Returns a local velocity Vector.
IsValid bool IsValid() Whether the handle belongs to a valid entity.
NextMovePeer handle NextMovePeer()
SetForwardVector void SetForwardVector(Vector direction) Set the orientation of the entity to have this forward vector.
SetHealth void SetHealth(int health) Changes the health value of the entity. Does not check whether to kill players.
SetOrigin void SetOrigin(Vector position) Sets the world entity position.
SetVelocity void SetVelocity(Vector velocity) Sets the entity velocity.
ValidateScriptScope bool ValidateScriptScope() Ensure that an entity's script scope has been created.

Hooks

If one of these functions are declared in an Entity Script, the entity will run this function automatically in the appropriate situation. This could be used to have an entity register itself with a master script or just do whatever needed to be down immediately after spawn.

Function Signature Description
Precache void Precache() Runs after the script executes.

CCallChainer

[Todo]

Methods

Function Signature Description
constructor [Todo] constructor()
PostScriptExecute [Todo] PostScriptExecute()
Call [Todo] Call()

Members

Instance Type Description
chains null
prefix null
scope null


CSimpleCallChainer

Seems to have the same members as CCallChainer. [Todo]


CEntities

Game Instance: Entities

An interface to find and iterate over the script handles for the entities in play.

To iterate over a set of entities, pass null to the previous argument in the appropriate method to start an iteration, or reference to a previously found entity to continue a search.

Methods

Function Signature Description
FindByClassname handle FindByClassname(handle previous, string class) Find entities by class name.
FindByClassnameNearest handle FindByClassnameNearest(string class, Vector origin, float radius) Find the entity with the given class name nearest to the specified point.
FindByClassnameWithin handle FindByClassnameWithin(handle previous, string class, Vector origin, float radius) Find entities by class name within a radius.
FindByModel handle FindByModel(handle previous, string filename) Find entities by model name.
FindByName handle FindByName(handle previous, string name) Find entities by name.
FindByNameNearest handle FindByNameNearest(string name, Vector origin, float radius) Find entities by name nearest to a point.
FindByNameWithin handle FindByNameWithin(handle previous, string name, Vector origin, float radius) Find entities by name within a radius.
FindByTarget handle FindByTarget(handle previous, string targetname) Find entities by its target.
FindInSphere handle FindInSphere(handle previous, Vector origin, float radius) Find entities within a radius.
First handle First() Begin an iteration over the list of entities.
Next handle Next(handle previous) Continue an iteration over the list of entities, providing reference to a previously found entity.
IsValid bool IsValid() Whether the handle belongs to a valid entity.


CPresident

Game Instance: ThePresident

Provides methods for controlling the President.

Methods

Function Signature Description
CleanupNonVisibleZombies Cleanup all zombies that a are not visible and have no enemy.
CreateAmmo void CreateAmmo(string entity, int amount) Spawns the specified ammunition pickups on random info_random_ammo entities.
CreateAmmoGroup Spawn a specific number of types of ammo to a group
CreateItem void CreateItem(string entity, int amount) Spawns the specified item pickups on random info_random_item entities.
CreateItemGroup Spawn a specific number of objective items to a group.
CreateWeapon void CreateWeapon(string entity, int amount) Spawns the specified weapon pickups on random info_random_weapon entities.
CreateWeaponGroup Spawn a specific number of weapons to a group.
CreateZombies void CreateZombies(int amount) Spawn a number of zombies in enabled spawns.
CreateZombiesArea void CreateZombiesArea(int amount, string entityName) Forcefully spawn a number of zombies in a specifically named trigger_zombie_spawn.
CreateZombiesConstant void CreateZombiesConstant(int amount) Spawns this many zombies at random locations, and spawns in new ones as they get killed.
CreateZombiesForced Forcefully spawn a number of zombies. Ignore survivors etc.
IsValid bool IsValid() Whether the handle belongs to a valid entity.
SendObjective void SendObjective(string text) Send a message to the players cell phones.
SendObjectiveWithTarget void SendObjectiveWithTarget(string text, int X, int Y, int Z) Send an objective message to all survivors with a target of (X, Y, Z).
SetHordeAttack Force a horde of zombies in a radius to run at the co-ords.
SetMusicIntensity void SetMusicIntensity(string) Set the music intensity for all players in the server.
SetRiotPoliceMinMax void SetRiotPoliceMinMax(int min, int max) A riot police will spawn every X zombies between min and max.
SetSurvivorJoinTime void SetSurvivorJoinTime(int time) Set the time until survivors are forced to join as zombies.
SetSpawnDelay Set the spawn delay for the zombies. -1 to clear the timer.
SetSpawnWeapon void SetSpawnWeapon(int slot, string weapon, int minAmmo, int maxAmmo) Overrides the default weapons players spawn with. If the function is run multiple times with the same slot number, one of the entered weapons is selected at random. Ammo is randomly selected between min and max.

CNetPropManager

Game Instance: NetProps

Allows reading and updating the network properties of an entity.

If the entity has multiple netprops with the same name, the data table name can be prepended with a dot to specify which one to use (e.g. "m_itTimer.m_timestamp").

Warning.pngWarning:Each netprop has a set size in bits, exceeding the size may desync the clients from the server causing unpredictable behavior.

Methods

Function Signature Description
GetPropArraySize int GetPropArraySize(CBaseEntity entity, string propertyName) Returns the size of an netprop array, or -1.
GetPropEntity CBaseEntity GetPropEntity(CBaseEntity entity, string propertyName) Reads an EHANDLE valued netprop (21 bit integer). Returns the script handle of the entity.
GetPropEntityArray CBaseEntity GetPropEntityArray(CBaseEntity entity, string propertyName, int arrayElement) Reads an EHANDLE valued netprop (21 bit integer) from an array. Returns the script handle of the entity.
GetPropFloat float GetPropFloat(CBaseEntity entity, string propertyName) Reads a float valued netprop.
GetPropFloatArray float GetPropFloatArray(CBaseEntity entity, string propertyName, int arrayElement) Reads a float valued netprop from an array.
GetPropInt int GetPropInt(CBaseEntity entity, string propertyName) Reads an integer valued netprop.
GetPropIntArray int GetPropIntArray(CBaseEntity entity, string propertyName, int arrayElement) Reads an integer valued netprop from an array.
GetPropString string GetPropString(CBaseEntity entity, string propertyName) Reads an string valued netprop.
GetPropStringArray string GetPropStringArray(CBaseEntity entity, string propertyName, int arrayElement) Reads an string valued netprop from an array.
GetPropType string GetPropType(CBaseEntity entity, string propertyName) Returns the name of the netprop type as a string.
GetPropVector Vector GetPropVector(CBaseEntity entity, string propertyName) Reads a 3D vector valued netprop.
Todo:  Does it work for other dimensions too?
GetPropVectorArray Vector GetPropVectorArray(CBaseEntity entity, string propertyName, int arrayElement) Reads a 3D vector valued netprop from an array.
HasProp bool HasProp(CBaseEntity entity, string propertyName) Checks if a netprop exists.
SetPropEntity void SetPropEntity(CBaseEntity entity, string propertyName, CBaseEntity value) Sets an EHANDLE valued netprop (21 bit integer) to reference the specified entity.
SetPropEntityArray void SetPropEntityArray(CBaseEntity entity, string propertyName, CBaseEntity value, int arrayElement) Sets an EHANDLE valued netprop (21 bit integer) from an array to reference the specified entity.
SetPropFloat void SetPropFloat(CBaseEntity entity, string propertyName, float value) Sets a netprop to the specified float.
SetPropFloatArray void SetPropFloatArray(CBaseEntity entity, string propertyName, float value, int arrayElement) Sets a netprop from an array to the specified float.
SetPropInt void SetPropInt(CBaseEntity entity, string propertyName, int value) Sets a netprop to the specified integer.
SetPropIntArray void SetPropInt(CBaseEntity entity, string propertyName, int value, int arrayElement) Sets a netprop from an array to the specified integer.
SetPropString void SetPropString(CBaseEntity entity, string propertyName, string value) Sets a netprop to the specified string.
SetPropStringArray void SetPropStringArray(CBaseEntity entity, string propertyName, string value, int arrayElement) Sets a netprop from an array to the specified string.
SetPropVector void SetPropVector(CBaseEntity entity, string propertyName, Vector value) Sets a netprop to the specified vector.
SetPropVectorArray void SetPropVectorArray(CBaseEntity entity, string propertyName, Vector value, int arrayElement) Sets a netprop from an array to the specified vector.

regexp

The built-in Squirrel class for regular expressions.

Methods

Function Signature Description
constructor regexp()
capture [table] capture(str, [start]) Returns an array of tables containing two indexes("begin" and "end")of the first match of the regular expression in the string str. An array entry is created for each captured sub expressions. If no match occurs returns null. The search starts from the index start of the string, if start is omitted the search starts from the beginning of the string.
match bool match(str) Returns a true if the regular expression matches the string str, otherwise returns false.
search table search(str, [start]) Returns a table containing two indexes("begin" and "end") of the first match of the regular expression in the string str, otherwise if no match occurs returns null. The search starts from the index start of the string, if start is omitted the search starts from the beginning of the string.
subexpcount


Vector

Squirrel equivalent of the C++ Vector class.

Three-dimensional vector.

Has overloaded arithmetic operations with both Vectors and scalar values.

Note.pngNote:Example declaration and manipulation of Vector

Methods

Function Signature Description
constructor Vector(float x, float y, float z) Creates a new vector with the specified Cartesian coordinates.
Cross float Cross(Vector factor) The vector product of two vectors. Returns a vector orthogonal to the input vectors.
Dot float Dot(Vector factor) The scalar product of two vectors.
Length float Length() Magnitude of the vector.
LengthSqr float LengthSqr() The magnitude of the vector squared. Faster than the above method.
Length2D float Length2D() Returns the magnitude of the vector on the x-y plane.
Length2DSqr float Length2DSqr() Returns the square of the magnitude of the vector on the x-y plane. Faster than the above method.
Norm float Norm() Seems to also return the vector length.
ToKVString string ToKVString() Returns a string without separations commas.

Global Functions

Contagion Specific

Function Signature Description
GetDifficulty int GetDifficulty() Returns the current difficulty level as an integer from 0 to 3.
GetNearestPlayerName string GetNearestPlayerName(string entityName) Get the name of the player nearest to the specified entity name, for objective use usually.
ShowContagionHint Send a hint to all the clients in the server.


Engine Specific

Function Signature Description
Assert void Assert(bool value, string optional message) Test value and if not true, throws exception, optionally with message.
ConsoleText void ConsoleText(string text, int red, int green, int blue) Send some text to the console in with colour.
DebugDrawBox void DebugDrawBox( vector origin, vector min, vector max, int r, int g, int b, int alpha, float duration) Draw a debug overlay box.
DebugDrawLine void DebugDrawLine(Vector start, Vector end, int red, int green, int blue, bool zTest, float time) Draw a debug overlay line.
developer bool developer() If developer mode is on.
Document
DoIncludeScript void DoIncludeScript(string file, handle scope) Execute a script (internal)
DoEntFire void DoEntFire(string target, string action, string value, float delay, handle activator, handle caller) Generate an entity I/O event. The caller argument takes an entity handle, so it can be used with target set to !self to fire inputs to entities without usable targetnames.
DoUniqueString string DoUniqueString(string input) Generate a string guaranteed to be unique across the life of the script VM.
GetFunctionSignature
Msg void Msg(string message) Prints message to console without any line feed after.
PrintHelp
printl void printl(string message) Prints message to console with a line feed after.
RandomFloat float RandomFloat() Generate a random floating point number.
RandomFloat float RandomFloat(float min, float max) Generate a random floating point number within a range, inclusive.
RandomInt int RandomInt() Generate a random integer.
RandomInt int RandomInt(int min, int max) Generate a random integer within a range, inclusive.
RegisterFunctionDocumentation
ReloadMOTD void ReloadMOTD() Reloads the MotD file.
RetrieveNativeSignature
SendToConsole void SendToConsole(string command) Send a string to the console as a command.
ShowMessage void ShowMessage(string message) Print a HUD message on all clients.
Todo: likely non-functional
Time float Time() Get the current server time.
VSquirrel_OnCreateScope
VSquirrel_OnReleaseScope

Standard Squirrel library

SquirrelStandard Squirrel library functions (consult official Squirrel language league for more details):

Function
abs
acos
array
asin
assert
atan
atan2
ceil
collectgarbage
compilestring
cos
exp
fabs
floor
format
getconsttable
getroottable
getstackinfos
log
log10
lstrip
pow
print
rand
rstrip
setconsttable
seterrorhandler
setroottable
type
sin
split
sqrt
srand
strip
suspend
tan

See also