玩家是代表鼠标和键盘背后个体的实体。当连接到服务器时,玩家会自动生成。
👪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.
🎒 示例
Player.Subscribe("Spawn", function(player)
local new_char = Character(Vector(), Rotator(), "nanos-world::SK_Male")
player:Possess(new_char)
end)
Player.Subscribe("Destroy", function(player)
local character = player:GetControlledCharacter()
if (character) then
character:Destroy()
end
end)
🗿 静态函数
Inherited Entity Static Functions


GetBySteamID
通过 Steam ID 获取玩家
local player = Player.GetBySteamID(steam_id)
Parameters
| Type | Parameter | Default | Description |
|---|
| string | steam_id | Required parameter | No description provided |
🦠 函数
Inherited Entity Functions


AttachCameraTo
将玩家的相机附加到一个 Actor 上
my_player:AttachCameraTo(actor, socket_offset?, blend_speed?)
Parameters
| Type | Parameter | Default | Description |
|---|
| Base Actor | actor | Required parameter | No description provided |
| Vector | socket_offset? | Vector(0, 0, 0)
| No description provided |
| float | blend_speed? | 0.0
| No description provided |


Ban
将玩家从服务器封禁
Parameters
| Type | Parameter | Default | Description |
|---|
| string | reason | Required parameter | No description provided |


Connect
将玩家重定向到另一个服务器
my_player:Connect(IP, password?)
Parameters
| Type | Parameter | Default | Description |
|---|
| string | IP | Required parameter | No description provided |
| string | password? |
| 服务器密码 |


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


GetAccountID
local account_id = my_player:GetAccountID()
Returns
| Type | Description |
|---|
| string | account_id |


GetAccountName
local account_name = my_player:GetAccountName()
Returns
| Type | Description |
|---|
| string | account_name |


GetCameraArmLength
local length = my_player:GetCameraArmLength(return_base?)
Parameters
| Type | Parameter | Default | Description |
|---|
| boolean | return_base? | false
| 是否返回当前值 (false) 或基础值 (true)。基础值是通过 SetCameraArmLength() 设置的相同值。如果你想获取通过 SetCameraArmLength() 设置的原始值而不是当前的(插值)值,请使用基础值。 |
Returns
| Type | Description |
|---|
| float | length |
See also SetCameraArmLength.


GetCameraLocation
local location = my_player:GetCameraLocation()
See also SetCameraLocation.


GetCameraRotation
local rotation = my_player:GetCameraRotation()
See also SetCameraRotation.


GetControlledCharacter
local controlled_character = my_player:GetControlledCharacter()


GetDimension
获取此玩家的维度
local dimension = my_player:GetDimension()
See also SetDimension, DimensionChange.


GetIP
local ip = my_player:GetIP()


GetName
local player_name = my_player:GetName()
Returns
| Type | Description |
|---|
| string | player_name |
See also SetName.


GetPing
local ping = my_player:GetPing()


GetSteamID
local steam_id = my_player:GetSteamID()


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


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


IsHost
local is_host = my_player:IsHost()


IsLocalPlayer
local is_local_player = my_player:IsLocalPlayer()
Returns
| Type | Description |
|---|
| boolean | is_local_player |


IsVOIPMuted
返回该玩家的语音通话是否已被静音
local ret = my_player:IsVOIPMuted()
Returns
| Type | Description |
|---|
| boolean | No description provided |
See also SetVOIPMuted.


Kick
将玩家从服务器踢出
Parameters
| Type | Parameter | Default | Description |
|---|
| string | reason | Required parameter | No description provided |


Possess
使玩家附身并控制一个 Pawn(角色)
my_player:Possess(new_pawn, blend_time?, exp?)
Parameters
| Type | Parameter | Default | Description |
|---|
| Base Pawn | new_pawn | Required parameter | No description provided |
| float | blend_time? | 0
| No description provided |
| float | exp? | 0
| No description provided |


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


RotateCameraTo
平滑移动玩家的相机旋转
my_player:RotateCameraTo(rotation, time, exp?)
Parameters
| Type | Parameter | Default | Description |
|---|
| Rotator | rotation | Required parameter | No description provided |
| float | time | Required parameter | No description provided |
| float | exp? | 0
| 用于平滑插值的指数,使用 0 表示线性运动 |


SetCameraArmLength
设置玩家的相机悬臂长度(弹簧臂长度)
my_player:SetCameraArmLength(length, force?)
Parameters
| Type | Parameter | Default | Description |
|---|
| float | length | Required parameter | No description provided |
| boolean | force? | false
| 是否绕过插值并直接将其设为目标值 |
See also GetCameraArmLength.


SetCameraFOV
设置玩家的相机视场角(在未附身角色时生效)
my_player:SetCameraFOV(fov?)
Parameters
| Type | Parameter | Default | Description |
|---|
| float | fov? | 90
| 值必须在 5 到 170 之间。留空可重置为默认值。 |


SetCameraLocation
设置玩家的相机位置(仅在未附身任何角色时有效)
my_player:SetCameraLocation(location)
Parameters
| Type | Parameter | Default | Description |
|---|
| Vector | location | Required parameter | No description provided |
See also GetCameraLocation.


SetCameraRotation
设置玩家的相机旋转
my_player:SetCameraRotation(rotation)
Parameters
| Type | Parameter | Default | Description |
|---|
| Rotator | rotation | Required parameter | No description provided |
See also GetCameraRotation.


SetCameraSocketOffset
设置玩家的相机插槽偏移量(弹簧臂偏移量)
my_player:SetCameraSocketOffset(socket_offset)
Parameters
| Type | Parameter | Default | Description |
|---|
| Vector | socket_offset | Required parameter | No description provided |


SetCameraSpeedSettings
设置玩家的相机速度设置(在未附身角色时生效)
my_player:SetCameraSpeedSettings(max_speed?, acceleration?, deceleration?, turning_boost?)
Parameters
| Type | Parameter | Default | Description |
|---|
| float | max_speed? | 1200
| 允许的最大速度大小 |
| float | acceleration? | 4000
| 由输入施加的加速度(速度变化率) |
| float | deceleration? | 4000
| 当没有输入时施加的减速度(速度变化率) |
| float | turning_boost? | 8
| 影响改变方向时施加的额外力的设置,使转向时的漂移更少,响应更灵敏。速度大小不允许增加,那只能由正常加速度引起。在大幅度改变方向时它可能会减少。较大的值会施加额外力以更快地达到目标方向,而零值会禁用任何额外的转向力。 |


SetDimension
设置此玩家的维度
my_player:SetDimension(dimension)
Parameters
| Type | Parameter | Default | Description |
|---|
| integer | dimension | Required parameter | No description provided |
See also GetDimension, DimensionChange.


SetDistanceOptimizationMultiplier
设置此玩家的距离优化系数。
值为 0 时禁用优化。小于 1 的值会减弱优化效果,而大于 1 的值会增强优化效果
my_player:SetDistanceOptimizationMultiplier(multiplier)
Parameters
| Type | Parameter | Default | Description |
|---|
| float | multiplier | Required parameter | No description provided |


SetManualCameraFade
以给定的不透明度开启相机淡入淡出。不自动播放动画,允许用户自行播放动画。调用 StopCameraFade 可以关闭淡入淡出。
my_player:SetManualCameraFade(in_fade_amount, color, in_fade_audio)
Parameters
| Type | Parameter | Default | Description |
|---|
| float | in_fade_amount | Required parameter | 范围 [0..1],其中 0 为完全透明,1 为完全不透明的纯色。 |
| Color | color | Required parameter | No description provided |
| boolean | in_fade_audio | Required parameter | No description provided |


SetName
设置玩家的名称
my_player:SetName(player_name)
Parameters
| Type | Parameter | Default | Description |
|---|
| string | player_name | Required parameter | No description provided |
See also GetName.


SetVOIPGlobalAllChannelsSetting
设置所有全局频道的语音通话设置
my_player:SetVOIPGlobalAllChannelsSetting(setting)
Parameters
| Type | Parameter | Default | Description |
|---|
| VOIPSetting | setting | Required parameter | No description provided |
See also SetVOIPGlobalChannelSetting, GetVOIPListeningChannels, GetVOIPSpeakingChannels, VOIPGlobalChannelSettingChange.


SetVOIPGlobalChannelSetting
设置特定全局频道的语音通话设置
my_player:SetVOIPGlobalChannelSetting(channel, setting)
Parameters
| Type | Parameter | Default | Description |
|---|
| integer | channel | Required parameter | 0-63 |
| VOIPSetting | setting | Required parameter | No description provided |
See also SetVOIPGlobalAllChannelsSetting, GetVOIPListeningChannels, GetVOIPSpeakingChannels, VOIPGlobalChannelSettingChange.


SetVOIPGlobalHighPassFilter
设置全局语音通话高通滤波器的截止频率。将其设为 0 以禁用它
my_player:SetVOIPGlobalHighPassFilter(threshold)
Parameters
| Type | Parameter | Default | Description |
|---|
| integer | threshold | Required parameter | No description provided |
See also SetVOIPGlobalLowPassFilter.


SetVOIPGlobalLowPassFilter
设置全局语音通话低通滤波器的截止频率。将其设为 0 以禁用它
my_player:SetVOIPGlobalLowPassFilter(threshold)
Parameters
| Type | Parameter | Default | Description |
|---|
| integer | threshold | Required parameter | No description provided |
See also SetVOIPGlobalHighPassFilter.


SetVOIPGlobalVolume
设置全局语音通话的音量。它仅影响全局频道
my_player:SetVOIPGlobalVolume(volume)
Parameters
| Type | Parameter | Default | Description |
|---|
| float | volume | Required parameter | No description provided |


SetVOIPLocalMaxDistance
设置本地/邻近语音通话的最大距离。这也会影响网络使用率
my_player:SetVOIPLocalMaxDistance(max_distance)
Parameters
| Type | Parameter | Default | Description |
|---|
| integer | max_distance | Required parameter | 衰减距离。默认值为 3600 |
See also SetVOIPLocalSetting, SetVOIPLocalVolume.


SetVOIPLocalSetting
设置本地/邻近的语音通话设置
my_player:SetVOIPLocalSetting(setting)
Parameters
| Type | Parameter | Default | Description |
|---|
| VOIPSetting | setting | Required parameter | No description provided |
See also SetVOIPLocalMaxDistance, SetVOIPLocalVolume, VOIPLocalSettingChange.


SetVOIPLocalVolume
设置本地/邻近语音通话的输入/输出音量。它仅影响本地/邻近频道
my_player:SetVOIPLocalVolume(volume)
Parameters
| Type | Parameter | Default | Description |
|---|
| float | volume | Required parameter | No description provided |
See also SetVOIPLocalSetting, SetVOIPLocalMaxDistance, VOIPLocalSettingChange.


SetVOIPMuted
为该玩家静音或取消静音语音通话
my_player:SetVOIPMuted(is_muted)
Parameters
| Type | Parameter | Default | Description |
|---|
| boolean | is_muted | Required parameter | No description provided |
See also IsVOIPMuted.


Spectate
旁观其他玩家
my_player:Spectate(player, blend_speed?)
Parameters
| Type | Parameter | Default | Description |
|---|
| Player | player | Required parameter | No description provided |
| float | blend_speed? | 0
| No description provided |


StartCameraFade
使相机淡入/淡出到某种纯色。自动播放动画
my_player:StartCameraFade(from_alpha, to_alpha, duration, to_color, should_fade_audio?, hold_when_finished?)
Parameters
| Type | Parameter | Default | Description |
|---|
| float | from_alpha | Required parameter | 开始淡入淡出的 Alpha 值。范围 [0..1],其中 0 为完全透明,1 为完全不透明的纯色。 |
| float | to_alpha | Required parameter | 结束淡入淡出的 Alpha 值。 |
| float | duration | Required parameter | 淡入淡出应当持续的时间,以秒为单位。 |
| Color | to_color | Required parameter | 要淡入/淡出到的颜色。 |
| boolean | should_fade_audio? | false
| 如果为 True,则音频音量将随纯色的 Alpha 值一起淡入淡出。 |
| boolean | hold_when_finished? | false
| 如果为 True,淡入淡出将保持在 ToAlpha 值,直到被显式停止(例如使用 StopCameraFade) |


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


TranslateCameraTo
平滑移动玩家的相机位置(仅在未附身任何角色时有效)
my_player:TranslateCameraTo(location, time, exp?)
Parameters
| Type | Parameter | Default | Description |
|---|
| Vector | location | Required parameter | No description provided |
| float | time | Required parameter | No description provided |
| float | exp? | 0
| 用于平滑插值的指数,使用 0 表示线性运动 |


UnPossess
将玩家从角色中解除控制
🚀 事件
Inherited Entity Events

DimensionChange
当玩家改变其维度时触发
Player.Subscribe("DimensionChange", function(self, old_dimension, new_dimension)
end)
Arguments
| Type | Argument | Description |
|---|
| Player | self | No description provided |
| integer | old_dimension | No description provided |
| integer | new_dimension | No description provided |
See also SetDimension, GetDimension.

Possess
当玩家开始控制一个 Pawn(角色)时触发
Player.Subscribe("Possess", function(self, pawn)
end)
Arguments
| Type | Argument | Description |
|---|
| Player | self | No description provided |
| Base Pawn | pawn | No description provided |
See also GetControlledCharacter.

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

UnPossess
一个 Pawn(角色)与玩家解除了附身
Player.Subscribe("UnPossess", function(self, pawn)
end)
Arguments
| Type | Argument | Description |
|---|
| Player | self | No description provided |
| Base Pawn | pawn | No description provided |
See also GetControlledCharacter.

VOIP
当玩家开始/结束使用语音通话时
当 'is_talking' 为 true 时,返回 false 可阻止播放此语音流(在服务端将阻止所有人的播放,在客户端将仅阻止该客户端的播放)
Player.Subscribe("VOIP", function(self, is_talking)
return true
end)
Arguments
| Type | Argument | Description |
|---|
| Player | self | No description provided |
| boolean | is_talking | No description provided |

VOIPGlobalChannelSettingChange
当该玩家的全局语音通话频道设置发生更改时触发
Player.Subscribe("VOIPGlobalChannelSettingChange", function(self, channel, old_setting, new_setting)
end)
Arguments
| Type | Argument | Description |
|---|
| Player | self | No description provided |
| integer | channel | No description provided |
| VOIPSetting | old_setting | No description provided |
| VOIPSetting | new_setting | No description provided |
See also SetVOIPGlobalChannelSetting, SetVOIPGlobalAllChannelsSetting.

VOIPLocalSettingChange
当该玩家的本地语音通话设置发生更改时触发
Player.Subscribe("VOIPLocalSettingChange", function(self, old_setting, new_setting)
end)
Arguments
| Type | Argument | Description |
|---|
| Player | self | No description provided |
| VOIPSetting | old_setting | No description provided |
| VOIPSetting | new_setting | No description provided |
See also SetVOIPLocalSetting.