Difference between revisions of "List of Counter-Strike: Global Offensive Script Functions"

From Valve Developer Community
Jump to: navigation, search
(Cleanup, corrections and additions)
Line 1: Line 1:
 
 
{{otherlang2
 
{{otherlang2
 
|zh-cn=CSGO_VScript_清单
 
|zh-cn=CSGO_VScript_清单
Line 7: Line 6:
 
{{toc-right}}
 
{{toc-right}}
  
{{sq}} This list contains the engine-related Squirrel classes, functions and variables available for [[VScript]] in {{game link|Counter-Strike: Global Offensive}}. Some of it can be printed in the console by setting <code>developer</code> to at least 1, loading a map and executing <code>script_help</code>. Note that <code>developer</code> only needs to be non-zero during map-loading, so to dump <code>script_help</code> to a file do something like this:
+
{{sq}} This list contains the engine-related Squirrel classes, functions and variables available for [[VScript]] in {{game link|Counter-Strike: Global Offensive}}. The official documentation can be printed in the console by setting <code>developer</code> to non-zero, loading a map, and executing <code>script_help</code>.
 
 
<code>
 
developer 3
 
map de_nuke
 
developer 0
 
con_logfile dump.log
 
script_help
 
con_logfile ""
 
</code>
 
 
 
 
 
 
 
 
 
 
 
 
 
  
  
 
== Variables ==
 
== Variables ==
 
+
{| class="standard-table"
{| class="standard-table"  
 
 
!Instance
 
!Instance
 
!Type
 
!Type
Line 34: Line 17:
 
|<code>Entities</code>
 
|<code>Entities</code>
 
|<code>[[#CEntities|CEntities]]</code>
 
|<code>[[#CEntities|CEntities]]</code>
|Provides access to currently spawned entities.
+
|Provides access to spawned entities in the server.
 
|-
 
|-
 
|}
 
|}
 +
  
 
== Constants ==
 
== Constants ==
Line 58: Line 42:
 
|<code>_version_</code>
 
|<code>_version_</code>
 
|string
 
|string
| The version of squirrel: Squirrel 2.2.3 stable
+
| "Squirrel 2.2.3 stable"
 
|-
 
|-
 
|<code>RAND_MAX</code>
 
|<code>RAND_MAX</code>
Line 68: Line 52:
 
| 3.14159
 
| 3.14159
 
|}
 
|}
 +
  
 
== Classes ==
 
== Classes ==
Line 75: Line 60:
 
This is a script handle class for entities. All entities spawned have a script handle using this or one of its subclasses.  
 
This is a script handle class for entities. All entities spawned have a script handle using this or one of its subclasses.  
  
All script handles in-game are accessible from [[#CEntities|Entities]]. Entity Scripts can use <code>self</code> to access their own script handle.
+
All script handles in-game are accessible from [[#CEntities|Entities]]. Entity scripts can use <code>self</code> to access their own script handle. <code>actiavtor</code> and <code>caller</code> variables can be accessed on function calls.
 +
 
  
 
==== Methods ====
 
==== Methods ====
Line 85: Line 71:
 
| <code>__KeyValueFromInt</code>
 
| <code>__KeyValueFromInt</code>
 
| <code>bool __KeyValueFromInt(string ''key'', int ''value'')</code>
 
| <code>bool __KeyValueFromInt(string ''key'', int ''value'')</code>
| Sets an entity [[Keyvalue]] from an integer. This simply changes the value without executing any code that may be needed for the entity to process the KeyValue, so there may be unintended side effects.
+
| Sets an entity [[keyvalue]] from an integer.
 
|-
 
|-
 
| <code>__KeyValueFromFloat</code>
 
| <code>__KeyValueFromFloat</code>
 
| <code>bool __KeyValueFromFloat(string ''key'', float ''value'')</code>
 
| <code>bool __KeyValueFromFloat(string ''key'', float ''value'')</code>
| Sets an entity Keyvalue from a float. This simply changes the value without executing any code that may be needed for the entity to process the KeyValue, so there may be unintended side effects.
+
| Sets an entity keyvalue from a float.
 
|-
 
|-
 
| <code>__KeyValueFromString</code>
 
| <code>__KeyValueFromString</code>
 
| <code>bool __KeyValueFromString(string ''key'', string ''value'')</code>
 
| <code>bool __KeyValueFromString(string ''key'', string ''value'')</code>
| Sets an entity Keyvalue from a string. This simply changes the value without executing any code that may be needed for the entity to process the KeyValue, so there may be unintended side effects.
+
| Sets an entity keyvalue from a string.
 
|-
 
|-
 
| <code>__KeyValueFromVector</code>
 
| <code>__KeyValueFromVector</code>
 
| <code>bool __KeyValueFromVector(string ''key'', Vector ''value'')</code>
 
| <code>bool __KeyValueFromVector(string ''key'', Vector ''value'')</code>
| Sets an entity Keyvalue from a [[#Vector|Vector]]. This simply changes the value without executing any code that may be needed for the entity to process the KeyValue, so there may be unintended side effects.
+
| Sets an entity keyvalue from a [[#Vector|Vector]].
 
|-
 
|-
 
| <code>ConnectOutput</code>
 
| <code>ConnectOutput</code>
Line 125: Line 111:
 
| <code>FirstMoveChild</code>
 
| <code>FirstMoveChild</code>
 
| <code>handle FirstMoveChild()</code>
 
| <code>handle FirstMoveChild()</code>
| Return the first entity which has been parented to this entity, or null if this has no children. Exactly which is returned is unpredictable, but you can then call <code>NextMovePeer()</code> on each child to loop over all of them one by one.  
+
| If in hierarchy, get the first move child.
 
|-
 
|-
 
| <code>GetAngles</code>
 
| <code>GetAngles</code>
 
| <code>Vector GetAngles()</code>
 
| <code>Vector GetAngles()</code>
| Get the entity pitch, yaw, roll as a [[#Vector|Vector]] object.
+
| Get the entity pitch, yaw, roll as a Vector object.
 
|-
 
|-
 
| <code>GetAngularVelocity</code>
 
| <code>GetAngularVelocity</code>
Line 149: Line 135:
 
| <code>GetClassname</code>
 
| <code>GetClassname</code>
 
| <code>string GetClassname()</code>
 
| <code>string GetClassname()</code>
| Returns the entity class. This includes <code>player</code>.
+
| Get entity classname.
 
|-
 
|-
 
| <code>GetForwardVector</code>
 
| <code>GetForwardVector</code>
Line 161: Line 147:
 
| <code>GetLeftVector</code>
 
| <code>GetLeftVector</code>
 
| <code>Vector GetLeftVector()</code>
 
| <code>Vector GetLeftVector()</code>
| Get the left vector of the entity.
+
| Get the ''right'' vector of the entity.
 
|-
 
|-
 
| <code>GetMaxHealth</code>
 
| <code>GetMaxHealth</code>
 
| <code>int GetMaxHealth()</code>
 
| <code>int GetMaxHealth()</code>
|Returns the maximum health.
+
| Returns the maximum health.
 
|-
 
|-
 
| <code>GetModelKeyValues</code>
 
| <code>GetModelKeyValues</code>
Line 173: Line 159:
 
| <code>GetModelName</code>
 
| <code>GetModelName</code>
 
| <code>string GetModelName()</code>
 
| <code>string GetModelName()</code>
| Returns the file name of the entity's model.
+
| Returns the name of the model
 
|-
 
|-
 
| <code>GetMoveParent</code>
 
| <code>GetMoveParent</code>
Line 208: Line 194:
 
|-
 
|-
 
| <code>GetSoundDuration</code>
 
| <code>GetSoundDuration</code>
| <code>float GetSoundDuration(string ''soundName'', string ''actorModelName'' = "")</code>
+
| <code>float GetSoundDuration(string ''soundName'', string ''actorModelName'')</code>
 
| Returns float duration of the sound. Takes soundname and optional actormodelname.
 
| Returns float duration of the sound. Takes soundname and optional actormodelname.
 
|-
 
|-
Line 229: Line 215:
 
| <code>NextMovePeer</code>
 
| <code>NextMovePeer</code>
 
| <code>handle NextMovePeer()</code>
 
| <code>handle NextMovePeer()</code>
| If parented, return the next "sibling" entity (that is also parented to this entity's parent). Otherwise, return null. Repeatedly calling this will iterate over all the entities parented to the parent. This should be used in combination with <code>parent.FirstMoveChild()</code>.
+
| Return the next entity in the same movement hierarchy.
 
|-
 
|-
 
| <code>PrecacheModel</code>
 
| <code>PrecacheModel</code>
| <code>void PrecacheModel(string ''modelPath'')</code>
+
| <code>void PrecacheModel(string ''model'')</code>
| Precache a model after the map has loaded.
+
| Precache a model. Expensive.
 
|-
 
|-
 
| <code>PrecacheScriptSound</code>
 
| <code>PrecacheScriptSound</code>
 
| <code>void PrecacheScriptSound(string ''soundName'')</code>
 
| <code>void PrecacheScriptSound(string ''soundName'')</code>
|  
+
| Precache a sound. Expensive.
 
|-
 
|-
 
| <code>PrecacheSoundScript</code>
 
| <code>PrecacheSoundScript</code>
 
| <code>void PrecacheSoundScript(string ''soundScript'')</code>
 
| <code>void PrecacheSoundScript(string ''soundScript'')</code>
| Precache a sound for later playing. {{warning|If you copy your sound direction from Hammer's Sound Browser, you need to change backslashes to slashes <code>e.g. physics/flesh/..</code> or your script won't get compiled.}}
+
| Precache a sound for later playing. Expensive.
 
|-
 
|-
 
| <code>SetAbsOrigin</code>
 
| <code>SetAbsOrigin</code>
 
| <code>void SetAbsOrigin(Vector ''position'')</code>
 
| <code>void SetAbsOrigin(Vector ''position'')</code>
| Same as SetOrigin().
+
| Set absolute origin.
 
|-
 
|-
 
| <code>SetAngles</code>
 
| <code>SetAngles</code>
Line 268: Line 254:
 
|-
 
|-
 
| <code>SetModel</code>
 
| <code>SetModel</code>
| <code>void SetModel(string ''modelName'')</code>
+
| <code>void SetModel(string ''model'')</code>
| Changes the model of the entity. Does not Precache the model. {{todo|Check for side effects}}
+
| Changes the model of the entity. Does not precache the model.
 
|-
 
|-
 
| <code>SetOrigin</code>
 
| <code>SetOrigin</code>
 
| <code>void SetOrigin(Vector ''position'')</code>
 
| <code>void SetOrigin(Vector ''position'')</code>
| Moves the entity to this global position vector.
+
| Set local origin.
 
|-
 
|-
 
| <code>SetOwner</code>
 
| <code>SetOwner</code>
Line 285: Line 271:
 
| <code>SetTeam</code>
 
| <code>SetTeam</code>
 
| <code>void SetTeam(int ''teamNumber'')</code>
 
| <code>void SetTeam(int ''teamNumber'')</code>
| Instantly switches a players team. Terrorists = 2, CTs = 3.
+
| Set player team. T = 2, CT = 3
 
|-
 
|-
 
| <code>SetVelocity</code>
 
| <code>SetVelocity</code>
 
| <code>void SetVelocity(Vector ''velocity'')</code>
 
| <code>void SetVelocity(Vector ''velocity'')</code>
| Gives the entity a new local velocity.
+
| Set local velocity.
 
|-
 
|-
 
| <code>StopSound</code>
 
| <code>StopSound</code>
| <code>void StopSound(string ''???'')</code>
+
| <code>void StopSound(string ''soundName'')</code>
 
| Stops a sound on this entity.
 
| Stops a sound on this entity.
 
|-
 
|-
Line 300: Line 286:
 
|-
 
|-
 
|}
 
|}
 +
  
 
==== Hooks ====
 
==== Hooks ====
Line 315: Line 302:
 
| <code>OnPostSpawn</code>
 
| <code>OnPostSpawn</code>
 
| <code>void OnPostSpawn()</code>
 
| <code>void OnPostSpawn()</code>
| Called immediately after the entity spawns. This could be used to have an entity register itself with a master script, or adjusting the entity parameters in a programmatic way.
+
| Called after the entity script is executed. This could be used to have an entity register itself with a master script, or adjusting the entity parameters in a programmatic way.
 
|-
 
|-
 
| <code>Precache</code>
 
| <code>Precache</code>
 
| <code>void Precache()</code>
 
| <code>void Precache()</code>
| Called after the script executes. Can be used to call precache functions for models and sounds on map load.
+
| Called after the entity script is executed. Can be used to call precache functions for models and sounds on map load.
 
|}
 
|}
 +
  
 
=== CBaseAnimating ===
 
=== CBaseAnimating ===
Line 326: Line 314:
  
 
Script handle class for animating entities such as props.
 
Script handle class for animating entities such as props.
 +
  
 
==== Methods ====
 
==== Methods ====
Line 338: Line 327:
 
|-
 
|-
 
| <code>GetAttachmentOrigin</code>
 
| <code>GetAttachmentOrigin</code>
| <code>Vector GetAttachmentOrigin(int 'id')</code>
+
| <code>Vector GetAttachmentOrigin(int ''id'')</code>
 
| Get the attachment ID's origin vector.
 
| Get the attachment ID's origin vector.
 
|-
 
|-
Line 351: Line 340:
 
| <code>SetBodygroup</code>
 
| <code>SetBodygroup</code>
 
| <code>void SetBodygroup(int ''groupIndex'', int ''value'')</code>
 
| <code>void SetBodygroup(int ''groupIndex'', int ''value'')</code>
| Sets the models bodygroup value by index. {{todo|How do you find the index?}}
+
| Sets the models bodygroup value by index.
 
|}
 
|}
  
Line 357: Line 346:
 
=== CBaseFlex ===
 
=== CBaseFlex ===
 
Extends [[#CBaseAnimating|CBaseAnimating]]
 
Extends [[#CBaseAnimating|CBaseAnimating]]
 +
  
 
==== Methods ====
 
==== Methods ====
Line 376: Line 366:
 
=== CBasePlayer ===
 
=== CBasePlayer ===
 
Extends [[#CBaseAnimating|CBaseAnimating]]
 
Extends [[#CBaseAnimating|CBaseAnimating]]
 +
  
 
==== Methods ====
 
==== Methods ====
Line 387: Line 378:
 
| Returns true if the player is in noclip mode.
 
| Returns true if the player is in noclip mode.
 
|}
 
|}
 +
  
 
=== CBaseMultiplayerPlayer ===
 
=== CBaseMultiplayerPlayer ===
Line 398: Line 390:
  
 
Script handle class for [[env_entity_maker]].  
 
Script handle class for [[env_entity_maker]].  
 +
  
 
==== Methods ====
 
==== Methods ====
Line 410: Line 403:
 
|-
 
|-
 
| <code>SpawnEntityAtEntityOrigin</code>
 
| <code>SpawnEntityAtEntityOrigin</code>
| <code>void SpawnEntityAtEntityOrigin(CBaseEntity ''entity'')</code>
+
| <code>void SpawnEntityAtEntityOrigin(handle ''entity'')</code>
 
| Create an entity at the location of a specified entity instance.
 
| Create an entity at the location of a specified entity instance.
 
|-
 
|-
Line 418: Line 411:
 
|-
 
|-
 
| <code>SpawnEntityAtNamedEntityOrigin</code>
 
| <code>SpawnEntityAtNamedEntityOrigin</code>
| <code>void SpawnEntityAtNamedEntityOrigin(string ''targetName'')</code>
+
| <code>void SpawnEntityAtNamedEntityOrigin(string ''targetname'')</code>
 
| Create an entity at the location of a named entity.
 
| Create an entity at the location of a named entity.
 
|}
 
|}
Line 427: Line 420:
  
 
Script handle class for [[point_template]].
 
Script handle class for [[point_template]].
 +
  
 
==== Hooks ====
 
==== Hooks ====
 
 
;<code>table PreSpawnInstance(string ''entityClass'', string ''entityName'')</code>
 
;<code>table PreSpawnInstance(string ''entityClass'', string ''entityName'')</code>
:If this is defined, it will be called right before the entity is created, and any KeyValues returned will be assigned to the entity.
+
:If this is defined, it will be called right before the entity is created, and any keyvalues returned will be assigned to the entity.
  
 
<source lang="cpp">function PreSpawnInstance( entityClass, entityName )
 
<source lang="cpp">function PreSpawnInstance( entityClass, entityName )
 
{
 
{
local keyvalues =
+
local keyvalues = {  
{  
 
 
   rendercolor = "0 255 0"
 
   rendercolor = "0 255 0"
 
   targetname = "mySpawnedEntity"
 
   targetname = "mySpawnedEntity"
Line 446: Line 438:
  
 
;<code>void PostSpawn(table ''entities'')</code>
 
;<code>void PostSpawn(table ''entities'')</code>
:Called after the entities are spawned. A table with the handles of the spawned entities indexed by name is passed to the function. Could use this to connect outputs or do whatever needs to be done after the entity was created.  
+
:Called after the entities are spawned. A table with the handles of the spawned entities indexed by name is passed to the function. Could use this to connect outputs or do whatever needs to be done after the entity was created.
  
 
{{note|PostSpawn() will not be called unless the PreSpawnInstance() function is also defined in the script.}}
 
{{note|PostSpawn() will not be called unless the PreSpawnInstance() function is also defined in the script.}}
Line 452: Line 444:
 
<source lang="cpp">function PostSpawn( entities )
 
<source lang="cpp">function PostSpawn( entities )
 
{
 
{
foreach( name, handle in entities )
+
foreach( targetname, handle in entities )
 
{
 
{
printl( name + ": " + handle )
+
printl( targetname + ": " + handle )
 
}
 
}
 
}
 
}
 
</source>
 
</source>
 +
  
 
=== CSceneEntity ===
 
=== CSceneEntity ===
Line 464: Line 457:
  
 
==== Methods ====
 
==== Methods ====
 
 
{| class="standard-table" style="width: 100%;"
 
{| class="standard-table" style="width: 100%;"
 
! Function
 
! Function
Line 518: Line 510:
 
| Set cameras current FOV in integer degrees and FOV change rate as float.
 
| Set cameras current FOV in integer degrees and FOV change rate as float.
 
|}
 
|}
 +
  
 
==== Hooks ====
 
==== Hooks ====
 
 
;<code>void ScriptStartCameraShot(string ''shotType'', handle ''sceneEntity'', handle ''actor1'', handle ''actor2'', float ''duration'')</code>
 
;<code>void ScriptStartCameraShot(string ''shotType'', handle ''sceneEntity'', handle ''actor1'', handle ''actor2'', float ''duration'')</code>
 
: ''Called from SceneEntity in response to a CChoreoEvent::CAMERA sent from a VCD.'' {{todo}}
 
: ''Called from SceneEntity in response to a CChoreoEvent::CAMERA sent from a VCD.'' {{todo}}
Line 527: Line 519:
 
=== CFuncTrackTrain ===
 
=== CFuncTrackTrain ===
 
Extends [[#CBaseEntity|CBaseEntity]]
 
Extends [[#CBaseEntity|CBaseEntity]]
 +
  
 
==== Methods ====
 
==== Methods ====
Line 535: Line 528:
 
|-
 
|-
 
| <code>GetFuturePosition</code>
 
| <code>GetFuturePosition</code>
| <code>Vector GetFuturePosition(float, float) {{todo|Args?}}</code>
+
| <code>Vector GetFuturePosition(float ''x'', float ''speed'')</code>
| Get a position on the track x seconds in the future.  
+
| Get a position on the track x seconds in the future.
 
|}
 
|}
  
Line 542: Line 535:
 
=== CHostage ===
 
=== CHostage ===
 
Extends [[#CBaseEntity|CBaseEntity]]
 
Extends [[#CBaseEntity|CBaseEntity]]
 +
  
 
==== Methods ====
 
==== Methods ====
Line 557: Line 551:
 
=== CGameCoopMissionManager ===
 
=== CGameCoopMissionManager ===
 
Extends [[#CBaseEntity|CBaseEntity]]
 
Extends [[#CBaseEntity|CBaseEntity]]
 +
  
 
==== Methods ====
 
==== Methods ====
Line 572: Line 567:
 
=== CCallChainer ===
 
=== CCallChainer ===
 
{{todo}}
 
{{todo}}
 +
  
 
==== Methods ====
 
==== Methods ====
Line 591: Line 587:
 
|  
 
|  
 
|}
 
|}
 +
  
 
==== Members ====
 
==== Members ====
Line 626: Line 623:
 
|-
 
|-
 
| <code>CreateByClassname</code>
 
| <code>CreateByClassname</code>
| <code>handle CreateByClassname(string ''class'')</code>
+
| <code>handle CreateByClassname(string ''classname'')</code>
 
| Creates an entity by class name.
 
| Creates an entity by class name.
 
|-
 
|-
 
| <code>FindByClassname</code>
 
| <code>FindByClassname</code>
| <code>handle FindByClassname(handle ''previous'', string ''class'')</code>
+
| <code>handle FindByClassname(handle ''previous'', string ''classname'')</code>
 
| Find entities by class name.  
 
| Find entities by class name.  
 
|-
 
|-
Line 638: Line 635:
 
|-
 
|-
 
| <code>FindByClassnameWithin</code>
 
| <code>FindByClassnameWithin</code>
| <code>handle FindByClassnameWithin(handle ''previous'', string ''class'', Vector ''origin'', float ''radius'')</code>
+
| <code>handle FindByClassnameWithin(handle ''previous'', string ''classname'', Vector ''origin'', float ''radius'')</code>
 
| Find entities by class name within a radius.  
 
| Find entities by class name within a radius.  
 
|-
 
|-
 
| <code>FindByModel</code>
 
| <code>FindByModel</code>
| <code>handle FindByModel(handle ''previous'', string ''filename'')</code>
+
| <code>handle FindByModel(handle ''previous'', string ''model'')</code>
 
| Find entities by model name.  
 
| Find entities by model name.  
 
|-
 
|-
 
| <code>FindByName</code>
 
| <code>FindByName</code>
| <code>handle FindByName(handle ''previous'', string ''name'')</code>
+
| <code>handle FindByName(handle ''previous'', string ''targetname'')</code>
 
| Find entities by name.  
 
| Find entities by name.  
 
|-
 
|-
 
| <code>FindByNameNearest</code>
 
| <code>FindByNameNearest</code>
| <code>handle FindByNameNearest(string ''name'', Vector ''origin'', float ''radius'')</code>
+
| <code>handle FindByNameNearest(string ''targetname'', Vector ''origin'', float ''radius'')</code>
 
| Find entities by name nearest to a point.
 
| Find entities by name nearest to a point.
 
|-
 
|-
 
| <code>FindByNameWithin</code>
 
| <code>FindByNameWithin</code>
| <code>handle FindByNameWithin(handle ''previous'', string ''name'', Vector ''origin'', float ''radius'')</code>
+
| <code>handle FindByNameWithin(handle ''previous'', string ''targetname'', Vector ''origin'', float ''radius'')</code>
 
| Find entities by name within a radius.
 
| Find entities by name within a radius.
 
|-
 
|-
 
| <code>FindByTarget</code>
 
| <code>FindByTarget</code>
| <code>handle FindByTarget(handle ''previous'', string ''targetname'')</code>
+
| <code>handle FindByTarget(handle ''previous'', string ''target'')</code>
| Find entities by its target.
+
| Find entities by target keyvalue.
 
|-
 
|-
 
| <code>FindInSphere</code>
 
| <code>FindInSphere</code>
Line 680: Line 677:
  
 
=== CPlayerVoiceListener ===
 
=== CPlayerVoiceListener ===
{{todo|What is the int parameter to the methods.}}
+
{{warning|Broken! This class is implemented in CSGO, but the required <code>PlayerVoiceListener</code> instance is not.}}
 +
 
  
 
==== Methods ====
 
==== Methods ====
Line 689: Line 687:
 
|-
 
|-
 
| <code>GetPlayerSpeechDuration</code>
 
| <code>GetPlayerSpeechDuration</code>
| <code>float GetPlayerSpeechDuration(int)</code>
+
| <code>float GetPlayerSpeechDuration(int ''playerIndex'')</code>
 
| Returns the number of seconds the player has been continuously speaking.
 
| Returns the number of seconds the player has been continuously speaking.
 
|-
 
|-
 
| <code>IsPlayerSpeaking</code>
 
| <code>IsPlayerSpeaking</code>
| <code>bool IsPlayerSpeaking(int)</code>
+
| <code>bool IsPlayerSpeaking(int ''playerIndex'')</code>
 
| Returns whether the player specified is speaking.
 
| Returns whether the player specified is speaking.
 
|-
 
|-
Line 705: Line 703:
 
Script handle representation of a models [[$keyvalues]] block.
 
Script handle representation of a models [[$keyvalues]] block.
 
Sub keys are instances of the same class.
 
Sub keys are instances of the same class.
 +
  
 
==== Methods ====
 
==== Methods ====
Line 715: Line 714:
 
|-
 
|-
 
| <code>FindKey</code>
 
| <code>FindKey</code>
| <code>CScriptKeyValues FindKey(string ''keyName'')</code>
+
| <code>CScriptKeyValues FindKey(string ''key'')</code>
 
| Find a sub key by the key name.
 
| Find a sub key by the key name.
 
|-
 
|-
Line 723: Line 722:
 
|-
 
|-
 
| <code>GetKeyBool</code>
 
| <code>GetKeyBool</code>
| <code>bool GetKeyBool(string ''keyName'')</code>
+
| <code>bool GetKeyBool(string ''key'')</code>
 
| Return the key value as a bool.
 
| Return the key value as a bool.
 
|-
 
|-
 
| <code>GetKeyFloat</code>
 
| <code>GetKeyFloat</code>
| <code>float GetKeyFloat(string ''keyName'')</code>
+
| <code>float GetKeyFloat(string ''key'')</code>
 
| Return the key value as a float.
 
| Return the key value as a float.
 
|-
 
|-
 
| <code>GetKeyInt</code>
 
| <code>GetKeyInt</code>
| <code>int GetKeyInt(string ''keyName'')</code>
+
| <code>int GetKeyInt(string ''key'')</code>
 
| Return the key value as an integer.
 
| Return the key value as an integer.
 
|-
 
|-
 
| <code>GetKeyString</code>
 
| <code>GetKeyString</code>
| <code>string GetKeyString(string ''keyName'')</code>
+
| <code>string GetKeyString(string ''key'')</code>
 
| Return the key value as a string.
 
| Return the key value as a string.
 
|-
 
|-
Line 743: Line 742:
 
|-
 
|-
 
| <code>IsKeyEmpty</code>
 
| <code>IsKeyEmpty</code>
| <code>bool IsKeyEmpty(string ''keyName'')</code>
+
| <code>bool IsKeyEmpty(string ''key'')</code>
 
| Returns true if the named key has no value.
 
| Returns true if the named key has no value.
 
|-
 
|-
Line 757: Line 756:
  
 
=== CSimpleCallChainer ===
 
=== CSimpleCallChainer ===
Seems to have the same members as [[#CCallChainer|CCallChainer]].
+
Has the same members as [[#CCallChainer|CCallChainer]].
 
{{todo}}
 
{{todo}}
  
Line 788: Line 787:
  
 
When End() is called, all of the unresolved symbols in the tables and arrays will be resolved, any left unresolved will become a string prepended with '~', which later code can deal with.
 
When End() is called, all of the unresolved symbols in the tables and arrays will be resolved, any left unresolved will become a string prepended with '~', which later code can deal with.
 +
  
 
==== Methods ====
 
==== Methods ====
Line 821: Line 821:
 
| <code>UnhookRootMetamethod</code>
 
| <code>UnhookRootMetamethod</code>
 
|}
 
|}
 +
  
 
=== regexp ===
 
=== regexp ===
The built-in [http://squirrel-lang.org/doc/sqstdlib3.html#d0e2591 Squirrel class] for regular expressions.
+
The built-in [http://squirrel-lang.org/doc/sqstdlib2.html#d0e2580 Squirrel class] for regular expressions.
 +
 
  
 
==== Methods ====
 
==== Methods ====
Line 840: Line 842:
 
|-
 
|-
 
| <code>match</code>
 
| <code>match</code>
| <code> bool match(''str'')</code>
+
| <code>bool match(''str'')</code>
 
| Returns a true if the regular expression matches the string str, otherwise returns false.  
 
| Returns a true if the regular expression matches the string str, otherwise returns false.  
 
|-
 
|-
Line 860: Line 862:
 
Has overloaded arithmetic operations with both Vectors and scalar values.
 
Has overloaded arithmetic operations with both Vectors and scalar values.
  
{{note|[http://www.leeland.net/hochsuch.html Example] declaration and manipulation of Vector}}
 
  
 
==== Methods ====
 
==== Methods ====
Line 869: Line 870:
 
|-
 
|-
 
| <code>constructor</code>
 
| <code>constructor</code>
| <code>Vector(float ''x'', float ''y'', float ''z'')</code>
+
| <code>Vector(float ''x'' = 0, float ''y'' = 0, float ''z'' = 0)</code>
 
| Creates a new vector with the specified Cartesian coordiantes.
 
| Creates a new vector with the specified Cartesian coordiantes.
 
|-
 
|-
Line 882: Line 883:
 
| <code>Length</code>
 
| <code>Length</code>
 
| <code>float Length()</code>
 
| <code>float Length()</code>
| Magnitude of the vector.
+
| Length of the vector.
 
|-
 
|-
 
| <code>LengthSqr</code>
 
| <code>LengthSqr</code>
 
| <code>float LengthSqr()</code>
 
| <code>float LengthSqr()</code>
| The magnitude of the vector squared. Faster than the above method.
+
| Length of the vector squared. Cheaper than the above method.
 
|-
 
|-
 
| <code>Length2D</code>
 
| <code>Length2D</code>
 
| <code>float Length2D()</code>
 
| <code>float Length2D()</code>
| Returns the magnitude of the vector on the x-y plane.
+
| Returns the length of the vector on the x-y plane.
 
|-
 
|-
 
| <code>Length2DSqr</code>
 
| <code>Length2DSqr</code>
 
| <code>float Length2DSqr()</code>
 
| <code>float Length2DSqr()</code>
| Returns the square of the magnitude of the vector on the x-y plane. Faster than the above method.
+
| Returns the square of the length of the vector on the x-y plane. Cheaper than the above method.
 
|-
 
|-
 
| <code>Norm</code>
 
| <code>Norm</code>
 
| <code>float Norm()</code>
 
| <code>float Norm()</code>
| Will return the vector length as a float. This function will also NORMALIZE the vector, the X, Y, and Z values will each be set to a number between -1 and 1. You can then multiply these values by, for example, 3000 to use the vector to set the velocity of something in game.  
+
| Normalise the vector, return vector length.
 
|-
 
|-
 
| <code>ToKVString</code>
 
| <code>ToKVString</code>
Line 904: Line 905:
 
| Returns a string without separations commas.
 
| Returns a string without separations commas.
 
|}
 
|}
 +
  
 
==== Members ====
 
==== Members ====
Line 927: Line 929:
 
== Global functions ==
 
== Global functions ==
  
=== Printing and Drawing ===
+
=== Printing and drawing ===
  
 
{| class="standard-table" style="width: 100%;"
 
{| class="standard-table" style="width: 100%;"
Line 935: Line 937:
 
|-
 
|-
 
| <code>DebugDrawBox</code>
 
| <code>DebugDrawBox</code>
| <code>void DebugDrawBox(vector ''origin'', vector ''min'', vector ''max'', int ''r'', int ''g'', int ''b'', int ''alpha'', float ''duration'')</code>
+
| <code>void DebugDrawBox(vector ''origin'', vector ''mins'', vector ''maxs'', int ''r'', int ''g'', int ''b'', int ''alpha'', float ''duration'')</code>
 
| Draw a debug overlay box.
 
| Draw a debug overlay box.
 
|-
 
|-
 
| <code>DebugDrawLine</code>
 
| <code>DebugDrawLine</code>
| <code>void DebugDrawLine(Vector ''start'', Vector ''end'', int ''red'', int ''green'', int ''blue', bool ''zTest'', float ''time'')</code>
+
| <code>void DebugDrawLine(Vector ''start'', Vector ''end'', int ''r'', int ''g'', int ''b', bool ''noDepthTest'', float ''duration'')</code>
 
| Draw a debug line between two points.
 
| Draw a debug line between two points.
 
|-
 
|-
Line 952: Line 954:
 
| <code>printl</code>
 
| <code>printl</code>
 
| <code>void printl(string ''message'')</code>
 
| <code>void printl(string ''message'')</code>
| Prints the given message to the developer console just like print but also appends a newline.
+
| Prints the given message to the developer console with newline. <code>print( message + "\n" )</code>
 
|-
 
|-
 
| <code>ScriptPrintMessageCenterAll</code>
 
| <code>ScriptPrintMessageCenterAll</code>
Line 979: Line 981:
 
|-
 
|-
 
| <code>__DumpScope</code>
 
| <code>__DumpScope</code>
| <code>void __DumpScope(int ''indentation'', handle ''scope'')</code>
+
| <code>void __DumpScope(int ''indentation'', table ''scope'')</code>
 
| Dumps contents of everything in the scope.
 
| Dumps contents of everything in the scope.
 
|-
 
|-
Line 985: Line 987:
  
  
=== Training Course related ===
+
=== Training Course ===
 +
 
 
{| class="standard-table" style="width: 100%;"
 
{| class="standard-table" style="width: 100%;"
 
! Function
 
! Function
Line 1,034: Line 1,037:
  
  
=== Co-op Strike related ===
+
=== Co-op Strike ===
 +
 
 
{| class="standard-table" style="width: 100%;"
 
{| class="standard-table" style="width: 100%;"
 
! Function
 
! Function
Line 1,086: Line 1,090:
 
|}
 
|}
  
=== Math related ===
+
 
The built-in [http://www.squirrel-lang.org/squirreldoc/stdlib/stdmathlib.html Squirrel library] for mathematic routines.
+
=== Math ===
 +
 
 +
The built-in [http://www.squirrel-lang.org/mainsite/doc/sqstdlib2.html#d0e1519 Squirrel math library].
  
 
{| class="standard-table" style="width: 100%;"
 
{| class="standard-table" style="width: 100%;"
Line 1,169: Line 1,175:
  
 
=== Other ===
 
=== Other ===
 +
 
{| class="standard-table" style="width: 100%;"
 
{| class="standard-table" style="width: 100%;"
 
! Function
 
! Function
Line 1,175: Line 1,182:
 
|-
 
|-
 
| <code>Assert</code>
 
| <code>Assert</code>
| <code>void Assert(bool ''value'', string ''optional message'')</code>
+
| <code>void Assert(bool ''value'', string ''message'' = null)</code>
 
| Test value and if not true, throws exception, optionally with message.
 
| Test value and if not true, throws exception, optionally with message.
 
|-
 
|-
 
| <code>CreateProp</code>
 
| <code>CreateProp</code>
| <code>handle CreateProp(string ''class'', Vector ''origin'', string ''model'', int ''animation'')</code>
+
| <code>handle CreateProp(string ''classname'', Vector ''origin'', string ''model'', int ''animation'')</code>
 
| Create a prop with the specified class and model. Both prop_physics, prop_dynamic as well as some other entity classes with models work. Does not precache the model. {{bug|Does not initialize the physics of the prop.}}
 
| Create a prop with the specified class and model. Both prop_physics, prop_dynamic as well as some other entity classes with models work. Does not precache the model. {{bug|Does not initialize the physics of the prop.}}
 
|-
 
|-
Line 1,187: Line 1,194:
 
|-
 
|-
 
| <code>DispatchParticleEffect</code>
 
| <code>DispatchParticleEffect</code>
| <code>void DispatchParticleEffect(string particleName, Vector, Vector)</code>
+
| <code>void DispatchParticleEffect(string ''particle'', Vector ''position'', Vector ''orientation'')</code>
 
| Dispatches a one-off particle system.
 
| Dispatches a one-off particle system.
 
|-
 
|-
 
| <code>DoIncludeScript</code>
 
| <code>DoIncludeScript</code>
 
| <code>bool DoIncludeScript(string ''filename'', table ''scope'')</code>
 
| <code>bool DoIncludeScript(string ''filename'', table ''scope'')</code>
| Execute a script with the script scope set to the specified table.
+
| Execute a script file in the scope of ''scope''.
 +
|-
 +
| <code>IncludeScript</code>
 +
| <code>bool IncludeScript(string ''filename'', table ''scope'' = null)</code>
 +
| Execute a script file in the scope of ''scope'', <code>this</code> by default.
 
|-
 
|-
 
| <code>DoEntFire</code>
 
| <code>DoEntFire</code>
 
| <code>void DoEntFire(string ''target'', string ''action'', string ''value'', float ''delay'', handle ''activator'', handle ''caller'')</code>
 
| <code>void DoEntFire(string ''target'', string ''action'', string ''value'', float ''delay'', handle ''activator'', handle ''caller'')</code>
| Generate an entity I/O event. The ''caller'' argument takes a script handle, so it can be used with ''target'' set to ''!self'' to fire inputs to entities without usable targetnames.
+
| Generate an entity I/O event.
 
|-
 
|-
 
| <code>EntFire</code>
 
| <code>EntFire</code>
| <code>function EntFire(string ''target'', string ''action'', string ''value'', float ''delay'' = 0.0, handle ''activator'' = null)</code>
+
| <code>function EntFire(string ''target'', string ''action'', string ''value'' = "", float ''delay'' = 0.0, handle ''activator'' = null)</code>
 
| Generate an entity I/O event.
 
| Generate an entity I/O event.
 
|-
 
|-
 
| <code>EntFireByHandle</code>
 
| <code>EntFireByHandle</code>
 
| <code>void EntFireByHandle(handle ''target'', string ''action'', string ''value'', float ''delay'', handle ''activator'', handle ''caller'')</code>
 
| <code>void EntFireByHandle(handle ''target'', string ''action'', string ''value'', float ''delay'', handle ''activator'', handle ''caller'')</code>
| Generate an entity I/O event. The first parameter is an entity instance, so the handles of nameless or script generated entities can be passed easily.
+
| Generate an entity I/O event.
 
|-
 
|-
 
| <code>FrameTime</code>
 
| <code>FrameTime</code>
Line 1,212: Line 1,223:
 
| <code>GetDeveloperLevel</code>
 
| <code>GetDeveloperLevel</code>
 
| <code>int GetDeveloperLevel()</code>
 
| <code>int GetDeveloperLevel()</code>
| Gets the level of the ''developer'' mode.
+
| Gets the level of the ''developer'' mode. Equivalent to <code>developer()</code>
 
|-
 
|-
 
| <code>GetMapName</code>
 
| <code>GetMapName</code>
Line 1,247: Line 1,258:
 
|-
 
|-
 
| <code>RetrieveNativeSignature</code>
 
| <code>RetrieveNativeSignature</code>
| <code>void RetrieveNativeSignature(string ''or'' func)</code>
+
| <code>void RetrieveNativeSignature(string ''nativeFunction'')</code>
| Name suggests it would print the calling format for a native function, but I can't get it to output anything other than <code><unnamed></code>
+
|  
 
|-
 
|-
 
| <code>ScriptGetGameMode</code>
 
| <code>ScriptGetGameMode</code>
Line 1,271: Line 1,282:
 
|-
 
|-
 
| <code>ScriptSetRadarHidden</code>
 
| <code>ScriptSetRadarHidden</code>
| <code>void ScriptSetRadarHidden(bool ''hideRadar'')</code>
+
| <code>void ScriptSetRadarHidden(bool ''hide'')</code>
 
| Toggles the visibility of the radar hud element. Only works in training mode (game_type 2, game_mode 0) and only for the first person connected.
 
| Toggles the visibility of the radar hud element. Only works in training mode (game_type 2, game_mode 0) and only for the first person connected.
 
|-
 
|-
 
| <code>SendToConsole</code>
 
| <code>SendToConsole</code>
 
| <code>void SendToConsole(string ''command'')</code>
 
| <code>void SendToConsole(string ''command'')</code>
| Send a string to the console as a command.
+
| Send a string to the console as a command. The command is executed through the local player.
 
|-
 
|-
 
| <code>SendToConsoleServer</code>
 
| <code>SendToConsoleServer</code>
| <code>void SendToConsoleServer(string)</code>
+
| <code>void SendToConsoleServer(string ''command'')</code>
 
| Send a string that gets executed on the server as a ServerCommand
 
| Send a string that gets executed on the server as a ServerCommand
 
|-
 
|-
Line 1,287: Line 1,298:
 
|-
 
|-
 
| <code>TraceLine</code>
 
| <code>TraceLine</code>
| <code>float TraceLine(Vector, Vector, handle)</code>
+
| <code>float TraceLine(Vector ''start'', Vector ''end'', handle ''ignore'')</code>
 
| given 2 points & ent to ignore, return fraction along line that hits world or models
 
| given 2 points & ent to ignore, return fraction along line that hits world or models
 
|-
 
|-
 
| <code>UniqueString</code>
 
| <code>UniqueString</code>
| <code>function UniqueString(string)</code>
+
| <code>function UniqueString(string = "")</code>
 
| Generate a string guaranteed to be unique across the life of the script VM, with an optional root string. Useful for adding data to tables when not sure what keys are already in use in that table.
 
| Generate a string guaranteed to be unique across the life of the script VM, with an optional root string. Useful for adding data to tables when not sure what keys are already in use in that table.
 
|-
 
|-
Line 1,297: Line 1,308:
 
|}
 
|}
  
== See Also ==
 
* [http://pastebin.com/7LRsSjEZ Pastebin with script that suggests it is run when Squirrel VM starts]
 
  
* [[List of L4D2 Script Functions]]
+
== See also ==
 +
* {{l4d2}} [[List of L4D2 Script Functions]]
 
* {{portal2}} [[List of Portal 2 Script Functions]]
 
* {{portal2}} [[List of Portal 2 Script Functions]]
  
 
[[Category:Counter-Strike: Global Offensive]]
 
[[Category:Counter-Strike: Global Offensive]]
 
[[Category:Scripting]]
 
[[Category:Scripting]]

Revision as of 14:17, 29 January 2020

Русский 简体中文

Squirrel Language This list contains the engine-related Squirrel classes, functions and variables available for VScript in Counter-Strike: Global Offensive Counter-Strike: Global Offensive. The official documentation can be printed in the console by setting developer to non-zero, loading a map, and executing script_help.


Variables

Instance Type Description
Entities CEntities Provides access to spawned entities in the server.


Constants

Instance Type Description
_charsize_ integer 1
_floatsize_ integer 4
_intsize_ integer 4
_version_ string "Squirrel 2.2.3 stable"
RAND_MAX integer 32767
PI float 3.14159


Classes

CBaseEntity

This is a script handle class for entities. All entities spawned have a script handle using this or one of its subclasses.

All script handles in-game are accessible from Entities. Entity scripts can use self to access their own script handle. actiavtor and caller variables can be accessed on function calls.


Methods

Function Signature Description
__KeyValueFromInt bool __KeyValueFromInt(string key, int value) Sets an entity keyvalue from an integer.
__KeyValueFromFloat bool __KeyValueFromFloat(string key, float value) Sets an entity keyvalue from a float.
__KeyValueFromString bool __KeyValueFromString(string key, string value) Sets an entity keyvalue from a string.
__KeyValueFromVector bool __KeyValueFromVector(string key, Vector value) Sets an entity keyvalue from a Vector.
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.
Destroy void Destroy() Kills the entity.
EmitSound void EmitSound(string soundScript) Plays a sound from this entity.
entindex int entindex() Returns the entity index.
EyePosition Vector EyePosition() Get vector to the eye position - absolute coordinates.
FirstMoveChild handle FirstMoveChild() If in hierarchy, get the first move child.
GetAngles Vector GetAngles() Get the entity pitch, yaw, roll as a Vector object.
GetAngularVelocity Vector GetAngularVelocity() Get the local angular velocity - returns a Vector of pitch, yaw, roll.
GetBoundingMaxs Vector GetBoundingMaxs() Returns the maximum extent of the entity bounding box as a local vector.
GetBoundingMins Vector GetBoundingMins() Returns the maximum extent of the entity bounding box as a local vector.
GetCenter Vector GetCenter() Returns a local vector of the bounding box center.
GetClassname string GetClassname() Get entity classname.
GetForwardVector Vector GetForwardVector() Get the forward vector of the entity.
GetHealth int GetHealth() Returns the current health.
GetLeftVector Vector GetLeftVector() Get the right vector of the entity.
GetMaxHealth int GetMaxHealth() Returns the maximum health.
GetModelKeyValues Keyvalues GetModelKeyValues() Returns the $keyvalues block of the entity's model as a #Keyvalues object. Note that this is not the keyvalues of the entity itself.
GetModelName string GetModelName() Returns the name of the model
GetMoveParent CBaseEntity GetMoveParent() If in hierarchy, retrieves the entity's parent.
GetName string GetName() Returns the targetname of the entity.
GetOrigin Vector GetOrigin() Returns the Entity position in the world.
GetOwner handle GetOwner() Gets this entity's owner. (seems to only be useful if you have used SetOwner() previously on this entity, could be wrong)
GetPreTemplateName string GetPreTemplateName() Get the entity name stripped of template unique decoration. This is the &048 suffix added by templates that do not preserve the entity name.
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 data associated with this entity.
GetSoundDuration float GetSoundDuration(string soundName, string actorModelName) Returns float duration of the sound. Takes soundname and optional actormodelname.
GetTeam int GetTeam() Returns the team number of a player. Terrorists = 2, CTs = 3.
GetUpVector Vector GetUpVector() Get the up vector of the entity.
GetVelocity Vector GetVelocity() Returns a local velocity Vector.
IsValid bool IsValid() Whether the handle belongs to a valid entity.
NextMovePeer handle NextMovePeer() Return the next entity in the same movement hierarchy.
PrecacheModel void PrecacheModel(string model) Precache a model. Expensive.
PrecacheScriptSound void PrecacheScriptSound(string soundName) Precache a sound. Expensive.
PrecacheSoundScript void PrecacheSoundScript(string soundScript) Precache a sound for later playing. Expensive.
SetAbsOrigin void SetAbsOrigin(Vector position) Set absolute origin.
SetAngles void SetAngles(float pitch, float yaw, float roll) Set entity pitch, yaw, roll. Note that it doesn't take a Vector object.
SetAngularVelocity void SetAngularVelocity(float pitch, float yaw, float roll) Set the local angular velocity - takes float pitch, yaw, roll velocities.
SetForwardVector void SetForwardVector(Vector forwardVector) Set the orientation of the entity to have this forward vector.
SetHealth void SetHealth(int newHealth) Sets the current health.
SetMaxHealth void SetMaxHealth(int maxHealth) Sets a new maximum health.
SetModel void SetModel(string model) Changes the model of the entity. Does not precache the model.
SetOrigin void SetOrigin(Vector position) Set local origin.
SetOwner void SetOwner(handle owner) Sets this entity's owner. Entities will usually not collide with / hurt their owner.
SetSize void SetSize(Vector, Vector) Sets the bounding box size, for non-model/brush entities. The exact effect depends on the entity, but it may change the size of any collision-type checks.
SetTeam void SetTeam(int teamNumber) Set player team. T = 2, CT = 3
SetVelocity void SetVelocity(Vector velocity) Set local velocity.
StopSound void StopSound(string soundName) Stops a sound on this entity.
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.

Function Signature Description
InputInputName bool InputInputName() Called when the entity receives an input from the I/O system. The name of the function needs to be Input followed by the name of the input in CamelCase, for example InputFireUser1 for the FireUser1 input. When the function is called, the activating and calling entities Script Handles are written to the receiving entitys Script Scope in the activator and caller variables. The function needs to return a boolean value. Setting it to true allows the entity to process the input, while false cancels it.
OnPostSpawn void OnPostSpawn() Called after the entity script is executed. This could be used to have an entity register itself with a master script, or adjusting the entity parameters in a programmatic way.
Precache void Precache() Called after the entity script is executed. Can be used to call precache functions for models and sounds on map load.


CBaseAnimating

Extends CBaseEntity

Script handle class for animating entities such as props.


Methods

Function Signature Description
GetAttachmentAngles Vector GetAttachmentAngles(int id) Get the attachment ID's angles as a pitch, yaw, roll vector.
GetAttachmentOrigin Vector GetAttachmentOrigin(int id) Get the attachment ID's origin vector.
IsSequenceFinished bool IsSequenceFinished() Ask whether the main sequence is done playing.
LookupAttachment int LookupAttachment(string attachmentName) Get the named attachment ID.
SetBodygroup void SetBodygroup(int groupIndex, int value) Sets the models bodygroup value by index.


CBaseFlex

Extends CBaseAnimating


Methods

Function Signature Description
GetCurrentScene handle GetCurrentScene() Returns the instance of the oldest active scene entity (if any).
GetSceneByIndex handle GetSceneByIndex(int index) Returns the instance of the scene entity at the specified index.


CBasePlayer

Extends CBaseAnimating


Methods

Function Signature Description
IsNoclipping bool IsNoclipping() Returns true if the player is in noclip mode.


CBaseMultiplayerPlayer

Extends CBasePlayer

Script handle class for the CS:GO players. No additional methods.


CEnvEntityMaker

Extends CBaseEntity

Script handle class for env_entity_maker.


Methods

Function Signature Description
SpawnEntity void SpawnEntity() Create an entity at the location of the maker
SpawnEntityAtEntityOrigin void SpawnEntityAtEntityOrigin(handle entity) Create an entity at the location of a specified entity instance.
SpawnEntityAtLocation void SpawnEntityAtLocation(Vector origin, Vector orientation) Create an entity at a specified location and orientation, orientation is Euler angle in degrees (pitch, yaw, roll).
SpawnEntityAtNamedEntityOrigin void SpawnEntityAtNamedEntityOrigin(string targetname) Create an entity at the location of a named entity.


CPointTemplate

Extends CBaseEntity

Script handle class for point_template.


Hooks

table PreSpawnInstance(string entityClass, string entityName)
If this is defined, it will be called right before the entity is created, and any keyvalues returned will be assigned to the entity.
function PreSpawnInstance( entityClass, entityName )
{
	local keyvalues = { 
   		rendercolor = "0 255 0"
   		targetname = "mySpawnedEntity"
	}
	return keyvalues
	
}
void PostSpawn(table entities)
Called after the entities are spawned. A table with the handles of the spawned entities indexed by name is passed to the function. Could use this to connect outputs or do whatever needs to be done after the entity was created.
Note.png Note: PostSpawn() will not be called unless the PreSpawnInstance() function is also defined in the script.
function PostSpawn( entities )
{
	foreach( targetname, handle in entities )
	{
		printl( targetname + ": " + handle )
	}
}


CSceneEntity

Extends CBaseEntity


Methods

Function Signature Description
AddBroadcastTeamTarget void AddBroadcastTeamTarget(int index) Adds a team (by index) to the broadcast list.
EstimateLength float EstimateLength() Returns length of this scene in seconds.
FindNamedEntity handle FindNamedEntity(string reference) given an entity reference, such as !target, get actual entity from scene object.
IsPaused bool IsPaused() If this scene is currently paused.
IsPlayingBack bool IsPlayingBack() If this scene is currently playing.
LoadSceneFromString bool LoadSceneFromString(string sceneName, string scene) Given a dummy scene name and a vcd string, load the scene.
RemoveBroadcastTeamTarget void RemoveBroadcastTeamTarget(int index) Removes a team (by index) from the broadcast list.


CTriggerCamera

Extends CBaseEntity


Methods

Function Signature Description
GetFov int GetFov() Get cameras current Field Of View setting as integer.
SetFov void SetFov(int fov, float rate) Set cameras current FOV in integer degrees and FOV change rate as float.


Hooks

void ScriptStartCameraShot(string shotType, handle sceneEntity, handle actor1, handle actor2, float duration)
Called from SceneEntity in response to a CChoreoEvent::CAMERA sent from a VCD. To do


CFuncTrackTrain

Extends CBaseEntity


Methods

Function Signature Description
GetFuturePosition Vector GetFuturePosition(float x, float speed) Get a position on the track x seconds in the future.


CHostage

Extends CBaseEntity


Methods

Function Signature Description
IsBeingCarried bool IsBeingCarried() Get whether the hostage is currently being carried or not.


CGameCoopMissionManager

Extends CBaseEntity


Methods

Function Signature Description
GetWaveNumber int GetWaveNumber() Get the number of waves the players have completed.


CCallChainer

To do


Methods

Function Signature Description
constructor constructor(prefixString, scopeForThis = null)
PostScriptExecute PostScriptExecute()
Call Call(event, ...)


Members

Instance Type Description
chains null
prefix null
scope null


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
CreateByClassname handle CreateByClassname(string classname) Creates an entity by class name.
FindByClassname handle FindByClassname(handle previous, string classname) 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 classname, Vector origin, float radius) Find entities by class name within a radius.
FindByModel handle FindByModel(handle previous, string model) Find entities by model name.
FindByName handle FindByName(handle previous, string targetname) Find entities by name.
FindByNameNearest handle FindByNameNearest(string targetname, Vector origin, float radius) Find entities by name nearest to a point.
FindByNameWithin handle FindByNameWithin(handle previous, string targetname, Vector origin, float radius) Find entities by name within a radius.
FindByTarget handle FindByTarget(handle previous, string target) Find entities by target keyvalue.
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.


CPlayerVoiceListener

Warning.png Warning: Broken! This class is implemented in CSGO, but the required PlayerVoiceListener instance is not.


Methods

Function Signature Description
GetPlayerSpeechDuration float GetPlayerSpeechDuration(int playerIndex) Returns the number of seconds the player has been continuously speaking.
IsPlayerSpeaking bool IsPlayerSpeaking(int playerIndex) Returns whether the player specified is speaking.
IsValid bool IsValid() Whether the handle belongs to a valid entity.


CScriptKeyValues

Script handle representation of a models $keyvalues block. Sub keys are instances of the same class.


Methods

Function Signature Description
constructor
FindKey CScriptKeyValues FindKey(string key) Find a sub key by the key name.
GetFirstSubKey CScriptKeyValues GetFirstSubKey() Return the first sub key object.
GetKeyBool bool GetKeyBool(string key) Return the key value as a bool.
GetKeyFloat float GetKeyFloat(string key) Return the key value as a float.
GetKeyInt int GetKeyInt(string key) Return the key value as an integer.
GetKeyString string GetKeyString(string key) Return the key value as a string.
GetNextKey handle GetNextKey() Return the next neighbor key object to the one the method is called on.
IsKeyEmpty bool IsKeyEmpty(string key) Returns true if the named key has no value.
IsValid bool IsValid() Whether the handle belongs to a valid entity.
ReleaseKeyValues void ReleaseKeyValues() Releases the contents of the instance.


CSimpleCallChainer

Has the same members as CCallChainer. To do


LateBinder

Late binding: allows a table to refer to parts of itself, it's children, it's owner, and then have the references fixed up after it's fully parsed.

// Usage:
lateBinder <- LateBinder();
lateBinder.Begin( this );

Test1 <-
{   
   Foo=1
}   

Test2 <-
{   
   FooFoo = "I'm foo foo"
   BarBar="@Test1.Foo"
   SubTable = { boo=[bah, "@Test2.FooFoo", "@Test1.Foo"], booboo2={one=bah, two="@Test2.FooFoo", three="@Test1.Foo"} }
   booboo=[bah, "@Test2.FooFoo", "@Test1.Foo"]
   booboo2={one=bah, two="@Test2.FooFoo", three="@Test1.Foo"}
   bah=wha
}   

lateBinder.End();
delete lateBinder;

When End() is called, all of the unresolved symbols in the tables and arrays will be resolved, any left unresolved will become a string prepended with '~', which later code can deal with.


Methods

Function Signature Description
Begin
End
EstablishDelegation
HookRootMetamethod
Log
m_bindNamesStack
m_fixupSet
m_log
m_logIndent
m_targetTable
RemoveDelegation
Resolve
UnhookRootMetamethod


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.


Methods

Function Signature Description
constructor Vector(float x = 0, float y = 0, float z = 0) Creates a new vector with the specified Cartesian coordiantes.
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() Length of the vector.
LengthSqr float LengthSqr() Length of the vector squared. Cheaper than the above method.
Length2D float Length2D() Returns the length of the vector on the x-y plane.
Length2DSqr float Length2DSqr() Returns the square of the length of the vector on the x-y plane. Cheaper than the above method.
Norm float Norm() Normalise the vector, return vector length.
ToKVString string ToKVString() Returns a string without separations commas.


Members

Instance Type Description
x float Cartesian X axis.
y float Cartesian Y axis.
z float Cartesian Z axis.


Global functions

Printing and drawing

Function Signature Description
DebugDrawBox void DebugDrawBox(vector origin, vector mins, vector maxs, int r, int g, int b, int alpha, float duration) Draw a debug overlay box.
DebugDrawLine void DebugDrawLine(Vector start, Vector end, int r, int g, int b', bool noDepthTest, float duration) Draw a debug line between two points.
Msg void Msg(string message) Equivalent to print
print void print(string message) Prints the given message to the developer console.
printl void printl(string message) Prints the given message to the developer console with newline. print( message + "\n" )
ScriptPrintMessageCenterAll void ScriptPrintMessageCenterAll(string message) Prints an alert message in the center of the screen to all players.
ScriptPrintMessageCenterAllWithParams void ScriptPrintMessageCenterAllWithParams(string message, string param1, string param2, string param3) Prints an alert message in the center print method to all players. Needs to pass token/message. param1, param2, param3. Can pass null if you need less than 3.
ScriptPrintMessageCenterTeam void ScriptPrintMessageCenterTeam(int, string) Prints an alert message in the center of the screen to the specified team.
ScriptPrintMessageChatAll void ScriptPrintMessageChatAll(string message) Prints a message in chat to all players.
ScriptPrintMessageChatTeam void ScriptPrintMessageChatTeam(int teamNumber, string message) Prints a message in chat to the specified team.
ShowMessage void ShowMessage(string) Print a hud message on all clients.
Bug.png Bug: Non-functional
__DumpScope void __DumpScope(int indentation, table scope) Dumps contents of everything in the scope.


Training Course

Function Signature Description
ScriptGetBestTrainingCourseTime int ScriptGetBestTrainingCourseTime() Gets the player's best time for completing the timed course.
ScriptGetPlayerCompletedTraining bool ScriptGetPlayerCompletedTraining() Returns true if the player has completed the initial portion of the training map.
ScriptGetValveTrainingCourseTime int ScriptGetValveTrainingCourseTime() Gets Valve's best time for completing the timed course.
ScriptHighlightAmmoCounter void ScriptHighlightAmmoCounter() Sends an event that is just used by the instructor system to show a hint highlighting the ammo counter.
ScriptSetBestTrainingCourseTime void ScriptSetBestTrainingCourseTime(int bestTime) Sets the player's best time for completing the timed course.
ScriptSetMiniScoreHidden void ScriptSetMiniScoreHidden(bool scoreHidden) Toggles the visibility of the miniscoreboard hud element.
ScriptSetPlayerCompletedTraining void ScriptSetPlayerCompletedTraining(bool trainingCompleted) Sets whether the player has completed the initial portion of the training map.
ScriptShowExitDoorMsg void ScriptShowExitDoorMsg() Shows a message box in trainign when the player exits through the exit door
ScriptShowFinishMsgBox void ScriptShowFinishMsgBox() Shows a message box to let players know what to do next after finishing the training course.
ScriptTrainingGivePlayerAmmo void ScriptTrainingGivePlayerAmmo() Refills ammo to max for all weapons the player has (only works in training).


Co-op Strike

Function Signature Description
ScriptCoopCollectBonusCoin void ScriptCoopCollectBonusCoin() Marks one of the bonus coins as collected.
ScriptCoopGiveC4sToCTs void ScriptCoopGiveC4sToCTs(int) Will give the number of specified C4s to all alive CT players.
ScriptCoopMissionGetMissionNumber int ScriptCoopMissionGetMissionNumber() Gets the mission number for the current map - maps can have multiple missions on them.
ScriptCoopMissionRespawnDeadPlayers void ScriptCoopMissionRespawnDeadPlayers() Respawns players only.
ScriptCoopMissionSetNextRespawnIn void ScriptCoopMissionSetNextRespawnIn(float, bool) Set the next respawn wave to happen in this many seconds.
ScriptCoopMissionSpawnFirstEnemies void ScriptCoopMissionSpawnFirstEnemies(int) Spawns the first wave of enemies in coop.
ScriptCoopMissionSpawnNextWave void ScriptCoopMissionSpawnNextWave(int) Tells the next wave of enemies to spawn in coop. Also respawns player.
ScriptCoopResetRoundStartTime void ScriptCoopResetRoundStartTime() Resets the round time and starts the mission.
ScriptCoopSetBotQuotaAndRefreshSpawns void ScriptCoopSetBotQuotaAndRefreshSpawns(int) Sets the bot quota considering the # of players connected and refreshes the spawns.
ScriptCoopExtendRoundDurationTime void ScriptCoopExtendRoundDurationTime(float) Extends the round time after checkpoint during the mission.
ScriptCoopToggleEntityOutlineHighlights void ScriptCoopToggleEntityOutlineHighlights(bool) Highlights all dropped weapons for players, or removes all highlights.


Math

The built-in Squirrel math library.

Function Signature Description
abs int abs(float x) Returns the absolute value of x as an integer.
acos float acos(float x) Returns the arccosine of x.
asin float asin(float x) Returns the arcsine of x.
atan float atan(float x) Returns the arctangent of x.
atan2 float atan2(float x, float y) Returns the arctangent of x/y.
ceil float ceil(float x) Returns a float value representing the smallest integer that is greater than or equal to x.
cos float cos(float x) Returns the cosine of x.
exp float exp(float x) Returns the exponential value of the float parameter x.
fabs float fabs(float x) Returns the absolute value of x as a float.
floor float floor(float x) Returns a float value representing the largest integer that is less than or equal to x.
log float log(float x) Returns the natural logarithm of x.
log10 float log10(float x) Returns the logarithm base-10 of x.
pow float pow(float x, float y) Returns x raised to the power of y.
rand int rand() Returns a pseudorandom integer in the range 0 to RAND_MAX.
sin float sin(float x) Returns the sine of x.
sqrt float sqrt(float x) Returns the square root of x.
srand void srand(float seed) Sets the starting point for generating a series of pseudorandom integers.
tan float tan(float x) Returns the tangent of x.


Other

Function Signature Description
Assert void Assert(bool value, string message = null) Test value and if not true, throws exception, optionally with message.
CreateProp handle CreateProp(string classname, Vector origin, string model, int animation) Create a prop with the specified class and model. Both prop_physics, prop_dynamic as well as some other entity classes with models work. Does not precache the model.
Bug.png Bug: Does not initialize the physics of the prop.
CreateSceneEntity CSceneEntity CreateSceneEntity(string scene) Create a scene entity to play the specified scene .vcd file.
DispatchParticleEffect void DispatchParticleEffect(string particle, Vector position, Vector orientation) Dispatches a one-off particle system.
DoIncludeScript bool DoIncludeScript(string filename, table scope) Execute a script file in the scope of scope.
IncludeScript bool IncludeScript(string filename, table scope = null) Execute a script file in the scope of scope, this by default.
DoEntFire void DoEntFire(string target, string action, string value, float delay, handle activator, handle caller) Generate an entity I/O event.
EntFire function EntFire(string target, string action, string value = "", float delay = 0.0, handle activator = null) Generate an entity I/O event.
EntFireByHandle void EntFireByHandle(handle target, string action, string value, float delay, handle activator, handle caller) Generate an entity I/O event.
FrameTime float FrameTime() Get the time spent on the server in the last frame
GetDeveloperLevel int GetDeveloperLevel() Gets the level of the developer mode. Equivalent to developer()
GetMapName string GetMapName() Get the name of the map.
LoopSinglePlayerMaps bool LoopSinglePlayerMaps() Run the single player maps in a continuous loop.
PrintHelp void PrintHelp(string string = "*", bool exact = false) Output help for script functions, optionally with a search string
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
RecordAchievementEvent void RecordAchievementEvent(string, int) Records achievement event or progress
RetrieveNativeSignature void RetrieveNativeSignature(string nativeFunction)
ScriptGetGameMode int ScriptGetGameMode() Retrieves the set game_mode. See this list for a settings vs modes overview.
ScriptGetGameType int ScriptGetGameType() Retrieves the set game_type. See this list for a settings vs modes overview.
ScriptGetRoundsPlayed int ScriptGetRoundsPlayed() Get the number of rounds played so far.
ScriptIsLocalPlayerUsingController bool ScriptIsLocalPlayerUsingController() Returns whether the player is playing with a controller or not.
ScriptIsWarmupPeriod bool ScriptIsWarmupPeriod() Is it warmup or not.
ScriptSetRadarHidden void ScriptSetRadarHidden(bool hide) Toggles the visibility of the radar hud element. Only works in training mode (game_type 2, game_mode 0) and only for the first person connected.
SendToConsole void SendToConsole(string command) Send a string to the console as a command. The command is executed through the local player.
SendToConsoleServer void SendToConsoleServer(string command) Send a string that gets executed on the server as a ServerCommand
Time float Time() Get the current server time
TraceLine float TraceLine(Vector start, Vector end, handle ignore) given 2 points & ent to ignore, return fraction along line that hits world or models
UniqueString function UniqueString(string = "") Generate a string guaranteed to be unique across the life of the script VM, with an optional root string. Useful for adding data to tables when not sure what keys are already in use in that table.
__ReplaceClosures


See also