本文与游戏《传送门2》有关。点击这里查看更多信息。
This article relates to "Squirrel". Click here for more information.

Zh/Portal 2/Scripting/Script Functions: Difference between revisions

From Valve Developer Community
< Zh‎ | Portal 2
Jump to navigation Jump to search
(Created page with "{{LanguageBar|List of Portal 2 Script Functions|title=''​ Portal 2 ​''脚本函数列表}} {{p2 topicon}}{{SQ topicon}} {{toc-right}} 此列表包含可用于的所有与{{Portal2|4}}游戏引擎相关的松鼠函数用于{{L|VScript}}。 当在{{L|Engine tools|工具模式}}运行游戏时可以使用<code>script_help</code>指令在控制台打印出来这些。 == 变量 == {| class="standard-table" !实例 !类型 !描述 |- |<code>Entities</code> |<code>#CEn...")
 
 
(20 intermediate revisions by the same user not shown)
Line 3: Line 3:
{{toc-right}}
{{toc-right}}


此列表包含可用于的所有与{{Portal2|4}}游戏引擎相关的松鼠函数用于{{L|VScript}}。 当在{{L|Engine tools|工具模式}}运行游戏时可以使用<code>script_help</code>指令在控制台打印出来这些。
此列表包含可用于的所有与{{Portal2|4}}{{L|VScript}}游戏引擎的{{L|Squirrel|松鼠}}函数。 当游戏在{{L|Engine tools|工具模式}}运行时可以使用<code>script_help</code>指令在控制台打印出来这些。


== 变量 ==
== 变量 ==
Line 55: Line 55:
=== CBaseEntity ===
=== CBaseEntity ===
这是实体的脚本句柄类。所有生成的实体都有一个使用此或其子类之一的脚本句柄。
这是实体的脚本句柄类。所有生成的实体都有一个使用此或其子类之一的脚本句柄。
 
游戏中的所有脚本句柄都可以从[[#CEntities|Entities]]访问实体脚本, 可以使用<code>self</code>关键字访问自己的脚本句柄。<code>activator</code><code>caller</code>关键字可以在函数调用时访问。
All script handles in-game are accessible from {{L|#CEntities|Entities}}。 Entity scripts can use <code>self</code> to access their own script handle. <code>activator</code> and <code>caller</code> variables can be accessed on function calls.
==== 使用方法 ====
 
{|class="standard-table" style="width: 100%;"
 
!函数
==== Methods ====
!特征用法
{| class="standard-table" style="width: 100%;"
!描述
! Function
! Signature
! Description
|-
|-
| <code>__KeyValueFromInt</code>
| <code>__KeyValueFromInt</code>
| <code>void __KeyValueFromInt(string ''key'', int ''value'')</code>
| <code>void __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.
| 设置实体的某个{{L|Keyvalue}}为整数。它只更改值, 但不会执行实体处理KeyValue所需的任何代码, 因此可能会产生意想不到的副作用。
|-
|-
| <code>__KeyValueFromFloat</code>
| <code>__KeyValueFromFloat</code>
| <code>void __KeyValueFromFloat(string ''key'', float ''value'')</code>
| <code>void __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.
| 设置实体的某个{{L|Keyvalue}}为浮点数。它只更改值, 但不会执行实体处理KeyValue所需的任何代码, 因此可能会产生意想不到的副作用。
|-
|-
| <code>__KeyValueFromString</code>
| <code>__KeyValueFromString</code>
| <code>void __KeyValueFromString(string ''key'', string ''value'')</code>
| <code>void __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.
| 设置实体的某个{{L|Keyvalue}}为字符串。它只更改值, 但不会执行实体处理KeyValue所需的任何代码, 因此可能会产生意想不到的副作用。
|-
|-
| <code>__KeyValueFromVector</code>
| <code>__KeyValueFromVector</code>
| <code>void __KeyValueFromVector(string ''key'', Vector ''value'')</code>
| <code>void __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.
| 设置实体的某个{{L|Keyvalue}}为{{L|Vector|向量}}。它只更改值, 但不会执行实体处理KeyValue所需的任何代码, 因此可能会产生意想不到的副作用。
|-
|-
| <code>ConnectOutput</code>
| <code>ConnectOutput</code>
| <code>void CBaseEntity::ConnectOutput(string output, string func_name)</code>
| <code>void CBaseEntity::ConnectOutput(string output, string func_name)</code>
| Adds an I/O connection that will call the named function when the specified output fires.
| 添加一个I/O连接, 当指定的输出触发时, 该连接将调用指定的函数。
|-
|-
| <code>Destroy</code>
| <code>Destroy</code>
| <code>void CBaseEntity::Destroy()</code>
| <code>void CBaseEntity::Destroy()</code>
| Kill this entity.
| 消灭这个实体。
|-
|-
| <code>DisconnectOutput</code>
| <code>DisconnectOutput</code>
| <code>void CBaseEntity::DisconnectOutput(string output, string func_name)</code>
| <code>void CBaseEntity::DisconnectOutput(string output, string func_name)</code>
| Removes a connected script function from an I/O event.
| 从I/O事件中删除连接的脚本函数。
|-
|-
| <code>EmitSound</code>
| <code>EmitSound</code>
| <code>void CBaseEntity::EmitSound(string sound)</code>
| <code>void CBaseEntity::EmitSound(string sound)</code>
| Plays a sound from this entity.
| 从该实体处播放一段声音。
|-
|-
| <code>EyePosition</code>
| <code>EyePosition</code>
| <code>Vector CBaseEntity::EyePosition()</code>
| <code>Vector CBaseEntity::EyePosition()</code>
| Get vector to eye position - absolute coords.
| 获得眼睛位置绝对坐标的向量。
|-
|-
| <code>FirstMoveChild</code>
| <code>FirstMoveChild</code>
| <code>handle CBaseEntity::FirstMoveChild()</code>
| <code>handle CBaseEntity::FirstMoveChild()</code>
| If in hierarchy, get the first move child.
| 如果处于层次结构中,则获取则检索第一个(移动)实体的子级。
|-
|-
| <code>GetAngles</code>
| <code>GetAngles</code>
| <code>Vector CBaseEntity::GetAngles()</code>
| <code>Vector CBaseEntity::GetAngles()</code>
| Get entity pitch, yaw, roll as a vector.
| 获得实体转换为向量的俯仰、水平、横滚的角度数值。
|-
|-
| <code>GetAngularVelocity</code>
| <code>GetAngularVelocity</code>
| <code>Vector CBaseEntity::GetAngularVelocity()</code>
| <code>Vector CBaseEntity::GetAngularVelocity()</code>
| Get the local angular velocity - returns a vector of pitch,yaw,roll.
| 获取局部角速度-返回俯仰、水平、横滚的向量。
|-
|-
| <code>GetBoundingMaxs</code>
| <code>GetBoundingMaxs</code>
| <code>Vector CBaseEntity::GetBoundingMaxs()</code>
| <code>Vector CBaseEntity::GetBoundingMaxs()</code>
| Get a vector containing max bounds, centered on object.
| 获取一个以对象为中心的最大边框的向量。
|-
|-
| <code>GetBoundingMins</code>
| <code>GetBoundingMins</code>
| <code>Vector CBaseEntity::GetBoundingMins()</code>
| <code>Vector CBaseEntity::GetBoundingMins()</code>
| Get a vector containing min bounds, centered on object.
| 获取一个以对象为中心的最小边框的向量。
|-
|-
| <code>GetCenter</code>
| <code>GetCenter</code>
| <code>Vector CBaseEntity::GetCenter()</code>
| <code>Vector CBaseEntity::GetCenter()</code>
| Get vector to center of object - absolute coords.
| 获取对象中心的向量-绝对坐标。
|-
|-
| <code>GetClassname</code>
| <code>GetClassname</code>
| <code>string CBaseEntity::GetClassname()</code>
| <code>string CBaseEntity::GetClassname()</code>
| Get the classname of this entity.
| 获取此实体的类名。
|-
|-
| <code>GetForwardVector</code>
| <code>GetForwardVector</code>
| <code>Vector CBaseEntity::GetForwardVector()</code>
| <code>Vector CBaseEntity::GetForwardVector()</code>
| Get the forward vector (+X) of the entity.
| 获取实体的正向向量(+X)。
|-
|-
| <code>GetHealth</code>
| <code>GetHealth</code>
| <code>int CBaseEntity::GetHealth()</code>
| <code>int CBaseEntity::GetHealth()</code>
| Returns the current [[health]].
| 返回实体当前{{L|health|血量}}。
|-
|-
| <code>GetLeftVector</code>
| <code>GetLeftVector</code>
| <code>Vector CBaseEntity::GetLeftVector()</code>
| <code>Vector CBaseEntity::GetLeftVector()</code>
| Get the left vector of the entity.
| 获取实体的左向量。
|-
|-
| <code>GetMaxHealth</code>
| <code>GetMaxHealth</code>
| <code>int CBaseEntity::GetMaxHealth()</code>
| <code>int CBaseEntity::GetMaxHealth()</code>
| Returns the maximum health.
| 返回实体最大血量。
|-
|-
| <code>GetModelKeyValues</code>
| <code>GetModelKeyValues</code>
| <code>handle CBaseEntity::GetModelKeyValues()</code>
| <code>handle CBaseEntity::GetModelKeyValues()</code>
| Get a KeyValue class instance on this entity's model.
| 获取此实体模型上的键值类实例。
|-
|-
| <code>GetModelName</code>
| <code>GetModelName</code>
| <code>string CBaseEntity::GetModelName()</code>
| <code>string CBaseEntity::GetModelName()</code>
| Returns the name of the model.
| 获取该实体模型名称。
|-
|-
| <code>GetMoveParent</code>
| <code>GetMoveParent</code>
| <code>handle CBaseEntity::GetMoveParent()</code>
| <code>handle CBaseEntity::GetMoveParent()</code>
| If in hierarchy, retrieves the entity's parent.
| 如果处于层次结构中, 则检索实体的父级。
|-
|-
| <code>GetName</code>
| <code>GetName</code>
| <code>string CBaseEntity::GetName()</code>
| <code>string CBaseEntity::GetName()</code>
| Get the Targetname of this entity.
| 获取此实体的Targetname。
|-
|-
| <code>GetOrigin</code>
| <code>GetOrigin</code>
| <code>Vector CBaseEntity::GetOrigin()</code>
| <code>Vector CBaseEntity::GetOrigin()</code>
| Returns this entity's local origin.
| 返回此实体的局部原点位置坐标。
|-
|-
| <code>GetOwner</code>
| <code>GetOwner</code>
| <code>handle CBaseEntity::GetOwner()</code>
| <code>handle CBaseEntity::GetOwner()</code>
| Gets this entity's owner.
| 获取此实体的所有者。
|-
|-
| <code>GetPreTemplateName</code>
| <code>GetPreTemplateName</code>
| <code>string CBaseEntity::GetPreTemplateName()</code>
| <code>string CBaseEntity::GetPreTemplateName()</code>
| Get the entity name stripped of template unique decoration - the &001 suffix.
| 将实体名称从模板唯一装饰(&001后缀)中删除。
|-
|-
| <code>GetRootMoveParent</code>
| <code>GetRootMoveParent</code>
| <code>handle CBaseEntity::GetRootMoveParent()</code>
| <code>handle CBaseEntity::GetRootMoveParent()</code>
| If in hierarchy, walks up the hierarchy to find the root parent
| 如果处于层次结构中, 则向上遍历层次结构以查找根父级
|-
|-
| <code>GetScriptId</code>
| <code>GetScriptId</code>
| <code>string CBaseEntity::GetScriptId()</code>
| <code>string CBaseEntity::GetScriptId()</code>
| Retrieve the unique identifier used to refer to the entity within the scripting system.
| 检索用于引用脚本系统中实体的唯一标识符。
|-
|-
| <code>GetScriptScope</code>
| <code>GetScriptScope</code>
| <code>handle CBaseEntity::GetScriptScope()</code>
| <code>handle CBaseEntity::GetScriptScope()</code>
| Retrieve the script-side data associated with an entity.
| 检索与实体关联的脚本端数据。
|-
|-
| <code>GetSoundDuration</code>
| <code>GetSoundDuration</code>
| <code>float CBaseEntity::GetSoundDuration(string, string)</code>
| <code>float CBaseEntity::GetSoundDuration(string, string)</code>
| Returns float duration of the sound. Takes soundname and optional actormodelname.
| 以浮点数返回声音的持续时间。接受声音名称和可选的actormodelname。
|-
|-
| <code>GetTeam</code>
| <code>GetTeam</code>
| <code>int CBaseEntity::GetTeam()</code>
| <code>int CBaseEntity::GetTeam()</code>
| Get the team this entity is on.
| 找到这个实体所在的队伍。
|-
|-
| <code>GetUpVector</code>
| <code>GetUpVector</code>
| <code>Vector CBaseEntity::GetUpVector()</code>
| <code>Vector CBaseEntity::GetUpVector()</code>
| Get the up vector (+Z) of the entity.
| 获取实体的向上向量(+Z)。
|-
|-
| <code>GetVelocity</code>
| <code>GetVelocity</code>
| <code>Vector CBaseEntity::GetVelocity()</code>
| <code>Vector CBaseEntity::GetVelocity()</code>
| Get the velocity of the entity. Note that this reads the [[QPhysics]] velocity value, so it only works for players, NPCs and moving brush entities. VPhysics objects always have a velocity of zero. A workaround is to record the position over multiple frames, and derive the velocity manually.
| 获取实体的速度。请注意,这会读取{{L|QPhysics}}速度值, 因此它仅适用于玩家、NPC和移动画笔实体。VPhysics对象的速度始终为零, 一种解决方法是记录多个帧上的位置, 并手动推导速度。
|-
|-
| <code>IsValid</code>
| <code>IsValid</code>
| <code>bool CBaseEntity::IsValid()</code>
| <code>bool CBaseEntity::IsValid()</code>
| Returns true if this entity is valid.
| 如果此实体有效, 则返回true。
|-
|-
| <code>NextMovePeer</code>
| <code>NextMovePeer</code>
| <code>handle CBaseEntity::NextMovePeer()</code>
| <code>handle CBaseEntity::NextMovePeer()</code>
| Return the next entity in the same movement hierarchy.
| 返回同一继承层次结构中的下一个实体。
|-
|-
| <code>PrecacheSoundScript</code>
| <code>PrecacheSoundScript</code>
| <code>void CBaseEntity::PrecacheSoundScript(string)</code>
| <code>void CBaseEntity::PrecacheSoundScript(string)</code>
| Precache a sound for later playing. Should be called in the 'Precache()' hook function.
| 预先加载一个声音以供以后播放, 应该在''Preche()''钩子函数中调用。
|-
|-
| <code>SetAbsOrigin</code>
| <code>SetAbsOrigin</code>
| <code>void CBaseEntity::SetAbsOrigin(Vector)</code>
| <code>void CBaseEntity::SetAbsOrigin(Vector)</code>
| Teleport the entity to this world position.
| 将实体传送到此世界位置。
|-
|-
| <code>SetAngles</code>
| <code>SetAngles</code>
| <code>void CBaseEntity::SetAngles(float, float, float)</code>
| <code>void CBaseEntity::SetAngles(float, float, float)</code>
| Set entity pitch, yaw, roll
| 设置实体俯仰、水平、横滚。
|-
|-
| <code>SetAngularVelocity</code>
| <code>SetAngularVelocity</code>
| <code>void CBaseEntity::SetAngularVelocity(float, float, float)</code>
| <code>void CBaseEntity::SetAngularVelocity(float, float, float)</code>
| Set the local angular velocity - takes float pitch,yaw,roll velocities
| 设置局部角速度-浮点数的俯仰、水平、横滚速度。
|-
|-
| <code>SetForwardVector</code>
| <code>SetForwardVector</code>
| <code>void CBaseEntity::SetForwardVector(Vector)</code>
| <code>void CBaseEntity::SetForwardVector(Vector)</code>
| Set the orientation of the entity to have this forward (+X) vector.
| 将实体的正向(+X)向量。
|-
|-
| <code>SetHealth</code>
| <code>SetHealth</code>
| <code>void CBaseEntity::SetHealth(int)</code>
| <code>void CBaseEntity::SetHealth(int)</code>
| Sets the current [[health]].
| 设置实体当前的{{L|health|血量}}。
|-
|-
| <code>SetMaxHealth</code>
| <code>SetMaxHealth</code>
| <code>void CBaseEntity::SetMaxHealth(int)</code>
| <code>void CBaseEntity::SetMaxHealth(int)</code>
| Sets the maximum health.
| 设置实体最大血量。
|-
|-
| <code>SetModel</code>
| <code>SetModel</code>
| <code>void CBaseEntity::SetModel(string)</code>
| <code>void CBaseEntity::SetModel(string)</code>
| 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 precached, which is usually done by placing it elsewhere in the map.
| 更改实体的模型, 这可用于更改prop_weighted_cube或其他类似实体的模型。模型必须预加载, 可以通过预先放置在地图的其他位置来完成。
|-
|-
| <code>SetOrigin</code>
| <code>SetOrigin</code>
| <code>void CBaseEntity::SetOrigin(Vector)</code>
| <code>void CBaseEntity::SetOrigin(Vector)</code>
| Teleport this entity to the given location.
| 将此实体传送到给定位置。
|-
|-
| <code>SetOwner</code>
| <code>SetOwner</code>
| <code>void CBaseEntity::SetOwner(handle)</code>
| <code>void CBaseEntity::SetOwner(handle)</code>
| Sets this entity's owner.
| 设置实体的所有者。
|-
|-
| <code>SetSize</code>
| <code>SetSize</code>
| <code>void CBaseEntity::SetSize(Vector, Vector)</code>
| <code>void CBaseEntity::SetSize(Vector, Vector)</code>
| Sets the bounding box size.
| 设置边界框大小。(比如func_brush或trigger_multiple)
|-
|-
| <code>SetTeam</code>
| <code>SetTeam</code>
| <code>void CBaseEntity::SetTeam(int)</code>
| <code>void CBaseEntity::SetTeam(int)</code>
| Set the team this entity is on.
| 设置此实体所在的队伍。
|-
|-
| <code>SetVelocity</code>
| <code>SetVelocity</code>
| <code>void CBaseEntity::SetVelocity(Vector)</code>
| <code>void CBaseEntity::SetVelocity(Vector)</code>
| Set local velocity.  Note that this sets the [[QPhysics]] velocity value, so it only works for players, NPCs and moving brush entities. On VPhysics objects, this has no effect.
| 设置局部速度。请注意,这会设置{{L|QPhysics}}速度值,因此它仅适用于玩家、NPC和移动画笔实体。对于VPhysics对象,这没有影响。
|-
|-
| <code>ValidateScriptScope</code>
| <code>ValidateScriptScope</code>
| <code>bool CBaseEntity::ValidateScriptScope()</code>
| <code>bool CBaseEntity::ValidateScriptScope()</code>
| Ensure that an entity's script scope has been created. This should be called before assigning to the entity's scope.
| 确保已创建实体的脚本作用域。 在分配给实体的作用域之前, 应该调用此函数。
|-
|-
| <code>entindex</code>
| <code>entindex</code>
| <code>int CBaseEntity::entindex()</code>
| <code>int CBaseEntity::entindex()</code>
| Returns the entity index.
| 返回实体的索引值。
|}
|}


=== CBaseAnimating ===
=== CBaseAnimating ===
Extends [[#CBaseEntity|CBaseEntity]]
继承 [[#CBaseEntity|CBaseEntity]]


Script handle class for animating entities such as props.
用于为道具等实体设置动画的脚本句柄类。


{{LanguageBar|Methods|title=使用方法}}


==== Methods ====
==== 使用方法 ====
{| class="standard-table" style="width: 100%;"
{| class="standard-table" style="width: 100%;"
! Function
! 函数
! Signature
! 签名
! Description
! 描述
|-
|-
| <code>GetAttachmentAngles</code>
| <code>GetAttachmentAngles</code>
| <code>Vector CBaseAnimating::GetAttachmentAngles(int id)</code>
| <code>Vector CBaseAnimating::GetAttachmentAngles(int id)</code>
| Get the attachment id's angles as a p,y,r vector.
| 获取附件ID的角度(p,y,r向量)。
|-
|-
| <code>GetAttachmentOrigin</code>
| <code>GetAttachmentOrigin</code>
| <code>Vector CBaseAnimating::GetAttachmentOrigin(int id)</code>
| <code>Vector CBaseAnimating::GetAttachmentOrigin(int id)</code>
| Get the attachment id's origin vector
| 获取附件ID的原始向量。
|-
|-
| <code>GetObjectScaleLevel</code>
| <code>GetObjectScaleLevel</code>
| <code>int CBaseAnimating::GetObjectScaleLevel()</code>
| <code>int CBaseAnimating::GetObjectScaleLevel()</code>
| The scale size of the entity
| 获取实体的缩放级别。
|-
|-
| <code>IsSequenceFinished</code>
| <code>IsSequenceFinished</code>
| <code>bool CBaseAnimating::IsSequenceFinished()</code>
| <code>bool CBaseAnimating::IsSequenceFinished()</code>
| Ask whether the main sequence is done playing
| 检查主序列是否播放完毕。
|-
|-
| <code>LookupAttachment</code>
| <code>LookupAttachment</code>
| <code>int CBaseAnimating::LookupAttachment(string)</code>
| <code>int CBaseAnimating::LookupAttachment(string)</code>
| Get the ID for the named attachment.
| 获取命名附件的ID。
|-
|-
| <code>SetBodygroup</code>
| <code>SetBodygroup</code>
| <code>void CBaseAnimating::SetBodygroup(int group, int index)</code>
| <code>void CBaseAnimating::SetBodygroup(int group, int index)</code>
| Sets a bodygroup. Group is the index for the desired group, and index is the desired part to use.
| 设置身体组。group是目标组的索引,index是要使用的部位索引。
|}
|}


=== CBaseFlex ===
=== CBaseFlex ===
Extends [[#CBaseAnimating|CBaseAnimating]]
继承 [[#CBaseAnimating|CBaseAnimating]]
 


==== Methods ====
==== 使用方法 ====
{| class="standard-table" style="width: 100%;"
{| class="standard-table" style="width: 100%;"
! Function
! 函数
! Signature
! 签名
! Description
! 描述
|-
|-
| <code>GetCurrentScene</code>
| <code>GetCurrentScene</code>
| <code>handle CBaseFlex::GetCurrentScene()</code>
| <code>handle CBaseFlex::GetCurrentScene()</code>
| Returns the instance of the oldest active scene entity (if any).
| 返回最早激活的场景实体实例(如果有)。
|-
|-
| <code>GetSceneByIndex</code>
| <code>GetSceneByIndex</code>
| <code>handle CBaseFlex::GetSceneByIndex(int)</code>
| <code>handle CBaseFlex::GetSceneByIndex(int)</code>
| Returns the instance of the scene entity at the specified index.
| 返回指定索引的场景实体实例。
|}
|}


=== CBasePlayer ===
=== CBasePlayer ===
Extends [[#CBaseAnimating|CBaseAnimating]]
继承 [[#CBaseAnimating|CBaseAnimating]]
 


==== Methods ====
==== 使用方法 ====
{| class="standard-table" style="width: 100%;"
{| class="standard-table" style="width: 100%;"
! Function
! 函数
! Signature
! 签名
! Description
! 描述
|-
|-
| <code>IsNoclipping</code>
| <code>IsNoclipping</code>
| <code>bool CBasePlayer::IsNoclipping()</code>
| <code>bool CBasePlayer::IsNoclipping()</code>
| Returns true if the player is in noclip mode.
| 如果玩家处于穿墙模式则返回true。
|}
|}


=== CEntities ===
=== CEntities ===
Script instance: <code>Entities</code>
脚本实例: <code>Entities</code>


An interface to find and iterate over the script handles for the entities in play.
用于查找和迭代游戏中实体的脚本接口。


To iterate over a set of entities, pass <code>null</code> to the ''previous'' argument in the appropriate method to start an iteration, or reference to a previously found entity to continue a search. Example:
要迭代一组实体,请在适当的方法中将<code>null</code>传递给"previous"参数以开始迭代,或引用先前找到的实体以继续搜索。示例:
<source lang=cpp>
<source lang=cpp>
//The first way
//第一种方式
local ent = null;    //The variable name "ent" is arbitrary.
local ent = null;    //变量名"ent"可自定义
while(ent = Entities.FindByName(ent, "entityname"))    //Indeed, we mean '=' and not '==' ! The loop aborts if "ent" becomes null.
while(ent = Entities.FindByName(ent, "entityname"))    //注意使用"="而非"=="
{
{
   //...    //In every iteration, "ent" is not null.
   //...    //每次迭代时"ent"有效则执行此处代码
}
}


//The second way
//第二种方式
for(local ent;ent = Entities.FindByName(ent, "entityname");)    //The variable name "ent" is arbitrary. Indeed, we mean '=' and not '==' ! The loop aborts if "ent" becomes null. (All the semicolons are correctly placed)
for(local ent;ent = Entities.FindByName(ent, "entityname");)    //注意分号位置
{
{
   //...    //In every iteration, "ent" is not null.
   //...    //每次迭代时"ent"有效则执行此处代码
}
}
</source>
</source>


 
==== 使用方法 ====
==== Methods ====
{| class="standard-table" style="width: 100%;"
{| class="standard-table" style="width: 100%;"
! Function
! 函数
! Signature
! 签名
! Description
! 描述
|-
|-
| <code>CreateByClassname</code>
| <code>CreateByClassname</code>
| <code>handle CEntities::CreateByClassname(string)</code>
| <code>handle CEntities::CreateByClassname(string)</code>
| Creates an entity by classname
| 通过类名创建实体
|-
|-
| <code>FindByClassname</code>
| <code>FindByClassname</code>
| <code>handle CEntities::FindByClassname(handle start_ent, string classname)</code>
| <code>handle CEntities::FindByClassname(handle start_ent, string classname)</code>
| Find entities by class name. Pass 'null' to start an iteration, or reference to a previously found entity to continue a search
| 按类名查找实体。传递'null'开始迭代,或引用先前找到的实体继续搜索
|-
|-
| <code>FindByClassnameNearest</code>
| <code>FindByClassnameNearest</code>
| <code>handle CEntities::FindByClassnameNearest(string classname, Vector loc, float radius)</code>
| <code>handle CEntities::FindByClassnameNearest(string classname, Vector loc, float radius)</code>
| Find entities by class name nearest to a point.
| 查找距离某点最近的指定类名实体
|-
|-
| <code>FindByClassnameWithin</code>
| <code>FindByClassnameWithin</code>
| <code>handle CEntities::FindByClassnameWithin(handle start_ent, string classname, Vector loc, float radius)</code>
| <code>handle CEntities::FindByClassnameWithin(handle start_ent, string classname, Vector loc, float radius)</code>
| 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
| 查找半径内的指定类名实体。传递'null'开始迭代
|-
|-
| <code>FindByModel</code>
| <code>FindByModel</code>
| <code>handle CEntities::FindByModel(handle start_ent, string model)</code>
| <code>handle CEntities::FindByModel(handle start_ent, string model)</code>
| Find entities by model name. Pass 'null' to start an iteration, or reference to a previously found entity to continue a search
| 按模型名查找实体。传递'null'开始迭代
|-
|-
| <code>FindByName</code>
| <code>FindByName</code>
| <code>handle CEntities::FindByName(handle start_ent, string targetname)</code>
| <code>handle CEntities::FindByName(handle start_ent, string targetname)</code>
| Find entities by name (including wildcards). Pass 'null' to start an iteration, or reference to a previously found entity to continue a search.
| 按名称(支持通配符)查找实体。传递'null'开始迭代
|-
|-
| <code>FindByNameNearest</code>
| <code>FindByNameNearest</code>
| <code>handle CEntities::FindByNameNearest(string targetname, Vector loc, float radius)</code>
| <code>handle CEntities::FindByNameNearest(string targetname, Vector loc, float radius)</code>
| Find entities by name nearest to a point.
| 查找距离某点最近的指定名称实体
|-
|-
| <code>FindByNameWithin</code>
| <code>FindByNameWithin</code>
| <code>handle CEntities::FindByNameWithin(handle, string, Vector loc, float radius)</code>
| <code>handle CEntities::FindByNameWithin(handle, string, Vector loc, float radius)</code>
| Find entities by name within a radius. Pass 'null' to start an iteration, or reference to a previously found entity to continue a search
| 查找半径内的指定名称实体。传递'null'开始迭代
|-
|-
| <code>FindByTarget</code>
| <code>FindByTarget</code>
| <code>handle CEntities::FindByTarget(handle start_ent, string targetname)</code>
| <code>handle CEntities::FindByTarget(handle start_ent, string targetname)</code>
| Find entities with a specific <code>target</code> keyvalue. Pass 'null' to start an iteration, or reference to a previously found entity to continue a search
| 查找具有特定<code>target</code>键值的实体。传递'null'开始迭代
|-
|-
| <code>FindInSphere</code>
| <code>FindInSphere</code>
| <code>handle CEntities::FindInSphere(handle start_ent, Vector loc, float radius)</code>
| <code>handle CEntities::FindInSphere(handle start_ent, Vector loc, float radius)</code>
| Find entities within a radius. Pass 'null' to start an iteration, or reference to a previously found entity to continue a search
| 查找半径内的实体。传递'null'开始迭代
|-
|-
| <code>First</code>
| <code>First</code>
| <code>handle CEntities::First()</code>
| <code>handle CEntities::First()</code>
| Begin an iteration over the list of entities. Equivalent to Next(null).
| 开始实体列表迭代。等同于Next(null)
|-
|-
| <code>Next</code>
| <code>Next</code>
| <code>handle CEntities::Next(handle)</code>
| <code>handle CEntities::Next(handle)</code>
| Continue an iteration over the list of entities, providing reference to a previously found entity.
| 继续迭代,需提供先前找到的实体引用
|}
|}


=== CEnvEntityMaker ===
=== CEnvEntityMaker ===
Extends [[#CBaseEntity|CBaseEntity]]
继承 [[#CBaseEntity|CBaseEntity]]
 
Script handle class for [[env_entity_maker]].


脚本句柄类是{{L|env_entity_maker}}。


==== Methods ====
==== 使用方法 ====
{| class="standard-table" style="width: 100%;"
{| class="standard-table" style="width: 100%;"
! Function
! 函数
! Signature
! 签名
! Description
! 描述
|-
|-
| <code>SpawnEntity</code>
| <code>SpawnEntity</code>
| <code>void CEnvEntityMaker::SpawnEntity()</code>
| <code>void CEnvEntityMaker::SpawnEntity()</code>
| Create an entity at the location of the maker
| 在maker位置创建实体
|-
|-
| <code>SpawnEntityAtEntityOrigin</code>
| <code>SpawnEntityAtEntityOrigin</code>
| <code>void CEnvEntityMaker::SpawnEntityAtEntityOrigin(handle)</code>
| <code>void CEnvEntityMaker::SpawnEntityAtEntityOrigin(handle)</code>
| Create an entity at the location of a specified entity instance
| 在指定实体位置创建实体
|-
|-
| <code>SpawnEntityAtLocation</code>
| <code>SpawnEntityAtLocation</code>
| <code>void CEnvEntityMaker::SpawnEntityAtLocation(Vector, Vector)</code>
| <code>void CEnvEntityMaker::SpawnEntityAtLocation(Vector, Vector)</code>
| Create an entity at a specified location and orientaton, orientation is Euler angle in degrees (pitch, yaw, roll)
| 在指定位置和角度创建实体
|-
|-
| <code>SpawnEntityAtNamedEntityOrigin</code>
| <code>SpawnEntityAtNamedEntityOrigin</code>
| <code>void CEnvEntityMaker::SpawnEntityAtNamedEntityOrigin(string)</code>
| <code>void CEnvEntityMaker::SpawnEntityAtNamedEntityOrigin(string)</code>
| Create an entity at the location of a named entity
| 在命名实体位置创建实体
|}
|}


=== CLinkedPortalDoor ===
=== CLinkedPortalDoor ===
{{todo}}
{{todo}}


 
==== 使用方法 ====
==== Methods ====
{| class="standard-table" style="width: 100%;"
{| class="standard-table" style="width: 100%;"
! Function
! 函数
! Signature
! 签名
! Description
! 描述
|-
|-
| <code>GetPartnerInstance</code>
| <code>GetPartnerInstance</code>
| <code>handle CLinkedPortalDoor::GetPartnerInstance()</code>
| <code>handle CLinkedPortalDoor::GetPartnerInstance()</code>
| Get the instance handle of the door's linked partner
| 获取门链接伙伴的实例句柄
|-
|-
| <code>GetPartnername</code>
| <code>GetPartnername</code>
| <code>string CLinkedPortalDoor::GetPartnername()</code>
| <code>string CLinkedPortalDoor::GetPartnername()</code>
| Returns the partnername of the door.
| 返回门的伙伴名称
|}
|}


=== CPlayerVoiceListener ===
=== CPlayerVoiceListener ===
{{todo}}
{{todo}}


 
==== 使用方法 ====
==== Methods ====
{| class="standard-table" style="width: 100%;"
{| class="standard-table" style="width: 100%;"
! Function
! 函数
! Signature
! 签名
! Description
! 描述
|-
|-
| <code>GetPlayerSpeechDuration</code>
| <code>GetPlayerSpeechDuration</code>
| <code>float CPlayerVoiceListener::GetPlayerSpeechDuration(int)</code>
| <code>float {{L|CPlayerVoiceListener}}::GetPlayerSpeechDuration(int)</code>
| Returns the number of seconds the player has been continuously speaking.
| 返回玩家持续说话的秒数
|-
|-
| <code>IsPlayerSpeaking</code>
| <code>IsPlayerSpeaking</code>
| <code>bool CPlayerVoiceListener::IsPlayerSpeaking(int)</code>
| <code>bool {{L|CPlayerVoiceListener}}::IsPlayerSpeaking(int)</code>
| Returns whether the player specified is speaking.
| 返回指定玩家是否正在说话
|}
|}


=== CPortal_Player ===
=== CPortal_Player ===
{{todo}}
{{todo}}


 
==== 使用方法 ====
==== Methods ====
{| class="standard-table" style="width: 100%;"
{| class="standard-table" style="width: 100%;"
! Function
! 函数
! Signature
! 签名
! Description
! 描述
|-
|-
| <code>GetWheatleyMonitorDestructionCount</code>
| <code>GetWheatleyMonitorDestructionCount</code>
| <code>int CPortal_Player::GetWheatleyMonitorDestructionCount()</code>
| <code>int {{L|CPortal_Player}}::GetWheatleyMonitorDestructionCount()</code>
| Get number of wheatley monitors destroyed by the player.
| 获取玩家摧毁Wheatley显示器的数量
|-
|-
| <code>IncWheatleyMonitorDestructionCount</code>
| <code>IncWheatleyMonitorDestructionCount</code>
| <code>void CPortal_Player::IncWheatleyMonitorDestructionCount()</code>
| <code>void {{L|CPortal_Player}}::IncWheatleyMonitorDestructionCount()</code>
| Set number of wheatley monitors destroyed by the player.
| 增加玩家摧毁Wheatley显示器的计数
|-
|-
| <code>TurnOffPotatos</code>
| <code>TurnOffPotatos</code>
| <code>void CPortal_Player::TurnOffPotatos()</code>
| <code>void {{L|CPortal_Player}}::TurnOffPotatos()</code>
| Turns Off the Potatos material light
| 关闭Potatos材质光源
|-
|-
| <code>TurnOnPotatos</code>
| <code>TurnOnPotatos</code>
| <code>void CPortal_Player::TurnOnPotatos()</code>
| <code>void {{L|CPortal_Player}}::TurnOnPotatos()</code>
| Turns On the Potatos material light
| 开启Potatos材质光源
|}
|}


=== CPropLinkedPortalDoor ===
=== CPropLinkedPortalDoor ===
{{todo}}
{{todo}}


 
==== 使用方法 ====
==== Methods ====
{| class="standard-table" style="width: 100%;"
{| class="standard-table" style="width: 100%;"
! Function
! 函数
! Signature
! 签名
! Description
! 描述
|-
|-
| <code>GetPartnerInstance</code>
| <code>GetPartnerInstance</code>
| <code>handle CPropLinkedPortalDoor::GetPartnerInstance()</code>
| <code>handle {{L|CPropLinkedPortalDoor}}::GetPartnerInstance()</code>
| Get the instance handle of the door's linked partner
| 获取门链接伙伴的实例句柄
|-
|-
| <code>GetPartnername</code>
| <code>GetPartnername</code>
| <code>string CPropLinkedPortalDoor::GetPartnername()</code>
| <code>string {{L|CPropLinkedPortalDoor}}::GetPartnername()</code>
| Returns the partnername of the door.
| 返回门的伙伴名称
|}
|}


=== CSceneEntity ===
=== CSceneEntity ===
Extends [[#CBaseEntity|CBaseEntity]]
继承 [[#CBaseEntity|CBaseEntity]]


 
==== 使用方法 ====
==== Methods ====
{| class="standard-table" style="width: 100%;"
{| class="standard-table" style="width: 100%;"
! Function
! 函数
! Signature
! 签名
! Description
! 描述
|-
|-
| <code>AddBroadcastTeamTarget</code>
| <code>AddBroadcastTeamTarget</code>
| <code>void CSceneEntity::AddBroadcastTeamTarget(int)</code>
| <code>void CSceneEntity::AddBroadcastTeamTarget(int)</code>
| Adds a team (by index) to the broadcast list
| 通过索引将团队添加到广播列表
|-
|-
| <code>EstimateLength</code>
| <code>EstimateLength</code>
| <code>float CSceneEntity::EstimateLength()</code>
| <code>float CSceneEntity::EstimateLength()</code>
| Returns length of this scene in seconds.
| 返回场景长度(秒)
|-
|-
| <code>FindNamedEntity</code>
| <code>FindNamedEntity</code>
| <code>handle CSceneEntity::FindNamedEntity(string)</code>
| <code>handle CSceneEntity::FindNamedEntity(string)</code>
| given an entity reference, such as !target, get actual entity from scene object
| 根据实体引用(如!target)从场景对象获取实际实体
|-
|-
| <code>IsPaused</code>
| <code>IsPaused</code>
| <code>bool CSceneEntity::IsPaused()</code>
| <code>bool CSceneEntity::IsPaused()</code>
| If this scene is currently paused.
| 检查当前场景是否暂停
|-
|-
| <code>IsPlayingBack</code>
| <code>IsPlayingBack</code>
| <code>bool CSceneEntity::IsPlayingBack()</code>
| <code>bool CSceneEntity::IsPlayingBack()</code>
| If this scene is currently playing.
| 检查当前场景是否正在播放
|-
|-
| <code>LoadSceneFromString</code>
| <code>LoadSceneFromString</code>
| <code>bool CSceneEntity::LoadSceneFromString(string, string)</code>
| <code>bool CSceneEntity::LoadSceneFromString(string, string)</code>
| given a dummy scene name and a vcd string, load the scene
| 根据虚拟场景名和vcd字符串加载场景
|-
|-
| <code>RemoveBroadcastTeamTarget</code>
| <code>RemoveBroadcastTeamTarget</code>
| <code>void CSceneEntity::RemoveBroadcastTeamTarget(int)</code>
| <code>void CSceneEntity::RemoveBroadcastTeamTarget(int)</code>
| Removes a team (by index) from the broadcast list
| 通过索引从广播列表移除团队
|}
|}




=== CScriptKeyValues ===
=== CScriptKeyValues ===
Script handle representation of a models [[$keyvalues]] block.
模型{{L|$keyvalues}}块的脚本句柄表示。
Sub keys are instances of the same class.
子键是相同类的实例。




==== Methods ====
==== 使用方法 ====
{| class="standard-table" style="width: 100%;"
{| class="standard-table" style="width: 100%;"
! Function
! 函数
! Signature
! 签名
! Description
! 描述
|-
|-
| <code>FindKey</code>
| <code>FindKey</code>
| <code>handle CScriptKeyValues::FindKey(string)</code>
| <code>handle CScriptKeyValues::FindKey(string)</code>
| Given a KeyValues object and a key name, find a KeyValues object associated with the key name
| 根据键名查找关联的KeyValues对象
|-
|-
| <code>GetFirstSubKey</code>
| <code>GetFirstSubKey</code>
| <code>handle CScriptKeyValues::GetFirstSubKey()</code>
| <code>handle CScriptKeyValues::GetFirstSubKey()</code>
| Given a KeyValues object, return the first sub key object
| 获取第一个子键对象
|-
|-
| <code>GetKeyBool</code>
| <code>GetKeyBool</code>
| <code>bool CScriptKeyValues::GetKeyBool(string)</code>
| <code>bool CScriptKeyValues::GetKeyBool(string)</code>
| Given a KeyValues object and a key name, return associated bool value
| 获取键关联的布尔值
|-
|-
| <code>GetKeyFloat</code>
| <code>GetKeyFloat</code>
| <code>float CScriptKeyValues::GetKeyFloat(string)</code>
| <code>float CScriptKeyValues::GetKeyFloat(string)</code>
| Given a KeyValues object and a key name, return associated float value
| 获取键关联的浮点值
|-
|-
| <code>GetKeyInt</code>
| <code>GetKeyInt</code>
| <code>int CScriptKeyValues::GetKeyInt(string)</code>
| <code>int CScriptKeyValues::GetKeyInt(string)</code>
| Given a KeyValues object and a key name, return associated integer value
| 获取键关联的整数值
|-
|-
| <code>GetKeyString</code>
| <code>GetKeyString</code>
| <code>string CScriptKeyValues::GetKeyString(string)</code>
| <code>string CScriptKeyValues::GetKeyString(string)</code>
| Given a KeyValues object and a key name, return associated string value
| 获取键关联的字符串值
|-
|-
| <code>GetNextKey</code>
| <code>GetNextKey</code>
| <code>handle CScriptKeyValues::GetNextKey()</code>
| <code>handle CScriptKeyValues::GetNextKey()</code>
| Given a KeyValues object, return the next key object in a sub key group
| 获取子键组中的下一个键对象
|-
|-
| <code>IsKeyEmpty</code>
| <code>IsKeyEmpty</code>
| <code>bool CScriptKeyValues::IsKeyEmpty(string)</code>
| <code>bool CScriptKeyValues::IsKeyEmpty(string)</code>
| Given a KeyValues object and a key name, return true if key name has no value
| 检查键名是否没有值
|-
|-
| <code>ReleaseKeyValues</code>
| <code>ReleaseKeyValues</code>
| <code>void CScriptKeyValues::ReleaseKeyValues()</code>
| <code>void CScriptKeyValues::ReleaseKeyValues()</code>
| Given a root KeyValues object, release its contents
| 释放根KeyValues对象内容
|}
|}




=== CTriggerCamera ===
=== CTriggerCamera ===
Extends [[#CBaseEntity|CBaseEntity]]
继承 [[#CBaseEntity|CBaseEntity]]




==== Methods ====
==== 使用方法 ====
{| class="standard-table" style="width: 100%;"
{| class="standard-table" style="width: 100%;"
! Function
! 函数
! Signature
! 签名
! Description
! 描述
|-
|-
| <code>GetFov</code>
| <code>GetFov</code>
| <code>int CTriggerCamera::GetFov()</code>
| <code>int CTriggerCamera::GetFov()</code>
| get camera's current fov setting as integer
| 获取相机当前FOV设置(整数)
|-
|-
| <code>SetFov</code>
| <code>SetFov</code>
| <code>void CTriggerCamera::SetFov(int, float)</code>
| <code>void CTriggerCamera::SetFov(int, float)</code>
| set camera's current fov in integer degrees and fov change rate as float
| 设置相机FOV(整数角度)和FOV变化率(浮点)
|}
|}




=== Math ===
=== Math ===
The built-in [http://www.squirrel-lang.org/mainsite/doc/sqstdlib2.html#d0e1519 Squirrel math library].
内置的[http://www.squirrel-lang.org/mainsite/doc/sqstdlib2.html#d0e1519 Squirrel数学库]




{| class="standard-table" style="width: 100%;"
{| class="standard-table" style="width: 100%;"
! Function
! 函数
! Signature
! 签名
! Description
! 描述
|-
|-
| <code>abs</code>
| <code>abs</code>
| <code> int abs(float ''x'')</code>
| <code> int abs(float ''x'')</code>
| Returns the absolute value of <code>x</code> as an integer.
| 返回<code>x</code>的整数绝对值
|-
|-
| <code>acos</code>
| <code>acos</code>
| <code> float acos(float ''x'')</code>
| <code> float acos(float ''x'')</code>
| Returns the arccosine of <code>x</code>.
| 返回<code>x</code>的反余弦值
|-
|-
| <code>asin</code>
| <code>asin</code>
| <code> float asin(float ''x'')</code>
| <code> float asin(float ''x'')</code>
| Returns the arcsine of <code>x</code>.
| 返回<code>x</code>的反正弦值
|-
|-
| <code>atan</code>
| <code>atan</code>
| <code> float atan(float ''x'')</code>
| <code> float atan(float ''x'')</code>
| Returns the arctangent of <code>x</code>.
| 返回<code>x</code>的反正切值
|-
|-
| <code>atan2</code>
| <code>atan2</code>
| <code> float atan2(float ''x'', float ''y'')</code>
| <code> float atan2(float ''x'', float ''y'')</code>
| Returns the arctangent of <code>x/y</code>.
| 返回<code>x/y</code>的反正切值
|-
|-
| <code>ceil</code>
| <code>ceil</code>
| <code> float ceil(float ''x'')</code>
| <code> float ceil(float ''x'')</code>
| Returns a float value representing the smallest integer that is greater than or equal to <code>x</code>.
| 返回大于等于<code>x</code>的最小整数值
|-
|-
| <code>cos</code>
| <code>cos</code>
| <code> float cos(float ''x'')</code>
| <code> float cos(float ''x'')</code>
| Returns the cosine of <code>x</code>.
| 返回<code>x</code>的余弦值
|-
|-
| <code>exp</code>
| <code>exp</code>
| <code> float exp(float ''x'')</code>
| <code> float exp(float ''x'')</code>
| Returns the exponential value (<code>e^x</code>) of the float parameter <code>x</code>.
| 返回<code>x</code>的指数值(<code>e^x</code>
|-
|-
| <code>fabs</code>
| <code>fabs</code>
| <code> float fabs(float ''x'')</code>
| <code> float fabs(float ''x'')</code>
| Returns the absolute value of <code>x</code> as a float.
| 返回<code>x</code>的浮点绝对值
|-
|-
| <code>floor</code>
| <code>floor</code>
| <code> float floor(float ''x'')</code>
| <code> float floor(float ''x'')</code>
| Returns a float value representing the largest integer that is less than or equal to <code>x</code>.
| 返回小于等于<code>x</code>的最大整数值
|-
|-
| <code>log</code>
| <code>log</code>
| <code> float log(float ''x'')</code>
| <code> float log(float ''x'')</code>
| Returns the natural logarithm of <code>x</code>.
| 返回<code>x</code>的自然对数
|-
|-
| <code>log10</code>
| <code>log10</code>
| <code> float log10(float ''x'')</code>
| <code> float log10(float ''x'')</code>
| Returns the logarithm base-10 of <code>x</code>.
| 返回<code>x</code>的以10为底对数
|-
|-
| <code>pow</code>
| <code>pow</code>
| <code> float pow(float ''x'', float ''y'')</code>
| <code> float pow(float ''x'', float ''y'')</code>
| Returns <code>x</code> raised to the power of <code>y</code>.
| 返回<code>x</code><code>y</code>次幂
|-
|-
| <code>rand</code>
| <code>rand</code>
| <code> int rand()</code>
| <code> int rand()</code>
| Returns a pseudorandom integer in the range 0 to <code>RAND_MAX</code>.
| 返回0到<code>RAND_MAX</code>间的伪随机整数
|-
|-
| <code>sin</code>
| <code>sin</code>
| <code> float sin(float ''x'')</code>
| <code> float sin(float ''x'')</code>
| Returns the sine of <code>x</code>.
| 返回<code>x</code>的正弦值
|-
|-
| <code>sqrt</code>
| <code>sqrt</code>
| <code> float sqrt(float ''x'')</code>
| <code> float sqrt(float ''x'')</code>
| Returns the square root of <code>x</code>.
| 返回<code>x</code>的平方根
|-
|-
| <code>srand</code>
| <code>srand</code>
| <code> void srand(float ''seed'')</code>
| <code> void srand(float ''seed'')</code>
| Sets the starting point for generating a series of pseudorandom integers.
| 设置伪随机数生成器的种子
|-
|-
| <code>tan</code>
| <code>tan</code>
| <code> float tan(float ''x'')</code>
| <code> float tan(float ''x'')</code>
| Returns the tangent of <code>x</code>.
| 返回<code>x</code>的正切值
|}
|}


 
=== 向量 ===
=== Vector ===
表示一个x/y/z位置,被许多函数返回/传递。它以3个x/y/z位置作为参数。<br>
Represents an x/y/z position, returned/passed to many functions. It takes the 3 x/y/z positions as a parameter.<br>
可以对向量应用一些数学运算 - 任意两个向量之间的''+/-'',以及<code>向量 * 数字</code>(仅限此顺序)。所有三种运算都返回另一个向量。其他数学运算通过方法调用完成:
A few math operations can be applied to vectors - ''+/-'' between any two vectors, and <code>Vector * number</code> in that order only. All three operations return another vector. Other math operations are done with method calls:




==== Methods ====
==== 使用方法 ====
{| class="standard-table" style="width: 100%;"
{| class="standard-table" style="width: 100%;"
! Function
! 函数
! Signature
! 签名
! Description
! 描述
|-
|-
| <code>Cross</code>
| <code>Cross</code>
| <code>Vector Vector::Cross(Vector other)</code>
| <code>Vector Vector::Cross(Vector other)</code>
| Return the vector cross product - <code>this × other</code>.
| 返回向量叉积 - <code>this × other</code>
|-
|-
| <code>Dot</code>
| <code>Dot</code>
| <code>float Vector::Dot(Vector other)</code>
| <code>float Vector::Dot(Vector other)</code>
| Return the vector dot product - <code>this · other</code>.
| 返回向量点积 - <code>this · other</code>
|-
|-
| <code>Length</code>
| <code>Length</code>
| <code>float Vector::Length()</code>
| <code>float Vector::Length()</code>
| Return the distance from the origin.
| 返回与原点距离
|-
|-
| <code>Length2D</code>
| <code>Length2D</code>
| <code>float Vector::Length2D()</code>
| <code>float Vector::Length2D()</code>
| Return the distance from the origin, ignoring the Z axis.
| 返回与原点距离(忽略Z轴)
|-
|-
| <code>LengthSqr</code>
| <code>LengthSqr</code>
| <code>float Vector::LengthSqr()</code>
| <code>float Vector::LengthSqr()</code>
| Return the distance from the origin, but squared. This is faster to compute since a square root isn\'t required.
| 返回与原点距离的平方(计算更快,无需平方根)
|-
|-
| <code>Length2DSqr</code>
| <code>Length2DSqr</code>
| <code>float Vector::Length2DSqr()</code>
| <code>float Vector::Length2DSqr()</code>
| Return the distance from the origin, ignoring the Z axis and squared. This is faster to compute since a square root isn\'t required.
| 返回与原点距离的平方(忽略Z轴,计算更快)
|-
|-
| <code>Norm</code>
| <code>Norm</code>
| <code>float Vector::Norm()</code>
| <code>float Vector::Norm()</code>
| Modify the vector to have a length of 1, and return its original length.
| 将向量长度归一化为1,并返回原长度
|-
|-
| <code>ToKVString</code>
| <code>ToKVString</code>
| <code>string Vector::ToKVString()</code>
| <code>string Vector::ToKVString()</code>
| Return a string in the form "X Y Z".
| 返回"X Y Z"格式字符串
|}
|}




== Other functions ==
== 其他函数 ==
{| class="standard-table" style="width: 100%;"
{| class="standard-table" style="width: 100%;"
! Function
! 函数
! Signature
! 签名
! Description
! 描述
|-
|-
| <code>Assert</code>
| <code>Assert</code>
| <code>void Assert(''exp'', string ''message'' = null)</code>
| <code>void Assert(''exp'', string ''message'' = null)</code>
| Throws an exception if ''exp'' equates to false, optionally with message.
| 如果''exp''为false则抛出异常(可选消息)
|-
|-
| <code>CreateProp</code>
| <code>CreateProp</code>
| <code>handle CreateProp(string classname, Vector origin, string modelname, int activity)</code>
| <code>handle CreateProp(string classname, Vector origin, string modelname, int activity)</code>
| Create a prop. The class should be a prop_physics style entity.
| 创建道具(类应为prop_physics风格实体)
|-
|-
| <code>CreateSceneEntity</code>
| <code>CreateSceneEntity</code>
| <code>handle CreateSceneEntity(string)</code>
| <code>handle CreateSceneEntity(string)</code>
| Create a scene entity to play the specified scene.
| 创建用于播放指定场景的场景实体
|-
|-
| <code>DebugDrawBox</code>
| <code>DebugDrawBox</code>
| <code>void DebugDrawBox(Vector origin, Vector mins, Vector maxs, 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 box, for visualizing code. It's positioned at <code>origin</code>, with the dimensions <code>mins</code>/<code>maxs</code> Developer must be on to show this, and it'll stay around for <code>duration</code> seconds (or 1 frame if -1.0). The color ranges from 0-255.
| 绘制调试方框(需开发者模式),位于<code>origin</code>,尺寸为<code>mins</code>/<code>maxs</code>,持续<code>duration</code>秒(-1.0为1帧),颜色范围0-255
|-
|-
| <code>DebugDrawLine</code>
| <code>DebugDrawLine</code>
| <code>void DebugDrawLine(Vector start, Vector end, int r, int g, int b, bool hitTest, float duration)</code>
| <code>void DebugDrawLine(Vector start, Vector end, int r, int g, int b, bool hitTest, float duration)</code>
| Draw a debug line, for visualizing code. Developer must be on to show this, and it'll stay around for <code>duration</code> seconds (or 1 frame if -1.0). The color ranges from 0-255.
| 绘制调试线(需开发者模式),持续<code>duration</code>秒,颜色范围0-255
|-
|-
| <code>DoIncludeScript</code>
| <code>DoIncludeScript</code>
| <code>bool DoIncludeScript(string ''filename'', table ''scope'')</code>
| <code>bool DoIncludeScript(string ''filename'', table ''scope'')</code>
| Execute the script file <code>"scripts/vscripts/" + filename</code> in the scope of <code>scope</code>. The extension <code>.nut</code> can be omitted.
| 在<code>scope</code>作用域执行脚本文件<code>"scripts/vscripts/" + filename</code>(可省略<code>.nut</code>扩展名)
|-
|-
| <code>IncludeScript</code>
| <code>IncludeScript</code>
| <code>bool IncludeScript(string ''filename'', table ''scope'' = null)</code>
| <code>bool IncludeScript(string ''filename'', table ''scope'' = null)</code>
| Execute the script file <code>"scripts/vscripts/" + filename</code> in the scope of <code>scope</code>, <code>this</code> by default. The extension <code>.nut</code> can be omitted.
| <code>scope</code>作用域(默认为<code>this</code>)执行脚本文件
|-
|-
| <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.
| 生成实体{{L|I/O}}事件
|-
|-
| <code>EntFire</code>
| <code>EntFire</code>
| <code>function EntFire(target, action, value, delay, activator)</code>
| <code>function EntFire(target, action, value, delay, activator)</code>
| Generate an entity [[I/O]] event. Value, delay and activator are optional.
| 生成实体{{L|I/O}}事件(value/delay/activator可选)
|-
|-
| <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. First parameter is an entity instance.
| 生成实体I/O事件(第一个参数为实体实例)
|-
|-
| <code>FrameTime</code>
| <code>FrameTime</code>
| <code>float FrameTime()</code>
| <code>float FrameTime()</code>
| Get the time spent on the server in the last frame.
| 获取服务器上一帧耗时
|-
|-
| <code>GetDeveloperLevel</code>
| <code>GetDeveloperLevel</code>
| <code>int GetDeveloperLevel()</code>
| <code>int GetDeveloperLevel()</code>
| Gets the level of 'developer'.
| 获取'developer'级别
|-
|-
| <code>GetMapIndexInPlayOrder</code>
| <code>GetMapIndexInPlayOrder</code>
| <code>int GetMapIndexInPlayOrder()</code>
| <code>int GetMapIndexInPlayOrder()</code>
| For workshop maps, determines which index (by order played) this map is. Returns -1 if entry is not found or -2 if this is not a workshop map.
| 获取创意工坊地图的游玩顺序索引(非工坊地图返回-2)
|-
|-
| <code>GetMapName</code>
| <code>GetMapName</code>
| <code>string GetMapName()</code>
| <code>string GetMapName()</code>
| Get the name of the map.
| 获取当前地图名称
|-
|-
| <code>GetNumMapsPlayed</code>
| <code>GetNumMapsPlayed</code>
| <code>int GetNumMapsPlayed()</code>
| <code>int GetNumMapsPlayed()</code>
| Returns how many workshop maps the player has played through.
| 获取玩家已游玩的创意工坊地图数量
|-
|-
| <code>GetPlayerSilenceDuration</code>
| <code>GetPlayerSilenceDuration</code>
| <code>float GetPlayerSilenceDuration(int player_index)</code>
| <code>float GetPlayerSilenceDuration(int player_index)</code>
| Time that the specified player has been silent on the mic.
| 获取指定玩家麦克风静默时长
|-
|-
| <code>IsMultiplayer</code>
| <code>IsMultiplayer</code>
| <code>bool IsMultiplayer()</code>
| <code>bool IsMultiplayer()</code>
| Returns true if this is a multiplayer game, or false if singleplayer.
| 检查是否为多人游戏
|-
|-
| <code>LoopSinglePlayerMaps</code>
| <code>LoopSinglePlayerMaps</code>
| <code>bool LoopSinglePlayerMaps()</code>
| <code>bool LoopSinglePlayerMaps()</code>
| Returns true if the cvar <code>loopsingleplayermaps</code> is enabled. Still works in multiplayer.
| 检查<code>loopsingleplayermaps</code>变量是否启用(多人游戏仍有效)
|-
|-
| <code>RandomFloat</code>
| <code>RandomFloat</code>
| <code>float RandomFloat(float min, float max)</code>
| <code>float RandomFloat(float min, float max)</code>
| Generate a random floating point number within a range, inclusive
| 生成范围内随机浮点数(包含边界)
|-
|-
| <code>RandomInt</code>
| <code>RandomInt</code>
| <code>int RandomInt(int min, int max)</code>
| <code>int RandomInt(int min, int max)</code>
| Generate a random integer within a range, inclusive
| 生成范围内随机整数(包含边界)
|-
|-
| <code>RecordAchievementEvent</code>
| <code>RecordAchievementEvent</code>
| <code>void RecordAchievementEvent(string name, int player_index)</code>
| <code>void RecordAchievementEvent(string name, int player_index)</code>
| Earns a given achievement or increases progress.
| 解锁成就或增加进度
|-
|-
| <code>RequestMapRating</code>
| <code>RequestMapRating</code>
| <code>void RequestMapRating()</code>
| <code>void RequestMapRating()</code>
| In workshop maps, pops up the map rating dialog for user input.
| 在创意工坊地图弹出评分对话框
|-
|-
| <code>RetrieveNativeSignature</code>
| <code>RetrieveNativeSignature</code>
Line 877: Line 856:
| <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. The command is treated as coming from the host in multiplayer.
| 向控制台发送命令(多人游戏中视为主机命令)
|-
|-
| <code>SetDucking</code>
| <code>SetDucking</code>
| <code>void SetDucking(string, string, float)</code>
| <code>void SetDucking(string, string, float)</code>
| Set the level of an audio ducking channel.
| 设置音频闪避通道级别
|-
|-
| <code>SetMapAsPlayed</code>
| <code>SetMapAsPlayed</code>
| <code>int SetMapAsPlayed()</code>
| <code>int SetMapAsPlayed()</code>
| For workshop maps, adds the current map to the play order and returns the new index therein. Returns -2 if this is not a workshop map.
| 将当前地图添加到游玩顺序(非工坊地图返回-2)
|-
|-
| <code>ShowMessage</code>
| <code>ShowMessage</code>
| <code>void ShowMessage(string)</code>
| <code>void ShowMessage(string)</code>
| Print a HUD message on all clients.
| 向所有客户端显示HUD消息
|-
|-
| <code>Time</code>
| <code>Time</code>
| <code>float Time()</code>
| <code>float Time()</code>
| Get the current server time
| 获取当前服务器时间
|-
|-
| <code>TraceLine</code>
| <code>TraceLine</code>
| <code>float TraceLine(Vector start, Vector end, handle ignored_ent)</code>
| <code>float TraceLine(Vector start, Vector end, handle ignored_ent)</code>
| Given 2 points and an entity to ignore, returns fraction along line that hits the world. Does not hit entities, seemingly making the ignored entity parameter useless.
| 给定起点/终点和忽略实体,返回击中世界的线段比例(不检测实体)
|-
|-
| <code>UniqueString</code>
| <code>UniqueString</code>
| <code>string UniqueString(string ''suffix'' = "")</code>
| <code>string UniqueString(string ''suffix'' = "")</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. Equivalent to <code>DoUniqueString(suffix)</code>.
| 生成脚本VM生命周期内唯一的字符串(可选前缀)
|-
|-
| <code>DoUniqueString</code>
| <code>DoUniqueString</code>
| <code>string DoUniqueString(string ''suffix'')</code>
| <code>string DoUniqueString(string ''suffix'')</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.
| 生成唯一字符串(功能同<code>UniqueString</code>)
|-
|-
| <code>__ReplaceClosures</code>
| <code>__ReplaceClosures</code>
| <code>void __ReplaceClosures(function ''script'', table ''scope'')</code>
| <code>void __ReplaceClosures(function ''script'', table ''scope'')</code>
| Internal function called in <code>script_reload_</code> server commands.
| <code>script_reload_</code>服务器命令调用的内部函数
|}
|}


=== Singleplayer only ===
=== 仅限单人模式 ===


These functions can only be used in singleplayer games, and may cause errors if used in multiplayer.
这些函数只能在单人游戏中使用,多人游戏中使用可能导致错误。


{| class="standard-table" style="width: 100%;"
{| class="standard-table" style="width: 100%;"
! Function
! 函数
! Signature
! 签名
! Description
! 描述
|-
|-
| <code>GetPlayer</code>
| <code>GetPlayer</code>
| <code>handle GetPlayer()</code>
| <code>handle GetPlayer()</code>
| Returns the player.
| 获取玩家实体
|-
|-
| <code>GivePlayerPortalgun</code>
| <code>GivePlayerPortalgun</code>
| <code>void GivePlayerPortalgun()</code>
| <code>void GivePlayerPortalgun()</code>
| Equips the player with a blue-only portalgun.
| 给予玩家仅限蓝色传送门枪
|-
|-
| <code>PrecacheMovie</code>
| <code>PrecacheMovie</code>
| <code>void PrecacheMovie(string)</code>
| <code>void PrecacheMovie(string)</code>
| Precaches a named movie. Only valid to call within the entity's 'Precache' function called on mapspawn.
| 预加载指定电影(仅在地图生成时的'Precache()'函数中有效)
|-
|-
| <code>ScriptShowHudMessageAll</code>
| <code>ScriptShowHudMessageAll</code>
| <code>void ScriptShowHudMessageAll(string, float)</code>
| <code>void ScriptShowHudMessageAll(string, float)</code>
| Show center print text message for specified number of seconds.
| 显示居中文本消息(持续指定秒数)
|-
|-
| <code>ScriptSteamShowURL</code>
| <code>ScriptSteamShowURL</code>
| <code>bool ScriptSteamShowURL(string)</code>
| <code>bool ScriptSteamShowURL(string)</code>
| Bring up the steam overlay and shows the specified URL.  (Full address with protocol type is required, e.g. http://www.steamgames.com/)
| 在Steam叠加层显示指定URL(需完整地址如http://www.steamgames.com/
|-
|-
| <code>TryDLC1InstalledOrCatch</code>
| <code>TryDLC1InstalledOrCatch</code>
| <code>void TryDLC1InstalledOrCatch()</code>
| <code>void TryDLC1InstalledOrCatch()</code>
| Throws an exception if the Peer Review DLC isn't installed. Useless in the current PC version of the game, as Peer Review will always be present.
| 如果未安装Peer Review DLC则抛出异常(当前PC版本中无效)
|-
|-
| <code>UpgradePlayerPortalgun</code>
| <code>UpgradePlayerPortalgun</code>
| <code>void UpgradePlayerPortalgun()</code>
| <code>void UpgradePlayerPortalgun()</code>
| Upgrades the player's portalgun to shoot orange portals.
| 将玩家传送门枪升级为可发射橙色传送门
|-
|-
| <code>UpgradePlayerPotatogun</code>
| <code>UpgradePlayerPotatogun</code>
| <code>void UpgradePlayerPotatogun()</code>
| <code>void UpgradePlayerPotatogun()</code>
| Upgrades the player's portalgun to shoot orange portals and have PotatOS impaled on it.
| 将玩家传送门枪升级为带PotatOS的橙色传送门枪
|}
|}


=== Multiplayer only ===
=== 仅限多人模式 ===


These functions can only be used in multiplayer games, and may cause errors if used in singleplayer.
这些函数只能在多人游戏中使用,单人游戏中使用可能导致错误。


{| class="standard-table" style="width: 100%;"
{| class="standard-table" style="width: 100%;"
! Function
! 函数
! Signature
! 签名
! Description
! 描述
|-
|-
| <code>AddBranchLevelName</code>
| <code>AddBranchLevelName</code>
| <code>void AddBranchLevelName(int, string)</code>
| <code>void AddBranchLevelName(int, string)</code>
| Adds a level to the specified branch's list. {{note|In co-op maps, this function must be called at least once or players will not be able to move.}}
| 向指定分支添加关卡{{note|合作地图中必须至少调用一次, 否则玩家可能会动弹不得}}
|-
|-
| <code>AddCoopCreditsName</code>
| <code>AddCoopCreditsName</code>
| <code>void AddCoopCreditsName(string)</code>
| <code>void AddCoopCreditsName(string)</code>
| Adds a name to the coop credit's list.
| 向合作模式演职员表添加名称
|-
|-
| <code>AddGladosSpokenFlags</code>
| <code>AddGladosSpokenFlags</code>
| <code>void AddGladosSpokenFlags(int, int)</code>
| <code>void AddGladosSpokenFlags(int, int)</code>
| Adds bit flags for specific lines that are tracked per session.
| 添加特定对话行的位标志(按会话追踪)
|-
|-
| <code>CoopGladosBlowUpBots</code>
| <code>CoopGladosBlowUpBots</code>
| <code>void CoopGladosBlowUpBots()</code>
| <code>void CoopGladosBlowUpBots()</code>
| Blows up both robots and prevents respawning.
| 摧毁两个机器人并阻止重生(用于合作课程1到4最后一关)
|-
|-
| <code>CoopGetNumPortalsPlaced</code>
| <code>CoopGetNumPortalsPlaced</code>
| <code>int CoopGetNumPortalsPlaced()</code>
| <code>int CoopGetNumPortalsPlaced()</code>
| Returns the number of portals the players have placed so far.
| 获取玩家已放置的传送门数量
|-
|-
| <code>CoopGetLevelsCompletedThisBranch</code>
| <code>CoopGetLevelsCompletedThisBranch</code>
| <code>int CoopGetLevelsCompletedThisBranch()</code>
| <code>int CoopGetLevelsCompletedThisBranch()</code>
| Returns the number of levels the players have completed in their run of the current branch.
| 获取当前分支中已完成的关卡数
|-
|-
| <code>CoopGetBranchTotalLevelCount</code>
| <code>CoopGetBranchTotalLevelCount</code>
| <code>int CoopGetBranchTotalLevelCount()</code>
| <code>int CoopGetBranchTotalLevelCount()</code>
| Returns the number of levels in the current branch.
| 获取当前分支的关卡总数
|-
|-
| <code>CoopSetCameFromLastDLCMap</code>
| <code>CoopSetCameFromLastDLCMap</code>
| <code>void CoopSetCameFromLastDLCMap(bool)</code>
| <code>void CoopSetCameFromLastDLCMap(bool)</code>
| Set whether the players came from the last coop DLC map or not.
| 设置玩家是否来自最后的合作DLC地图(合作课程6)
|-
|-
| <code>CoopSetMapRunTime</code>
| <code>CoopSetMapRunTime</code>
| <code>void CoopSetMapRunTime(float runLength)</code>
| <code>void CoopSetMapRunTime(float runLength)</code>
| Sets the time to complete a coop map from spawn to completing the puzzle. (Possibly related to the Triple Crown achievement.)
| 设置完成合作地图的时间(可能与Triple Crown(三皇冠)成就相关)
|-
|-
| <code>GetBluePlayerIndex</code>
| <code>GetBluePlayerIndex</code>
| <code>int GetBluePlayerIndex()</code>
| <code>int GetBluePlayerIndex()</code>
| Player index of the blue player.
| 获取蓝色玩家索引
|-
|-
| <code>GetCameFromLastDLCMap</code>
| <code>GetCameFromLastDLCMap</code>
| <code>bool GetCameFromLastDLCMap()</code>
| <code>bool GetCameFromLastDLCMap()</code>
| Returns true if coming from the last DLC coop map (as set by <code>CoopSetCameFromLastDLCMap</code>).
| 检查是否来自最后的合作DLC地图
|-
|-
| <code>GetCoopBranchLevelIndex</code>
| <code>GetCoopBranchLevelIndex</code>
| <code>int GetCoopBranchLevelIndex(int)</code>
| <code>int GetCoopBranchLevelIndex(int)</code>
| Given the 'branch' argument, returns the current chosen level.
| 获取指定分支的当前选定关卡索引
|-
|-
| <code>GetCoopSectionIndex</code>
| <code>GetCoopSectionIndex</code>
| <code>int GetCoopSectionIndex()</code>
| <code>int GetCoopSectionIndex()</code>
| Section that the coop players have selected to load.
| 获取合作玩家选择加载的章节索引
|-
|-
| <code>GetGladosSpokenFlags</code>
| <code>GetGladosSpokenFlags</code>
| <code>int GetGladosSpokenFlags(int)</code>
| <code>int GetGladosSpokenFlags(int)</code>
| Returns bit flags for specific lines that are tracked per session.
| 获取特定对话行的位标志
|-
|-
| <code>GetHaveSeenDLCTubesReveal</code>
| <code>GetHaveSeenDLCTubesReveal</code>
| <code>bool GetHaveSeenDLCTubesReveal()</code>
| <code>bool GetHaveSeenDLCTubesReveal()</code>
| Get whether players have seen the DLC tubes reveal this session (as set by <code>SetHaveSeenDLCTubesReveal</code>).
| 检查玩家是否已观看DLC管道
|-
|-
| <code>GetHighestActiveBranch</code>
| <code>GetHighestActiveBranch</code>
| <code>int GetHighestActiveBranch()</code>
| <code>int GetHighestActiveBranch()</code>
| Returns which branches should be available in the hub.
| 获取大厅中已解锁的最高关卡
|-
|-
| <code>GetNumPlayersConnected</code>
| <code>GetNumPlayersConnected</code>
| <code>int GetNumPlayersConnected()</code>
| <code>int GetNumPlayersConnected()</code>
| Returns how many players are connected. In normal co-op, this will almost always be 2.
| 获取已连接玩家数(通常为2)
|-
|-
| <code>GetOrangePlayerIndex</code>
| <code>GetOrangePlayerIndex</code>
| <code>int GetOrangePlayerIndex()</code>
| <code>int GetOrangePlayerIndex()</code>
| Player index of the orange player.
| 获取橙色玩家索引
|-
|-
| <code>GetPlayerDeathCount</code>
| <code>GetPlayerDeathCount</code>
| <code>int GetPlayerDeathCount(int player)</code>
| <code>int GetPlayerDeathCount(int player)</code>
| Returns the number of times that a specific player has died in the session.
| 获取指定玩家在会话中的死亡次数
|-
|-
| <code>IsBranchComplete</code>
| <code>IsBranchComplete</code>
| <code>bool IsBranchComplete(int course)</code>
| <code>bool IsBranchComplete(int course)</code>
| Returns true if every level in the course has been completed by either player.
| 检查分支所有关卡是否已完成
|-
|-
| <code>IsLevelComplete</code>
| <code>IsLevelComplete</code>
| <code>bool IsLevelComplete(int course, int level)</code>
| <code>bool IsLevelComplete(int course, int level)</code>
| Returns true if the level in the specified course is completed by either player.
| 检查指定分支关卡是否已完成
|-
|-
| <code>IsLocalSplitScreen</code>
| <code>IsLocalSplitScreen</code>
| <code>bool IsLocalSplitScreen()</code>
| <code>bool IsLocalSplitScreen()</code>
| Returns true if players are in split screen.
| 检查是否为本地分屏模式
|-
|-
| <code>IsPlayerBranchComplete</code>
| <code>IsPlayerBranchComplete</code>
| <code>bool IsPlayerBranchComplete(int player, int course)</code>
| <code>bool IsPlayerBranchComplete(int player, int course)</code>
| Returns true if every level in the course has been completed by the specified player.
| 检查指定玩家是否完成分支所有关卡
|-
|-
| <code>IsPlayerLevelComplete</code>
| <code>IsPlayerLevelComplete</code>
| <code>bool IsPlayerLevelComplete(int, int, int)</code>
| <code>bool IsPlayerLevelComplete(int, int, int)</code>
| Returns true if the level in the specified course is completed by a specific player.
| 检查指定玩家是否完成特定分支关卡
|-
|-
| <code>MarkMapComplete</code>
| <code>MarkMapComplete</code>
| <code>void MarkMapComplete(string)</code>
| <code>void MarkMapComplete(string)</code>
| Marks a maps a complete for both players.
| 标记地图为已完成(双方玩家)
|-
|-
| <code>NotifySpeedRunSuccess</code>
| <code>NotifySpeedRunSuccess</code>
| <code>void NotifySpeedRunSuccess(int runLength, string mapname)</code>
| <code>void NotifySpeedRunSuccess(int runLength, string mapname)</code>
| Tells the client that a successful speed run has been completed. (Used for the Triple Crown achievement.)
| 通知客户端速通成功(用于Triple Crown(三皇冠)成就)
|-
|-
| <code>SaveMPStatsData</code>
| <code>SaveMPStatsData</code>
| <code>void SaveMPStatsData()</code>
| <code>void SaveMPStatsData()</code>
| Save the multiplayer stats for the score board.
| 保存多人游戏统计信息(记分牌)
|-
|-
| <code>SetHaveSeenDLCTubesReveal</code>
| <code>SetHaveSeenDLCTubesReveal</code>
| <code>void SetHaveSeenDLCTubesReveal()</code>
| <code>void SetHaveSeenDLCTubesReveal()</code>
| Set that players have seen the DLC tubes reveal this session.
| 标记玩家已看见DLC管道
|}
|}


== See also ==
== 另见 ==
* [[VScript]]
* {{L|VScript}}
* [[VScript Fundamentals]]
* {{L|VScript Fundamentals|VScript基础}}
* {{sq}} [[Squirrel]]
* {{sq}} {{L|Squirrel}}
* [[PCapture-Lib - Portal 2 Script Library]]
* {{L|PCapture-Lib - Portal 2 Script Library|PCapture-Lib - 传送门2脚本库}}
* {{l4d2}} [[Left 4 Dead 2/Script Functions]]
* {{l4d2}} {{L|Left 4 Dead 2/Script Functions}}
* {{csgo}} [[List of Counter-Strike: Global Offensive Script Functions]]
* {{csgo}} {{L|List of Counter-Strike: Global Offensive Script Functions}}


[[Category:Portal 2]]
{{ACategory|Portal 2}}
[[Category:Scripting]]
{{ACategory|Scripting}}

Latest revision as of 06:37, 29 June 2025

English (en)中文 (zh)Translate (Translate)


此列表包含可用于的所有与传送门2 传送门2VScript(en)游戏引擎的松鼠(en)函数。 当游戏在工具模式(en)运行时可以使用script_help指令在控制台打印出来这些。

变量

实例 类型 描述
Entities CEntities 提供服务器中已生成实体的通道。


常量

实例 类型
_charsize_ integer 1
_floatsize_ integer 4
_intsize_ integer 4
_version_ string "Squirrel 2.2.3 stable"
RAND_MAX integer 32767
PI float 3.14159


CBaseEntity

这是实体的脚本句柄类。所有生成的实体都有一个使用此或其子类之一的脚本句柄。 游戏中的所有脚本句柄都可以从Entities访问实体脚本, 可以使用self关键字访问自己的脚本句柄。activatorcaller关键字可以在函数调用时访问。

使用方法

函数 特征用法 描述
__KeyValueFromInt void __KeyValueFromInt(string key, int value) 设置实体的某个Keyvalue(en)为整数。它只更改值, 但不会执行实体处理KeyValue所需的任何代码, 因此可能会产生意想不到的副作用。
__KeyValueFromFloat void __KeyValueFromFloat(string key, float value) 设置实体的某个Keyvalue(en)为浮点数。它只更改值, 但不会执行实体处理KeyValue所需的任何代码, 因此可能会产生意想不到的副作用。
__KeyValueFromString void __KeyValueFromString(string key, string value) 设置实体的某个Keyvalue(en)为字符串。它只更改值, 但不会执行实体处理KeyValue所需的任何代码, 因此可能会产生意想不到的副作用。
__KeyValueFromVector void __KeyValueFromVector(string key, Vector value) 设置实体的某个Keyvalue(en)向量(en)。它只更改值, 但不会执行实体处理KeyValue所需的任何代码, 因此可能会产生意想不到的副作用。
ConnectOutput void CBaseEntity::ConnectOutput(string output, string func_name) 添加一个I/O连接, 当指定的输出触发时, 该连接将调用指定的函数。
Destroy void CBaseEntity::Destroy() 消灭这个实体。
DisconnectOutput void CBaseEntity::DisconnectOutput(string output, string func_name) 从I/O事件中删除连接的脚本函数。
EmitSound void CBaseEntity::EmitSound(string sound) 从该实体处播放一段声音。
EyePosition Vector CBaseEntity::EyePosition() 获得眼睛位置绝对坐标的向量。
FirstMoveChild handle CBaseEntity::FirstMoveChild() 如果处于层次结构中,则获取则检索第一个(移动)实体的子级。
GetAngles Vector CBaseEntity::GetAngles() 获得实体转换为向量的俯仰、水平、横滚的角度数值。
GetAngularVelocity Vector CBaseEntity::GetAngularVelocity() 获取局部角速度-返回俯仰、水平、横滚的向量。
GetBoundingMaxs Vector CBaseEntity::GetBoundingMaxs() 获取一个以对象为中心的最大边框的向量。
GetBoundingMins Vector CBaseEntity::GetBoundingMins() 获取一个以对象为中心的最小边框的向量。
GetCenter Vector CBaseEntity::GetCenter() 获取对象中心的向量-绝对坐标。
GetClassname string CBaseEntity::GetClassname() 获取此实体的类名。
GetForwardVector Vector CBaseEntity::GetForwardVector() 获取实体的正向向量(+X)。
GetHealth int CBaseEntity::GetHealth() 返回实体当前血量(en)
GetLeftVector Vector CBaseEntity::GetLeftVector() 获取实体的左向量。
GetMaxHealth int CBaseEntity::GetMaxHealth() 返回实体最大血量。
GetModelKeyValues handle CBaseEntity::GetModelKeyValues() 获取此实体模型上的键值类实例。
GetModelName string CBaseEntity::GetModelName() 获取该实体模型名称。
GetMoveParent handle CBaseEntity::GetMoveParent() 如果处于层次结构中, 则检索实体的父级。
GetName string CBaseEntity::GetName() 获取此实体的Targetname。
GetOrigin Vector CBaseEntity::GetOrigin() 返回此实体的局部原点位置坐标。
GetOwner handle CBaseEntity::GetOwner() 获取此实体的所有者。
GetPreTemplateName string CBaseEntity::GetPreTemplateName() 将实体名称从模板唯一装饰(&001后缀)中删除。
GetRootMoveParent handle CBaseEntity::GetRootMoveParent() 如果处于层次结构中, 则向上遍历层次结构以查找根父级
GetScriptId string CBaseEntity::GetScriptId() 检索用于引用脚本系统中实体的唯一标识符。
GetScriptScope handle CBaseEntity::GetScriptScope() 检索与实体关联的脚本端数据。
GetSoundDuration float CBaseEntity::GetSoundDuration(string, string) 以浮点数返回声音的持续时间。接受声音名称和可选的actormodelname。
GetTeam int CBaseEntity::GetTeam() 找到这个实体所在的队伍。
GetUpVector Vector CBaseEntity::GetUpVector() 获取实体的向上向量(+Z)。
GetVelocity Vector CBaseEntity::GetVelocity() 获取实体的速度。请注意,这会读取QPhysics(en)速度值, 因此它仅适用于玩家、NPC和移动画笔实体。VPhysics对象的速度始终为零, 一种解决方法是记录多个帧上的位置, 并手动推导速度。
IsValid bool CBaseEntity::IsValid() 如果此实体有效, 则返回true。
NextMovePeer handle CBaseEntity::NextMovePeer() 返回同一继承层次结构中的下一个实体。
PrecacheSoundScript void CBaseEntity::PrecacheSoundScript(string) 预先加载一个声音以供以后播放, 应该在Preche()钩子函数中调用。
SetAbsOrigin void CBaseEntity::SetAbsOrigin(Vector) 将实体传送到此世界位置。
SetAngles void CBaseEntity::SetAngles(float, float, float) 设置实体俯仰、水平、横滚。
SetAngularVelocity void CBaseEntity::SetAngularVelocity(float, float, float) 设置局部角速度-浮点数的俯仰、水平、横滚速度。
SetForwardVector void CBaseEntity::SetForwardVector(Vector) 将实体的正向(+X)向量。
SetHealth void CBaseEntity::SetHealth(int) 设置实体当前的血量(en)
SetMaxHealth void CBaseEntity::SetMaxHealth(int) 设置实体最大血量。
SetModel void CBaseEntity::SetModel(string) 更改实体的模型, 这可用于更改prop_weighted_cube或其他类似实体的模型。模型必须预加载, 可以通过预先放置在地图的其他位置来完成。
SetOrigin void CBaseEntity::SetOrigin(Vector) 将此实体传送到给定位置。
SetOwner void CBaseEntity::SetOwner(handle) 设置实体的所有者。
SetSize void CBaseEntity::SetSize(Vector, Vector) 设置边界框大小。(比如func_brush或trigger_multiple)
SetTeam void CBaseEntity::SetTeam(int) 设置此实体所在的队伍。
SetVelocity void CBaseEntity::SetVelocity(Vector) 设置局部速度。请注意,这会设置QPhysics(en)速度值,因此它仅适用于玩家、NPC和移动画笔实体。对于VPhysics对象,这没有影响。
ValidateScriptScope bool CBaseEntity::ValidateScriptScope() 确保已创建实体的脚本作用域。 在分配给实体的作用域之前, 应该调用此函数。
entindex int CBaseEntity::entindex() 返回实体的索引值。

CBaseAnimating

继承 CBaseEntity

用于为道具等实体设置动画的脚本句柄类。

English (en)中文 (zh)Translate (Translate)

使用方法

函数 签名 描述
GetAttachmentAngles Vector CBaseAnimating::GetAttachmentAngles(int id) 获取附件ID的角度(p,y,r向量)。
GetAttachmentOrigin Vector CBaseAnimating::GetAttachmentOrigin(int id) 获取附件ID的原始向量。
GetObjectScaleLevel int CBaseAnimating::GetObjectScaleLevel() 获取实体的缩放级别。
IsSequenceFinished bool CBaseAnimating::IsSequenceFinished() 检查主序列是否播放完毕。
LookupAttachment int CBaseAnimating::LookupAttachment(string) 获取命名附件的ID。
SetBodygroup void CBaseAnimating::SetBodygroup(int group, int index) 设置身体组。group是目标组的索引,index是要使用的部位索引。

CBaseFlex

继承 CBaseAnimating

使用方法

函数 签名 描述
GetCurrentScene handle CBaseFlex::GetCurrentScene() 返回最早激活的场景实体实例(如果有)。
GetSceneByIndex handle CBaseFlex::GetSceneByIndex(int) 返回指定索引的场景实体实例。

CBasePlayer

继承 CBaseAnimating

使用方法

函数 签名 描述
IsNoclipping bool CBasePlayer::IsNoclipping() 如果玩家处于穿墙模式则返回true。

CEntities

脚本实例: Entities

用于查找和迭代游戏中实体的脚本接口。

要迭代一组实体,请在适当的方法中将null传递给"previous"参数以开始迭代,或引用先前找到的实体以继续搜索。示例:

//第一种方式
local ent = null;     //变量名"ent"可自定义
while(ent = Entities.FindByName(ent, "entityname"))     //注意使用"="而非"=="
{
  //...     //每次迭代时"ent"有效则执行此处代码
}

//第二种方式
for(local ent;ent = Entities.FindByName(ent, "entityname");)     //注意分号位置
{
  //...     //每次迭代时"ent"有效则执行此处代码
}

使用方法

函数 签名 描述
CreateByClassname handle CEntities::CreateByClassname(string) 通过类名创建实体
FindByClassname handle CEntities::FindByClassname(handle start_ent, string classname) 按类名查找实体。传递'null'开始迭代,或引用先前找到的实体继续搜索
FindByClassnameNearest handle CEntities::FindByClassnameNearest(string classname, Vector loc, float radius) 查找距离某点最近的指定类名实体
FindByClassnameWithin handle CEntities::FindByClassnameWithin(handle start_ent, string classname, Vector loc, float radius) 查找半径内的指定类名实体。传递'null'开始迭代
FindByModel handle CEntities::FindByModel(handle start_ent, string model) 按模型名查找实体。传递'null'开始迭代
FindByName handle CEntities::FindByName(handle start_ent, string targetname) 按名称(支持通配符)查找实体。传递'null'开始迭代
FindByNameNearest handle CEntities::FindByNameNearest(string targetname, Vector loc, float radius) 查找距离某点最近的指定名称实体
FindByNameWithin handle CEntities::FindByNameWithin(handle, string, Vector loc, float radius) 查找半径内的指定名称实体。传递'null'开始迭代
FindByTarget handle CEntities::FindByTarget(handle start_ent, string targetname) 查找具有特定target键值的实体。传递'null'开始迭代
FindInSphere handle CEntities::FindInSphere(handle start_ent, Vector loc, float radius) 查找半径内的实体。传递'null'开始迭代
First handle CEntities::First() 开始实体列表迭代。等同于Next(null)
Next handle CEntities::Next(handle) 继续迭代,需提供先前找到的实体引用

CEnvEntityMaker

继承 CBaseEntity

脚本句柄类是env_entity_maker(en)

使用方法

函数 签名 描述
SpawnEntity void CEnvEntityMaker::SpawnEntity() 在maker位置创建实体
SpawnEntityAtEntityOrigin void CEnvEntityMaker::SpawnEntityAtEntityOrigin(handle) 在指定实体位置创建实体
SpawnEntityAtLocation void CEnvEntityMaker::SpawnEntityAtLocation(Vector, Vector) 在指定位置和角度创建实体
SpawnEntityAtNamedEntityOrigin void CEnvEntityMaker::SpawnEntityAtNamedEntityOrigin(string) 在命名实体位置创建实体

CLinkedPortalDoor

[待完善]

使用方法

函数 签名 描述
GetPartnerInstance handle CLinkedPortalDoor::GetPartnerInstance() 获取门链接伙伴的实例句柄
GetPartnername string CLinkedPortalDoor::GetPartnername() 返回门的伙伴名称

CPlayerVoiceListener

[待完善]

使用方法

函数 签名 描述
GetPlayerSpeechDuration float CPlayerVoiceListener(en)::GetPlayerSpeechDuration(int) 返回玩家持续说话的秒数
IsPlayerSpeaking bool CPlayerVoiceListener(en)::IsPlayerSpeaking(int) 返回指定玩家是否正在说话

CPortal_Player

[待完善]

使用方法

函数 签名 描述
GetWheatleyMonitorDestructionCount int CPortal_Player(en)::GetWheatleyMonitorDestructionCount() 获取玩家摧毁Wheatley显示器的数量
IncWheatleyMonitorDestructionCount void CPortal_Player(en)::IncWheatleyMonitorDestructionCount() 增加玩家摧毁Wheatley显示器的计数
TurnOffPotatos void CPortal_Player(en)::TurnOffPotatos() 关闭Potatos材质光源
TurnOnPotatos void CPortal_Player(en)::TurnOnPotatos() 开启Potatos材质光源

CPropLinkedPortalDoor

[待完善]

使用方法

函数 签名 描述
GetPartnerInstance handle CPropLinkedPortalDoor(en)::GetPartnerInstance() 获取门链接伙伴的实例句柄
GetPartnername string CPropLinkedPortalDoor(en)::GetPartnername() 返回门的伙伴名称

CSceneEntity

继承 CBaseEntity

使用方法

函数 签名 描述
AddBroadcastTeamTarget void CSceneEntity::AddBroadcastTeamTarget(int) 通过索引将团队添加到广播列表
EstimateLength float CSceneEntity::EstimateLength() 返回场景长度(秒)
FindNamedEntity handle CSceneEntity::FindNamedEntity(string) 根据实体引用(如!target)从场景对象获取实际实体
IsPaused bool CSceneEntity::IsPaused() 检查当前场景是否暂停
IsPlayingBack bool CSceneEntity::IsPlayingBack() 检查当前场景是否正在播放
LoadSceneFromString bool CSceneEntity::LoadSceneFromString(string, string) 根据虚拟场景名和vcd字符串加载场景
RemoveBroadcastTeamTarget void CSceneEntity::RemoveBroadcastTeamTarget(int) 通过索引从广播列表移除团队


CScriptKeyValues

模型$keyvalues(en)块的脚本句柄表示。 子键是相同类的实例。


使用方法

函数 签名 描述
FindKey handle CScriptKeyValues::FindKey(string) 根据键名查找关联的KeyValues对象
GetFirstSubKey handle CScriptKeyValues::GetFirstSubKey() 获取第一个子键对象
GetKeyBool bool CScriptKeyValues::GetKeyBool(string) 获取键关联的布尔值
GetKeyFloat float CScriptKeyValues::GetKeyFloat(string) 获取键关联的浮点值
GetKeyInt int CScriptKeyValues::GetKeyInt(string) 获取键关联的整数值
GetKeyString string CScriptKeyValues::GetKeyString(string) 获取键关联的字符串值
GetNextKey handle CScriptKeyValues::GetNextKey() 获取子键组中的下一个键对象
IsKeyEmpty bool CScriptKeyValues::IsKeyEmpty(string) 检查键名是否没有值
ReleaseKeyValues void CScriptKeyValues::ReleaseKeyValues() 释放根KeyValues对象内容


CTriggerCamera

继承 CBaseEntity


使用方法

函数 签名 描述
GetFov int CTriggerCamera::GetFov() 获取相机当前FOV设置(整数)
SetFov void CTriggerCamera::SetFov(int, float) 设置相机FOV(整数角度)和FOV变化率(浮点)


Math

内置的Squirrel数学库


函数 签名 描述
abs int abs(float x) 返回x的整数绝对值
acos float acos(float x) 返回x的反余弦值
asin float asin(float x) 返回x的反正弦值
atan float atan(float x) 返回x的反正切值
atan2 float atan2(float x, float y) 返回x/y的反正切值
ceil float ceil(float x) 返回大于等于x的最小整数值
cos float cos(float x) 返回x的余弦值
exp float exp(float x) 返回x的指数值(e^x
fabs float fabs(float x) 返回x的浮点绝对值
floor float floor(float x) 返回小于等于x的最大整数值
log float log(float x) 返回x的自然对数
log10 float log10(float x) 返回x的以10为底对数
pow float pow(float x, float y) 返回xy次幂
rand int rand() 返回0到RAND_MAX间的伪随机整数
sin float sin(float x) 返回x的正弦值
sqrt float sqrt(float x) 返回x的平方根
srand void srand(float seed) 设置伪随机数生成器的种子
tan float tan(float x) 返回x的正切值

向量

表示一个x/y/z位置,被许多函数返回/传递。它以3个x/y/z位置作为参数。
可以对向量应用一些数学运算 - 任意两个向量之间的+/-,以及向量 * 数字(仅限此顺序)。所有三种运算都返回另一个向量。其他数学运算通过方法调用完成:


使用方法

函数 签名 描述
Cross Vector Vector::Cross(Vector other) 返回向量叉积 - this × other
Dot float Vector::Dot(Vector other) 返回向量点积 - this · other
Length float Vector::Length() 返回与原点距离
Length2D float Vector::Length2D() 返回与原点距离(忽略Z轴)
LengthSqr float Vector::LengthSqr() 返回与原点距离的平方(计算更快,无需平方根)
Length2DSqr float Vector::Length2DSqr() 返回与原点距离的平方(忽略Z轴,计算更快)
Norm float Vector::Norm() 将向量长度归一化为1,并返回原长度
ToKVString string Vector::ToKVString() 返回"X Y Z"格式字符串


其他函数

函数 签名 描述
Assert void Assert(exp, string message = null) 如果exp为false则抛出异常(可选消息)
CreateProp handle CreateProp(string classname, Vector origin, string modelname, int activity) 创建道具(类应为prop_physics风格实体)
CreateSceneEntity handle CreateSceneEntity(string) 创建用于播放指定场景的场景实体
DebugDrawBox void DebugDrawBox(Vector origin, Vector mins, Vector maxs, int r, int g, int b, int alpha, float duration) 绘制调试方框(需开发者模式),位于origin,尺寸为mins/maxs,持续duration秒(-1.0为1帧),颜色范围0-255
DebugDrawLine void DebugDrawLine(Vector start, Vector end, int r, int g, int b, bool hitTest, float duration) 绘制调试线(需开发者模式),持续duration秒,颜色范围0-255
DoIncludeScript bool DoIncludeScript(string filename, table scope) scope作用域执行脚本文件"scripts/vscripts/" + filename(可省略.nut扩展名)
IncludeScript bool IncludeScript(string filename, table scope = null) scope作用域(默认为this)执行脚本文件
DoEntFire void DoEntFire(string target, string action, string value, float delay, handle activator, handle caller) 生成实体I/O(en)事件
EntFire function EntFire(target, action, value, delay, activator) 生成实体I/O(en)事件(value/delay/activator可选)
EntFireByHandle void EntFireByHandle(handle target, string action, string value, float delay, handle activator, handle caller) 生成实体I/O事件(第一个参数为实体实例)
FrameTime float FrameTime() 获取服务器上一帧耗时
GetDeveloperLevel int GetDeveloperLevel() 获取'developer'级别
GetMapIndexInPlayOrder int GetMapIndexInPlayOrder() 获取创意工坊地图的游玩顺序索引(非工坊地图返回-2)
GetMapName string GetMapName() 获取当前地图名称
GetNumMapsPlayed int GetNumMapsPlayed() 获取玩家已游玩的创意工坊地图数量
GetPlayerSilenceDuration float GetPlayerSilenceDuration(int player_index) 获取指定玩家麦克风静默时长
IsMultiplayer bool IsMultiplayer() 检查是否为多人游戏
LoopSinglePlayerMaps bool LoopSinglePlayerMaps() 检查loopsingleplayermaps变量是否启用(多人游戏仍有效)
RandomFloat float RandomFloat(float min, float max) 生成范围内随机浮点数(包含边界)
RandomInt int RandomInt(int min, int max) 生成范围内随机整数(包含边界)
RecordAchievementEvent void RecordAchievementEvent(string name, int player_index) 解锁成就或增加进度
RequestMapRating void RequestMapRating() 在创意工坊地图弹出评分对话框
RetrieveNativeSignature void RetrieveNativeSignature(string nativeFunction) [待完善]
SendToConsole void SendToConsole(string command) 向控制台发送命令(多人游戏中视为主机命令)
SetDucking void SetDucking(string, string, float) 设置音频闪避通道级别
SetMapAsPlayed int SetMapAsPlayed() 将当前地图添加到游玩顺序(非工坊地图返回-2)
ShowMessage void ShowMessage(string) 向所有客户端显示HUD消息
Time float Time() 获取当前服务器时间
TraceLine float TraceLine(Vector start, Vector end, handle ignored_ent) 给定起点/终点和忽略实体,返回击中世界的线段比例(不检测实体)
UniqueString string UniqueString(string suffix = "") 生成脚本VM生命周期内唯一的字符串(可选前缀)
DoUniqueString string DoUniqueString(string suffix) 生成唯一字符串(功能同UniqueString
__ReplaceClosures void __ReplaceClosures(function script, table scope) script_reload_服务器命令调用的内部函数

仅限单人模式

这些函数只能在单人游戏中使用,多人游戏中使用可能导致错误。

函数 签名 描述
GetPlayer handle GetPlayer() 获取玩家实体
GivePlayerPortalgun void GivePlayerPortalgun() 给予玩家仅限蓝色传送门枪
PrecacheMovie void PrecacheMovie(string) 预加载指定电影(仅在地图生成时的'Precache()'函数中有效)
ScriptShowHudMessageAll void ScriptShowHudMessageAll(string, float) 显示居中文本消息(持续指定秒数)
ScriptSteamShowURL bool ScriptSteamShowURL(string) 在Steam叠加层显示指定URL(需完整地址如http://www.steamgames.com/)
TryDLC1InstalledOrCatch void TryDLC1InstalledOrCatch() 如果未安装Peer Review DLC则抛出异常(当前PC版本中无效)
UpgradePlayerPortalgun void UpgradePlayerPortalgun() 将玩家传送门枪升级为可发射橙色传送门
UpgradePlayerPotatogun void UpgradePlayerPotatogun() 将玩家传送门枪升级为带PotatOS的橙色传送门枪

仅限多人模式

这些函数只能在多人游戏中使用,单人游戏中使用可能导致错误。

函数 签名 描述
AddBranchLevelName void AddBranchLevelName(int, string) 向指定分支添加关卡
Note.png注意:合作地图中必须至少调用一次, 否则玩家可能会动弹不得
AddCoopCreditsName void AddCoopCreditsName(string) 向合作模式演职员表添加名称
AddGladosSpokenFlags void AddGladosSpokenFlags(int, int) 添加特定对话行的位标志(按会话追踪)
CoopGladosBlowUpBots void CoopGladosBlowUpBots() 摧毁两个机器人并阻止重生(用于合作课程1到4最后一关)
CoopGetNumPortalsPlaced int CoopGetNumPortalsPlaced() 获取玩家已放置的传送门数量
CoopGetLevelsCompletedThisBranch int CoopGetLevelsCompletedThisBranch() 获取当前分支中已完成的关卡数
CoopGetBranchTotalLevelCount int CoopGetBranchTotalLevelCount() 获取当前分支的关卡总数
CoopSetCameFromLastDLCMap void CoopSetCameFromLastDLCMap(bool) 设置玩家是否来自最后的合作DLC地图(合作课程6)
CoopSetMapRunTime void CoopSetMapRunTime(float runLength) 设置完成合作地图的时间(可能与Triple Crown(三皇冠)成就相关)
GetBluePlayerIndex int GetBluePlayerIndex() 获取蓝色玩家索引
GetCameFromLastDLCMap bool GetCameFromLastDLCMap() 检查是否来自最后的合作DLC地图
GetCoopBranchLevelIndex int GetCoopBranchLevelIndex(int) 获取指定分支的当前选定关卡索引
GetCoopSectionIndex int GetCoopSectionIndex() 获取合作玩家选择加载的章节索引
GetGladosSpokenFlags int GetGladosSpokenFlags(int) 获取特定对话行的位标志
GetHaveSeenDLCTubesReveal bool GetHaveSeenDLCTubesReveal() 检查玩家是否已观看DLC管道
GetHighestActiveBranch int GetHighestActiveBranch() 获取大厅中已解锁的最高关卡
GetNumPlayersConnected int GetNumPlayersConnected() 获取已连接玩家数(通常为2)
GetOrangePlayerIndex int GetOrangePlayerIndex() 获取橙色玩家索引
GetPlayerDeathCount int GetPlayerDeathCount(int player) 获取指定玩家在会话中的死亡次数
IsBranchComplete bool IsBranchComplete(int course) 检查分支所有关卡是否已完成
IsLevelComplete bool IsLevelComplete(int course, int level) 检查指定分支关卡是否已完成
IsLocalSplitScreen bool IsLocalSplitScreen() 检查是否为本地分屏模式
IsPlayerBranchComplete bool IsPlayerBranchComplete(int player, int course) 检查指定玩家是否完成分支所有关卡
IsPlayerLevelComplete bool IsPlayerLevelComplete(int, int, int) 检查指定玩家是否完成特定分支关卡
MarkMapComplete void MarkMapComplete(string) 标记地图为已完成(双方玩家)
NotifySpeedRunSuccess void NotifySpeedRunSuccess(int runLength, string mapname) 通知客户端速通成功(用于Triple Crown(三皇冠)成就)
SaveMPStatsData void SaveMPStatsData() 保存多人游戏统计信息(记分牌)
SetHaveSeenDLCTubesReveal void SetHaveSeenDLCTubesReveal() 标记玩家已看见DLC管道

另见