跳至正文
版本:bleeding-edge 🩸

👩‍💻 玩家

玩家是代表鼠标和键盘背后个体的实体。当连接到服务器时,玩家会自动生成。

👪Inheritance
This class shares methods and events from Base Entity.
🧑‍💻API Source
This page is auto-generated! The Functions, Properties and Events described here are defined in our GitHub's API Repository! Feel free to commit suggestions and changes to the source .json API files!

主控

🟥 You cannot spawn or Destroy Players.

🎒 示例

-- Spawns and possess a Character when a Player joins the server
Player.Subscribe("Spawn", function(player)
local new_char = Character(Vector(), Rotator(), "nanos-world::SK_Male")
player:Possess(new_char)
end)

-- Destroys the Character when the Player leaves the server
Player.Subscribe("Destroy", function(player)
local character = player:GetControlledCharacter()
if (character) then
character:Destroy()
end
end)

🗿 静态函数

Inherited Entity Static Functions
Player inherits from Base Entity Class, sharing it's methods and functions:
Base Entityscripting-reference/classes/base-classes/entity
ReturnsNameDescription
table of Base EntityGetAll返回一个包含调用此方法的类中所有实体的表
Base EntityGetByIndex返回该类中指定索引处的特定实体
integerGetCount返回该类当前存在的实体数量
table of tableGetInheritedClasses获取使用 继承系统 创建的、直接继承自该类的所有子类列表
iteratorGetPairs返回一个包含该类所有实体的迭代器,用于 pairs() 循环
table or nilGetParentClass如果该类是使用 继承系统 创建的,则获取其父类
tableInherit使用 继承系统 继承此类
booleanIsChildOf如果该类是使用 继承系统 创建的,检查此类是否为另一个类的子类
functionSubscribe为该类的所有实体订阅一个 事件
functionSubscribeRemote订阅从服务器调用的自定义远程事件
Unsubscribe退订此包内该类中此 事件 的所有回调,或者仅取消传入的特定回调
ReturnsNameDescription
Player or nilGetBySteamID通过 Steam ID 获取玩家

GetBySteamID

通过 Steam ID 获取玩家
local player = Player.GetBySteamID(steam_id)

Parameters

TypeParameterDefaultDescription
stringsteam_id Required parameter No description provided

Returns

TypeDescription
Player or nilplayer

🦠 函数

Inherited Entity Functions
Player inherits from Base Entity Class, sharing it's methods and functions:
Base Entityscripting-reference/classes/base-classes/entity
ReturnsNameDescription
BroadcastRemoteEvent直接在此实体上向所有玩家调用自定义远程事件
BroadcastRemoteInRadiusEvent直接针对此实体调用自定义远程事件,并将该事件传递给半径范围内的所有玩家
CallRemoteEvent直接在此实体上向特定玩家调用自定义远程事件
CallRemoteEvent直接在此实体上调用自定义远程事件
CallRemotePlayersEvent直接在此实体上调用自定义远程事件,并将事件传递给玩家列表
Destroy销毁该实体
FinishSpawn完成生成过程,如果实体是通过 defer_spawn 生成的,则将实体发送给客户端
table of stringGetAllValuesKeys获取所有值键的列表
tableGetClass获取该实体的类
integerGetID获取该实体的全网通用网络 ID(在客户端和服务器上相同)
anyGetValue获取此实体上存储在给定键处的
booleanHasAuthority获取本地上下文是否对此实体拥有主控(如果由客户端生成则为 true,由服务器生成则为 false)
booleanIsA递归检查此实体是否继承自某个类
booleanIsBeingDestroyed如果该实体正在被销毁,则返回 true
booleanIsValid如果该实体有效(即未被销毁且指向一个有效的实体),则返回 true
SetValue在此实体中设置一个
functionSubscribe在这个特定实体上订阅一个事件
functionSubscribeRemote在这个特定实体上订阅一个从服务器调用的自定义远程事件
Unsubscribe退订此包内该实体中此 事件 的所有回调,或者仅取消传入的特定回调
ReturnsNameDescription
AttachCameraTo将玩家的相机附加到一个 Actor 上
Ban将玩家从服务器封禁
Connect将玩家重定向到另一个服务器
stringGetAccountIconURL返回一个可在 WebUI 和控件中使用的 URL,用于显示玩家的 Steam 头像 (64x64)
stringGetAccountIDNo description provided
stringGetAccountNameNo description provided
floatGetCameraArmLengthNo description provided
VectorGetCameraLocationNo description provided
RotatorGetCameraRotationNo description provided
Base Pawn or nilGetControlledCharacterNo description provided
integerGetDimension获取此玩家的维度
stringGetIPNo description provided
stringGetNameNo description provided
integerGetPingNo description provided
stringGetSteamIDNo description provided
table of integerGetVOIPListeningChannels返回该玩家正在收听的语音通话频道列表
table of integerGetVOIPSpeakingChannels返回该玩家当前正在发言的语音通话频道列表
booleanIsHostNo description provided
booleanIsLocalPlayerNo description provided
booleanIsVOIPMuted返回该玩家的语音通话是否已被静音
Kick将玩家从服务器踢出
Possess使玩家附身并控制一个 Pawn(角色)
ResetCamera将相机重置为默认状态(取消旁观并解除附加)
RotateCameraTo平滑移动玩家的相机旋转
SetCameraArmLength设置玩家的相机悬臂长度(弹簧臂长度)
SetCameraFOV设置玩家的相机视场角(在未附身角色时生效)
SetCameraLocation设置玩家的相机位置(仅在未附身任何角色时有效)
SetCameraRotation设置玩家的相机旋转
SetCameraSocketOffset设置玩家的相机插槽偏移量(弹簧臂偏移量)
SetCameraSpeedSettings设置玩家的相机速度设置(在未附身角色时生效)
SetDimension设置此玩家的维度
SetDistanceOptimizationMultiplier设置此玩家的距离优化系数
SetManualCameraFade以给定的不透明度开启相机淡入淡出
SetName设置玩家的名称
SetVOIPGlobalAllChannelsSetting设置所有全局频道的语音通话设置
SetVOIPGlobalChannelSetting设置特定全局频道的语音通话设置
SetVOIPGlobalHighPassFilter设置全局语音通话高通滤波器的截止频率
SetVOIPGlobalLowPassFilter设置全局语音通话低通滤波器的截止频率
SetVOIPGlobalVolume设置全局语音通话的音量。它仅影响全局频道
SetVOIPLocalMaxDistance设置本地/邻近语音通话的最大距离。这也会影响网络使用率
SetVOIPLocalSetting设置本地/邻近的语音通话设置
SetVOIPLocalVolume设置本地/邻近语音通话的输入/输出音量。它仅影响本地/邻近频道
SetVOIPMuted为该玩家静音或取消静音语音通话
Spectate旁观其他玩家
StartCameraFade使相机淡入/淡出到某纯色
StopCameraFade停止相机淡入淡出。
TranslateCameraTo平滑移动玩家的相机位置(仅在未附身任何角色时有效)
UnPossess将玩家从角色中解除控制

AttachCameraTo

将玩家的相机附加到一个 Actor 上
my_player:AttachCameraTo(actor, socket_offset?, blend_speed?)

Parameters

TypeParameterDefaultDescription
Base Actoractor Required parameter No description provided
Vectorsocket_offset?Vector(0, 0, 0)
No description provided
floatblend_speed?0.0
No description provided

Ban

将玩家从服务器封禁
my_player:Ban(reason)

Parameters

TypeParameterDefaultDescription
stringreason Required parameter No description provided

Connect

将玩家重定向到另一个服务器
my_player:Connect(IP, password?)

Parameters

TypeParameterDefaultDescription
stringIP Required parameter No description provided
stringpassword?
服务器密码

GetAccountIconURL

返回一个可在 WebUI 和控件中使用的 URL,用于显示玩家的 Steam 头像 (64x64)
local account_icon_url = my_player:GetAccountIconURL()

Returns

TypeDescription
stringaccount_icon_url

GetAccountID

local account_id = my_player:GetAccountID()

Returns

TypeDescription
stringaccount_id

GetAccountName

local account_name = my_player:GetAccountName()

Returns

TypeDescription
stringaccount_name

GetCameraArmLength

local length = my_player:GetCameraArmLength(return_base?)

Parameters

TypeParameterDefaultDescription
booleanreturn_base?false
是否返回当前值 (false) 或基础值 (true)。基础值是通过 SetCameraArmLength() 设置的相同值。如果你想获取通过 SetCameraArmLength() 设置的原始值而不是当前的(插值)值,请使用基础值。

Returns

TypeDescription
floatlength

See also SetCameraArmLength.


GetCameraLocation

local location = my_player:GetCameraLocation()

Returns

TypeDescription
Vectorlocation

See also SetCameraLocation.


GetCameraRotation

local rotation = my_player:GetCameraRotation()

Returns

TypeDescription
Rotatorrotation

See also SetCameraRotation.


GetControlledCharacter

local controlled_character = my_player:GetControlledCharacter()

Returns

TypeDescription
Base Pawn or nilcontrolled_character

GetDimension

获取此玩家的维度
local dimension = my_player:GetDimension()

Returns

TypeDescription
integerdimension

See also SetDimension, DimensionChange.


GetIP

local ip = my_player:GetIP()

Returns

TypeDescription
stringip

GetName

local player_name = my_player:GetName()

Returns

TypeDescription
stringplayer_name

See also SetName.


GetPing

local ping = my_player:GetPing()

Returns

TypeDescription
integerping

GetSteamID

local steam_id = my_player:GetSteamID()

Returns

TypeDescription
stringsteam_id

GetVOIPListeningChannels

返回该玩家正在收听的语音通话频道列表
local ret = my_player:GetVOIPListeningChannels()

Returns

TypeDescription
table of integer频道索引列表

GetVOIPSpeakingChannels

返回该玩家当前正在发言的语音通话频道列表
local ret = my_player:GetVOIPSpeakingChannels()

Returns

TypeDescription
table of integer频道索引列表

IsHost

local is_host = my_player:IsHost()

Returns

TypeDescription
booleanis_host

IsLocalPlayer

local is_local_player = my_player:IsLocalPlayer()

Returns

TypeDescription
booleanis_local_player

IsVOIPMuted

返回该玩家的语音通话是否已被静音
local ret = my_player:IsVOIPMuted()

Returns

TypeDescription
booleanNo description provided

See also SetVOIPMuted.


Kick

将玩家从服务器踢出
my_player:Kick(reason)

Parameters

TypeParameterDefaultDescription
stringreason Required parameter No description provided

Possess

使玩家附身并控制一个 Pawn(角色)
my_player:Possess(new_pawn, blend_time?, exp?)

Parameters

TypeParameterDefaultDescription
Base Pawnnew_pawn Required parameter No description provided
floatblend_time?0
No description provided
floatexp?0
No description provided

ResetCamera

将相机重置为默认状态(取消旁观并解除附加)
my_player:ResetCamera()

RotateCameraTo

平滑移动玩家的相机旋转
my_player:RotateCameraTo(rotation, time, exp?)

Parameters

TypeParameterDefaultDescription
Rotatorrotation Required parameter No description provided
floattime Required parameter No description provided
floatexp?0
用于平滑插值的指数,使用 0 表示线性运动

SetCameraArmLength

设置玩家的相机悬臂长度(弹簧臂长度)
my_player:SetCameraArmLength(length, force?)

Parameters

TypeParameterDefaultDescription
floatlength Required parameter No description provided
booleanforce?false
是否绕过插值并直接将其设为目标值

See also GetCameraArmLength.


SetCameraFOV

设置玩家的相机视场角(在未附身角色时生效)
my_player:SetCameraFOV(fov?)

Parameters

TypeParameterDefaultDescription
floatfov?90
值必须在 5 到 170 之间。留空可重置为默认值。

SetCameraLocation

设置玩家的相机位置(仅在未附身任何角色时有效)
my_player:SetCameraLocation(location)

Parameters

TypeParameterDefaultDescription
Vectorlocation Required parameter No description provided

See also GetCameraLocation.


SetCameraRotation

设置玩家的相机旋转
my_player:SetCameraRotation(rotation)

Parameters

TypeParameterDefaultDescription
Rotatorrotation Required parameter No description provided

See also GetCameraRotation.


SetCameraSocketOffset

设置玩家的相机插槽偏移量(弹簧臂偏移量)
my_player:SetCameraSocketOffset(socket_offset)

Parameters

TypeParameterDefaultDescription
Vectorsocket_offset Required parameter No description provided

SetCameraSpeedSettings

设置玩家的相机速度设置(在未附身角色时生效)
my_player:SetCameraSpeedSettings(max_speed?, acceleration?, deceleration?, turning_boost?)

Parameters

TypeParameterDefaultDescription
floatmax_speed?1200
允许的最大速度大小
floatacceleration?4000
由输入施加的加速度(速度变化率)
floatdeceleration?4000
当没有输入时施加的减速度(速度变化率)
floatturning_boost?8
影响改变方向时施加的额外力的设置,使转向时的漂移更少,响应更灵敏。速度大小不允许增加,那只能由正常加速度引起。在大幅度改变方向时它可能会减少。较大的值会施加额外力以更快地达到目标方向,而零值会禁用任何额外的转向力。

SetDimension

设置此玩家的维度
my_player:SetDimension(dimension)

Parameters

TypeParameterDefaultDescription
integerdimension Required parameter No description provided

See also GetDimension, DimensionChange.


SetDistanceOptimizationMultiplier

设置此玩家的距离优化系数。
值为 0 时禁用优化。小于 1 的值会减弱优化效果,而大于 1 的值会增强优化效果
my_player:SetDistanceOptimizationMultiplier(multiplier)

Parameters

TypeParameterDefaultDescription
floatmultiplier Required parameter No description provided

SetManualCameraFade

以给定的不透明度开启相机淡入淡出。不自动播放动画,允许用户自行播放动画。调用 StopCameraFade 可以关闭淡入淡出。
my_player:SetManualCameraFade(in_fade_amount, color, in_fade_audio)

Parameters

TypeParameterDefaultDescription
floatin_fade_amount Required parameter 范围 [0..1],其中 0 为完全透明,1 为完全不透明的纯色。
Colorcolor Required parameter No description provided
booleanin_fade_audio Required parameter No description provided

SetName

设置玩家的名称
my_player:SetName(player_name)

Parameters

TypeParameterDefaultDescription
stringplayer_name Required parameter No description provided

See also GetName.


SetVOIPGlobalAllChannelsSetting

设置所有全局频道的语音通话设置
my_player:SetVOIPGlobalAllChannelsSetting(setting)

Parameters

TypeParameterDefaultDescription
VOIPSettingsetting Required parameter No description provided

See also SetVOIPGlobalChannelSetting, GetVOIPListeningChannels, GetVOIPSpeakingChannels, VOIPGlobalChannelSettingChange.


SetVOIPGlobalChannelSetting

设置特定全局频道的语音通话设置
my_player:SetVOIPGlobalChannelSetting(channel, setting)

Parameters

TypeParameterDefaultDescription
integerchannel Required parameter 0-63
VOIPSettingsetting Required parameter No description provided

See also SetVOIPGlobalAllChannelsSetting, GetVOIPListeningChannels, GetVOIPSpeakingChannels, VOIPGlobalChannelSettingChange.


SetVOIPGlobalHighPassFilter

设置全局语音通话高通滤波器的截止频率。将其设为 0 以禁用它
my_player:SetVOIPGlobalHighPassFilter(threshold)

Parameters

TypeParameterDefaultDescription
integerthreshold Required parameter No description provided

See also SetVOIPGlobalLowPassFilter.


SetVOIPGlobalLowPassFilter

设置全局语音通话低通滤波器的截止频率。将其设为 0 以禁用它
my_player:SetVOIPGlobalLowPassFilter(threshold)

Parameters

TypeParameterDefaultDescription
integerthreshold Required parameter No description provided

See also SetVOIPGlobalHighPassFilter.


SetVOIPGlobalVolume

设置全局语音通话的音量。它仅影响全局频道
my_player:SetVOIPGlobalVolume(volume)

Parameters

TypeParameterDefaultDescription
floatvolume Required parameter No description provided

SetVOIPLocalMaxDistance

设置本地/邻近语音通话的最大距离。这也会影响网络使用率
my_player:SetVOIPLocalMaxDistance(max_distance)

Parameters

TypeParameterDefaultDescription
integermax_distance Required parameter 衰减距离。默认值为 3600

See also SetVOIPLocalSetting, SetVOIPLocalVolume.


SetVOIPLocalSetting

设置本地/邻近的语音通话设置
my_player:SetVOIPLocalSetting(setting)

Parameters

TypeParameterDefaultDescription
VOIPSettingsetting Required parameter No description provided

See also SetVOIPLocalMaxDistance, SetVOIPLocalVolume, VOIPLocalSettingChange.


SetVOIPLocalVolume

设置本地/邻近语音通话的输入/输出音量。它仅影响本地/邻近频道
my_player:SetVOIPLocalVolume(volume)

Parameters

TypeParameterDefaultDescription
floatvolume Required parameter No description provided

See also SetVOIPLocalSetting, SetVOIPLocalMaxDistance, VOIPLocalSettingChange.


SetVOIPMuted

为该玩家静音或取消静音语音通话
my_player:SetVOIPMuted(is_muted)

Parameters

TypeParameterDefaultDescription
booleanis_muted Required parameter No description provided

See also IsVOIPMuted.


Spectate

旁观其他玩家
my_player:Spectate(player, blend_speed?)

Parameters

TypeParameterDefaultDescription
Playerplayer Required parameter No description provided
floatblend_speed?0
No description provided

StartCameraFade

使相机淡入/淡出到某种纯色。自动播放动画
my_player:StartCameraFade(from_alpha, to_alpha, duration, to_color, should_fade_audio?, hold_when_finished?)

Parameters

TypeParameterDefaultDescription
floatfrom_alpha Required parameter 开始淡入淡出的 Alpha 值。范围 [0..1],其中 0 为完全透明,1 为完全不透明的纯色。
floatto_alpha Required parameter 结束淡入淡出的 Alpha 值。
floatduration Required parameter 淡入淡出应当持续的时间,以秒为单位。
Colorto_color Required parameter 要淡入/淡出到的颜色。
booleanshould_fade_audio?false
如果为 True,则音频音量将随纯色的 Alpha 值一起淡入淡出。
booleanhold_when_finished?false
如果为 True,淡入淡出将保持在 ToAlpha 值,直到被显式停止(例如使用 StopCameraFade)

StopCameraFade

停止相机淡入淡出。
my_player:StopCameraFade()

TranslateCameraTo

平滑移动玩家的相机位置(仅在未附身任何角色时有效)
my_player:TranslateCameraTo(location, time, exp?)

Parameters

TypeParameterDefaultDescription
Vectorlocation Required parameter No description provided
floattime Required parameter No description provided
floatexp?0
用于平滑插值的指数,使用 0 表示线性运动

UnPossess

将玩家从角色中解除控制
my_player:UnPossess()

🚀 事件

Inherited Entity Events
Player inherits from Base Entity Class, sharing it's events:
Base Entityscripting-reference/classes/base-classes/entity
NameDescription
ClassRegister当使用 继承系统 注册一个新类时触发
Destroy当实体被销毁时触发
Spawn当实体被生成/创建时触发
ValueChange当实体通过 :SetValue() 改变了值时触发
NameDescription
DimensionChange当玩家改变其维度时触发
Possess当玩家开始控制一个 Pawn(角色)时触发
Ready当玩家准备就绪时触发(客户端已完全加入,加载了地图和所有实体,并准备好进行游戏)
UnPossess一个 Pawn(角色)与玩家解除了附身
VOIP当玩家开始/结束使用语音通话时
VOIPGlobalChannelSettingChange当该玩家的全局语音通话频道设置发生更改时触发
VOIPLocalSettingChange当该玩家的本地语音通话设置发生更改时触发

DimensionChange

当玩家改变其维度时触发
Player.Subscribe("DimensionChange", function(self, old_dimension, new_dimension)
-- DimensionChange was called
end)

Arguments

TypeArgumentDescription
PlayerselfNo description provided
integerold_dimensionNo description provided
integernew_dimensionNo description provided

See also SetDimension, GetDimension.


Possess

当玩家开始控制一个 Pawn(角色)时触发
Player.Subscribe("Possess", function(self, pawn)
-- Possess was called
end)

Arguments

TypeArgumentDescription
PlayerselfNo description provided
Base PawnpawnNo description provided

See also GetControlledCharacter.


Ready

当玩家准备就绪时触发(客户端已完全加入,加载了地图和所有实体,并准备好进行游戏)
Player.Subscribe("Ready", function(self)
-- Ready was called
end)

Arguments

TypeArgumentDescription
PlayerselfNo description provided

UnPossess

一个 Pawn(角色)与玩家解除了附身
Player.Subscribe("UnPossess", function(self, pawn)
-- UnPossess was called
end)

Arguments

TypeArgumentDescription
PlayerselfNo description provided
Base PawnpawnNo description provided

See also GetControlledCharacter.


VOIP

当玩家开始/结束使用语音通话时

当 'is_talking' 为 true 时,返回 false 可阻止播放此语音流(在服务端将阻止所有人的播放,在客户端将仅阻止该客户端的播放)
Player.Subscribe("VOIP", function(self, is_talking)
-- VOIP was called
return true
end)

Arguments

TypeArgumentDescription
PlayerselfNo description provided
booleanis_talkingNo description provided

VOIPGlobalChannelSettingChange

当该玩家的全局语音通话频道设置发生更改时触发
Player.Subscribe("VOIPGlobalChannelSettingChange", function(self, channel, old_setting, new_setting)
-- VOIPGlobalChannelSettingChange was called
end)

Arguments

TypeArgumentDescription
PlayerselfNo description provided
integerchannelNo description provided
VOIPSettingold_settingNo description provided
VOIPSettingnew_settingNo description provided

See also SetVOIPGlobalChannelSetting, SetVOIPGlobalAllChannelsSetting.


VOIPLocalSettingChange

当该玩家的本地语音通话设置发生更改时触发
Player.Subscribe("VOIPLocalSettingChange", function(self, old_setting, new_setting)
-- VOIPLocalSettingChange was called
end)

Arguments

TypeArgumentDescription
PlayerselfNo description provided
VOIPSettingold_settingNo description provided
VOIPSettingnew_settingNo description provided

See also SetVOIPLocalSetting.