List of Portal 2 Script Functions

From Valve Developer Community
Jump to: navigation, search

<Squirrel Language> This list contains all engine-related Squirrel functions available for VScript in [Portal 2] Portal 2. It can be printed in-game with the script_help command while running in tools mode.


Function Signature Description
GetAttachmentAngles Vector CBaseAnimating::GetAttachmentAngles(int id) Get the attachment id's angles as a p,y,r vector.
GetAttachmentOrigin Vector CBaseAnimating::GetAttachmentOrigin(int id) Get the attachment id's origin vector
GetObjectScaleLevel int CBaseAnimating::GetObjectScaleLevel() The scale size of the entity
IsSequenceFinished bool CBaseAnimating::IsSequenceFinished() Ask whether the main sequence is done playing
LookupAttachment int CBaseAnimating::LookupAttachment(string) Get the ID for the named attachment.
SetBodygroup void CBaseAnimating::SetBodygroup(int group, int index) Sets a bodygroup. Group is the index for the desired group, and index is the desired part to use.


Function Signature Description
ConnectOutput void CBaseEntity::ConnectOutput(string output, string func_name) Adds an I/O connection that will call the named function when the specified output fires.
Destroy void CBaseEntity::Destroy() Kill this entity.
DisconnectOutput void CBaseEntity::DisconnectOutput(string output, string func_name) Removes a connected script function from an I/O event.
EmitSound void CBaseEntity::EmitSound(string sound) Plays a sound from this entity.
EyePosition Vector CBaseEntity::EyePosition() Get vector to eye position - absolute coords
FirstMoveChild handle CBaseEntity::FirstMoveChild()
GetAngles Vector CBaseEntity::GetAngles() Get entity pitch, yaw, roll as a vector
GetAngularVelocity Vector CBaseEntity::GetAngularVelocity() Get the local angular velocity - returns a vector of pitch,yaw,roll
GetBoundingMaxs Vector CBaseEntity::GetBoundingMaxs() Get a vector containing max bounds, centered on object
GetBoundingMins Vector CBaseEntity::GetBoundingMins() Get a vector containing min bounds, centered on object
GetCenter Vector CBaseEntity::GetCenter() Get vector to center of object - absolute coords
GetClassname string CBaseEntity::GetClassname() Get the classname of this entity.
GetForwardVector Vector CBaseEntity::GetForwardVector() Get the forward vector of the entity
GetHealth int CBaseEntity::GetHealth()
GetLeftVector Vector CBaseEntity::GetLeftVector() Get the left vector of the entity.
GetMaxHealth int CBaseEntity::GetMaxHealth()
GetModelKeyValues handle CBaseEntity::GetModelKeyValues() Get a KeyValue class instance on this entity's model.
GetModelName string CBaseEntity::GetModelName() Returns the name of the model.
GetMoveParent handle CBaseEntity::GetMoveParent() If in hierarchy, retrieves the entity's parent
GetName string CBaseEntity::GetName() Get the Targetname of this entity.
GetOrigin Vector CBaseEntity::GetOrigin()
GetOwner handle CBaseEntity::GetOwner() Gets this entity's owner
GetPreTemplateName string CBaseEntity::GetPreTemplateName() Get the entity name stripped of template unique decoration
GetRootMoveParent handle CBaseEntity::GetRootMoveParent() If in hierarchy, walks up the hierarchy to find the root parent
GetScriptId string CBaseEntity::GetScriptId() Retrieve the unique identifier used to refer to the entity within the scripting system.
GetScriptScope handle CBaseEntity::GetScriptScope() Retrieve the script-side data associated with an entity.
GetSoundDuration float CBaseEntity::GetSoundDuration(string, string) Returns float duration of the sound. Takes soundname and optional actormodelname.
GetTeam int CBaseEntity::GetTeam()
GetUpVector Vector CBaseEntity::GetUpVector() Get the up vector of the entity.
GetVelocity Vector CBaseEntity::GetVelocity()
IsValid bool CBaseEntity::IsValid() Returns true if this entity is valid.
NextMovePeer handle CBaseEntity::NextMovePeer()
PrecacheSoundScript void CBaseEntity::PrecacheSoundScript(string) Precache a sound for later playing. Should be called in the 'Precache()' hook function.
SetAbsOrigin void CBaseEntity::SetAbsOrigin(Vector) Teleport the entity to this world position.
SetAngles void CBaseEntity::SetAngles(float, float, float) Set entity pitch, yaw, roll
SetAngularVelocity void CBaseEntity::SetAngularVelocity(float, float, float) Set the local angular velocity - takes float pitch,yaw,roll velocities
SetForwardVector void CBaseEntity::SetForwardVector(Vector) Set the orientation of the entity to have this forward vector
SetHealth void CBaseEntity::SetHealth(int)
SetMaxHealth void CBaseEntity::SetMaxHealth(int)
SetModel void CBaseEntity::SetModel(string) Change the model used for the entity. This can be used to change models for prop_weighted_cube or other similar entities. The model must be used elsewhere in the map.
SetOrigin void CBaseEntity::SetOrigin(Vector) Teleport this entity to the given location.
SetOwner void CBaseEntity::SetOwner(handle) Sets this entity's owner
SetSize void CBaseEntity::SetSize(Vector, Vector)
SetTeam void CBaseEntity::SetTeam(int)
SetVelocity void CBaseEntity::SetVelocity(Vector)
ValidateScriptScope bool CBaseEntity::ValidateScriptScope() Ensure that an entity's script scope has been created. This should be called before assigning to the entity's scope.
entindex int CBaseEntity::entindex()


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


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


Function Signature Description
CreateByClassname handle CEntities::CreateByClassname(string) Creates an entity by classname
FindByClassname handle CEntities::FindByClassname(handle start_ent, string classname) Find entities by class name. Pass 'null' to start an iteration, or reference to a previously found entity to continue a search
FindByClassnameNearest handle CEntities::FindByClassnameNearest(string classname, Vector loc, float radius) Find entities by class name nearest to a point.
FindByClassnameWithin handle CEntities::FindByClassnameWithin(handle start_ent, string classname, Vector loc, float radius) Find entities by class name within a radius. Pass 'null' to start an iteration, or reference to a previously found entity to continue a search
FindByModel handle CEntities::FindByModel(handle start_ent, string model) Find entities by model name. Pass 'null' to start an iteration, or reference to a previously found entity to continue a search
FindByName handle CEntities::FindByName(handle start_ent, string targetname) Find entities by name. Pass 'null' to start an iteration, or reference to a previously found entity to continue a search.
FindByNameNearest handle CEntities::FindByNameNearest(string targetname, Vector loc, float radius) Find entities by name nearest to a point.
FindByNameWithin handle CEntities::FindByNameWithin(handle, string, Vector loc, float radius) Find entities by name within a radius. Pass 'null' to start an iteration, or reference to a previously found entity to continue a search
FindByTarget handle CEntities::FindByTarget(handle start_ent, string targetname) Find entities with a specific target keyvalue. Pass 'null' to start an iteration, or reference to a previously found entity to continue a search
FindInSphere handle CEntities::FindInSphere(handle start_ent, Vector loc, float radius) Find entities within a radius. Pass 'null' to start an iteration, or reference to a previously found entity to continue a search
First handle CEntities::First() Begin an iteration over the list of entities. Equivalent to Next(null).
Next handle CEntities::Next(handle) Continue an iteration over the list of entities, providing reference to a previously found entity.


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


Function Signature Description
GetPartnerInstance handle CLinkedPortalDoor::GetPartnerInstance() Get the instance handle of the door's linked partner
GetPartnername string CLinkedPortalDoor::GetPartnername() Returns the partnername of the door.


Function Signature Description
GetPlayerSpeechDuration float CPlayerVoiceListener::GetPlayerSpeechDuration(int) Returns the number of seconds the player has been continuously speaking.
IsPlayerSpeaking bool CPlayerVoiceListener::IsPlayerSpeaking(int) Returns whether the player specified is speaking.


Function Signature Description
GetWheatleyMonitorDestructionCount int CPortal_Player::GetWheatleyMonitorDestructionCount() Get number of wheatley monitors destroyed by the player.
IncWheatleyMonitorDestructionCount void CPortal_Player::IncWheatleyMonitorDestructionCount() Set number of wheatley monitors destroyed by the player.
TurnOffPotatos void CPortal_Player::TurnOffPotatos() Turns Off the Potatos material light
TurnOnPotatos void CPortal_Player::TurnOnPotatos() Turns On the Potatos material light


Function Signature Description
GetPartnerInstance handle CPropLinkedPortalDoor::GetPartnerInstance() Get the instance handle of the door's linked partner
GetPartnername string CPropLinkedPortalDoor::GetPartnername() Returns the partnername of the door.


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


Function Signature Description
FindKey handle CScriptKeyValues::FindKey(string) Given a KeyValues object and a key name, find a KeyValues object associated with the key name
GetFirstSubKey handle CScriptKeyValues::GetFirstSubKey() Given a KeyValues object, return the first sub key object
GetKeyBool bool CScriptKeyValues::GetKeyBool(string) Given a KeyValues object and a key name, return associated bool value
GetKeyFloat float CScriptKeyValues::GetKeyFloat(string) Given a KeyValues object and a key name, return associated float value
GetKeyInt int CScriptKeyValues::GetKeyInt(string) Given a KeyValues object and a key name, return associated integer value
GetKeyString string CScriptKeyValues::GetKeyString(string) Given a KeyValues object and a key name, return associated string value
GetNextKey handle CScriptKeyValues::GetNextKey() Given a KeyValues object, return the next key object in a sub key group
IsKeyEmpty bool CScriptKeyValues::IsKeyEmpty(string) Given a KeyValues object and a key name, return true if key name has no value
ReleaseKeyValues void CScriptKeyValues::ReleaseKeyValues() Given a root KeyValues object, release its contents


Function Signature Description
GetFov int CTriggerCamera::GetFov() get camera's current fov setting as integer
SetFov void CTriggerCamera::SetFov(int, float) set camera's current fov in integer degrees and fov change rate as float

Other functions

Function Signature Description
AddBranchLevelName void AddBranchLevelName(int, string) Adds a level to the specified branch's list.
AddCoopCreditsName void AddCoopCreditsName(string) Adds a name to the coop credit's list.
CreateProp handle CreateProp(string classname, Vector origin, string modelname, int activity) Create a prop. The class should be a prop_physics style entity.
CreateSceneEntity handle CreateSceneEntity(string) Create a scene entity to play the specified scene.
DebugDrawBox void DebugDrawBox(Vector, Vector, Vector, int, int, int, int, float) Draw a debug overlay box
DebugDrawLine void DebugDrawLine(Vector, Vector, int, int, int, bool, float) Draw a debug overlay box
DoIncludeScript bool DoIncludeScript(string, handle) Execute a script (internal). Use 'IncludeScript' instead. Handle should be 'self'.
EntFire function EntFire(target, action, value, delay, activator) Generate and entity i/o event. Value, delay and activator are optional.
EntFireByHandle void EntFireByHandle(handle target, string action, string value, float delay, handle activator, handle caller) Generate an entity i/o event. First parameter is an entity instance.
FrameTime float FrameTime() Get the time spent on the server in the last frame.
GetBluePlayerIndex int GetBluePlayerIndex() Player index of the blue player.
GetCoopBranchLevelIndex int GetCoopBranchLevelIndex(int) Given the 'branch' argument, returns the current chosen level.
GetCoopSectionIndex int GetCoopSectionIndex() Section that the coop players have selected to load.
GetDeveloperLevel int GetDeveloperLevel() Gets the level of 'developer'.
GetHighestActiveBranch int GetHighestActiveBranch() Returns which branches should be available in the hub.
GetMapName string GetMapName() Get the name of the map.
GetOrangePlayerIndex int GetOrangePlayerIndex() Player index of the orange player.
GetPlayer handle GetPlayer() Returns the player (SP Only).
GetPlayerSilenceDuration float GetPlayerSilenceDuration(int player_index) Time that the specified player has been silent on the mic.
IncludeScript bool IncludeScript(string name, handle scope) Execute the given script filename in a scope (defaulting to 'self').
IsLevelComplete bool IsLevelComplete(int course, int level) Returns true if the level in the specified course is completed by either player.
IsMultiplayer bool IsMultiplayer() Is this a multiplayer game?
IsPlayerLevelComplete bool IsPlayerLevelComplete(int, int, int) Returns true if the level in the specified branch is completed by a specific player.
LoopSinglePlayerMaps bool LoopSinglePlayerMaps() Run the single player maps in a continuous loop.
MarkMapComplete void MarkMapComplete(string) Marks a maps a complete for both players.
PrecacheMovie void PrecacheMovie(string) Precaches a named movie. Only valid to call within the entity's 'Precache' function called on mapspawn.
RandomFloat float RandomFloat(float min, float max) Generate a random floating point number within a range, inclusive
RandomInt int RandomInt(int min, int max) Generate a random integer within a range, inclusive
RecordAchievementEvent void RecordAchievementEvent(string name, int player_index) "Earns" a given achievement or increases progress.
ScriptShowHudMessageAll void ScriptShowHudMessageAll(string, float) Show center print text message.
ScriptSteamShowURL bool ScriptSteamShowURL(string) Bring up the steam overlay and shows the specified URL. (Full address with protocol type is required, e.g.
SendToConsole void SendToConsole(string command) Send a string to the console as a command.
SetDucking void SetDucking(string, string, float) Set the level of an audio ducking channel
ShowMessage void ShowMessage(string) Print a hud message on all clients
Time float Time() Get the current server time
TraceLine float TraceLine(Vector start, Vector end, handle ignored_ent) 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.

Introduced in "Peer Review"

These were introduced in Portal 2's first DLC, "Peer Review", as a measure against cheating.

Function Signature Description
TryDLC1InstalledOrCatch void TryDLC1InstalledOrCatch() Throws an exception if "Peer Review" isn't installed.
GivePlayerPortalgun void GivePlayerPortalgun() Equips the player with a blue-only portalgun.
UpgradePlayerPortalgun void UpgradePlayerPortalgun() Upgrades the player's portalgun to shoot orange portals.
UpgradePlayerPotatogun void UpgradePlayerPotatogun() Upgrades the player's portalgun to shoot orange portals and have PotatOS impaled on it.

See also