Server 代表服务器端的所有服务器控件。

🗿Static Class
This is a Static Class. Access it's methods directly with .. It's not possible to spawn new instances.
💂Authority
This static class can be accessed only on 🟦
Server side.
🧑💻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!
🎒 示例
Server/Index.lua
Server.Subscribe("Start", function()
Console.Log("服务器已启动")
end)
Server.Subscribe("Stop", function()
Console.Log("服务器已停止")
end)
Server.Subscribe("Tick", function(delta_time)
Console.Log("刻:" .. delta_time)
end)
🗿 静态函数


AddMapSpawnPoint
向当前地图的生成点列表中添加一个生成点
Server.AddMapSpawnPoint(location, rotation?)
Parameters
| Type | Parameter | Default | Description |
|---|
| Vector | location | Required parameter | 生成位置 |
| Rotator | rotation? | Rotator()
| 生成旋转 |
See also GetMapSpawnPoints.


BanByAccountID
通过玩家的账户 ID 将其从服务器封禁,非常适合在 PlayerConnect 事件内部调用
Server.BanByAccountID(player_account_id, reason)
Parameters
| Type | Parameter | Default | Description |
|---|
| string | player_account_id | Required parameter | No description provided |
| string | reason | Required parameter | No description provided |


ChangeMap
在新地图中重启服务器,重启所有包并重新连接所有玩家
Server.ChangeMap(map_path)
Parameters
| Type | Parameter | Default | Description |
|---|
| string | map_path | Required parameter | 要加载的新地图路径 |


GetActorsInRadius
返回指定半径内的 Actor
local ret = Server.GetActorsInRadius(location, radius, only_classes?, dimension?)
Parameters
| Type | Parameter | Default | Description |
|---|
| Vector | location | Required parameter | 搜索的中心位置 |
| number | radius | Required parameter | 搜索半径 |
| table of string | only_classes? | []
| 仅返回这些类的 Actor(传入空数组以获取所有类) |
| integer | dimension? | 0
| 要搜索的维度(传入 0 以搜索所有维度) |


GetAllValuesKeys
获取所有值键的列表
local ret = Server.GetAllValuesKeys()
See also GetValue, SetValue.


GetCompressionLevel
返回当前使用的服务器压缩级别
local ret = Server.GetCompressionLevel()


GetConnectionCount
返回已连接的玩家数量(包括正在连接过程中的玩家)
local ret = Server.GetConnectionCount()
Returns
| Type | Description |
|---|
| integer | No description provided |


GetCustomSettings
返回作为参数传入或通过新游戏屏幕设置的服务器自定义设置
local ret = Server.GetCustomSettings()
Returns
| Type | Description |
|---|
| table of table | 自定义设置的列表 with this format |


GetDefaultEntityDimension
返回默认的实体维度
local ret = Server.GetDefaultEntityDimension()
Returns
| Type | Description |
|---|
| integer | No description provided |
See also SetDefaultEntityDimension.


GetDefaultPlayerDimension
返回默认的玩家维度
local ret = Server.GetDefaultPlayerDimension()
Returns
| Type | Description |
|---|
| integer | No description provided |
See also SetDefaultPlayerDimension.


GetDescription
返回服务器描述
local ret = Server.GetDescription()
See also SetDescription.


GetEntityByID
返回指定 ID 的实体
local ret = Server.GetEntityByID(entity_id)
Parameters
| Type | Parameter | Default | Description |
|---|
| integer | entity_id | Required parameter | No description provided |


GetIP
返回服务器的公网 IP
local ret = Server.GetIP()


GetLogLevel
返回当前的日志级别
local ret = Server.GetLogLevel()


GetMap
返回当前地图的包名称
local ret = Server.GetMap()


GetMapAsset
返回当前地图资产的引用路径
local ret = Server.GetMapAsset()


GetMapConfig
返回当前地图的自定义配置列表(存储在 MAP_NAME.toml 中)
local ret = Server.GetMapConfig()
Returns
| Type | Description |
|---|
| table | 当前地图的自定义配置列表 |


GetMapSpawnPoints
返回当前地图的生成点列表(存储在 MAP_NAME.toml 中)
local ret = Server.GetMapSpawnPoints()
Returns
| Type | Description |
|---|
| table of table | 当前地图的生成点列表 with this format |
See also AddMapSpawnPoint.


GetMaxPlayers
返回配置的最大玩家数
local ret = Server.GetMaxPlayers()
See also SetMaxPlayers.


GetName
返回服务器名称
local ret = Server.GetName()
See also SetName.


GetPackages
返回正在运行的包列表,也可以选择返回服务器中安装的所有包
local ret = Server.GetPackages(only_loaded?, package_type_filter?)
Parameters
| Type | Parameter | Default | Description |
|---|
| boolean | only_loaded? | true
| 设为 true 时,该函数仅返回已加载且正在运行的包。注意:设为 false 将从磁盘读取包列表,这是一项耗时的慢速操作! |
| PackageType | package_type_filter? | PackageType.All
| 要返回的包类型。默认返回所有类型。 |
Returns
| Type | Description |
|---|
| table of table | 包的数据列表 with this format |


GetPlayersInRadius
返回指定半径内的玩家
local ret = Server.GetPlayersInRadius(location, radius, dimension?)
Parameters
| Type | Parameter | Default | Description |
|---|
| Vector | location | Required parameter | 搜索的中心位置 |
| number | radius | Required parameter | 搜索半径 |
| integer | dimension? | 0
| 要搜索的维度 |


GetPort
返回服务器端口
local ret = Server.GetPort()


GetQueryPort
返回服务器 QueryPort
local ret = Server.GetQueryPort()
Returns
| Type | Description |
|---|
| integer | 服务器 QueryPort |


GetTickRate
返回配置的刻速率
local ret = Server.GetTickRate()


GetTime
获取毫秒级 Unix 时间戳
local ret = Server.GetTime()


GetValue
获取指定键的值
local ret = Server.GetValue(key, fallback)
Parameters
| Type | Parameter | Default | Description |
|---|
| string | key | Required parameter | 键 |
| any | fallback | Required parameter | 当键不存在时的备用值 |
Returns
| Type | Description |
|---|
| any | 键对应的值,若键不存在则返回备用值 |
See also GetAllValuesKeys, SetValue.


GetVersion
返回服务器版本
local ret = Server.GetVersion()


IsAnnounced
返回服务器是否已发布到主列表中
local ret = Server.IsAnnounced()
Returns
| Type | Description |
|---|
| boolean | 服务器是否已发布到主列表中 |


IsPackageLoaded
返回指定的包当前是否已加载
local ret = Server.IsPackageLoaded(package_name)
Parameters
| Type | Parameter | Default | Description |
|---|
| string | package_name | Required parameter | No description provided |


KickByAccountID
通过玩家的账户 ID 将其从服务器踢出,非常适合在 PlayerConnect 事件内部调用
Server.KickByAccountID(player_account_id, reason)
Parameters
| Type | Parameter | Default | Description |
|---|
| string | player_account_id | Required parameter | No description provided |
| string | reason | Required parameter | No description provided |


LoadPackage
加载一个包
local ret = Server.LoadPackage(package_folder_name)
Parameters
| Type | Parameter | Default | Description |
|---|
| string | package_folder_name | Required parameter | 要加载的包 |
See also ReloadPackage, UnloadPackage.


ReloadPackage
重新加载一个包
注:该包实际上会在下一个服务器刻中被重新加载
local ret = Server.ReloadPackage(package_folder_name)
Parameters
| Type | Parameter | Default | Description |
|---|
| string | package_folder_name | Required parameter | 要重新加载的包 |
See also LoadPackage, UnloadPackage.


Restart
重启服务器,重新加载所有包并重新连接所有玩家


SetDefaultEntityDimension
设置实体生成时的默认服务器维度。你可以在生成实体前更改它,并在生成后将其恢复,以便直接将特定实体生成到指定维度中
Server.SetDefaultEntityDimension(default_dimension)
Parameters
| Type | Parameter | Default | Description |
|---|
| integer | default_dimension | Required parameter | No description provided |
See also GetDefaultEntityDimension.


SetDefaultPlayerDimension
设置玩家生成时的默认服务器维度
Server.SetDefaultPlayerDimension(default_dimension)
Parameters
| Type | Parameter | Default | Description |
|---|
| integer | default_dimension | Required parameter | No description provided |
See also GetDefaultPlayerDimension.


SetDescription
设置服务器的描述,可选择是否覆盖 Config.toml
Server.SetDescription(description, persist_to_config_file?)
Parameters
| Type | Parameter | Default | Description |
|---|
| string | description | Required parameter | 新的描述 |
| boolean | persist_to_config_file? | false
| 是否持久化保存到配置文件 |
See also GetDescription.


SetLogo
设置服务器的徽标,可选择是否覆盖 Config.toml
Server.SetLogo(logo_url, persist_to_config_file?)
Parameters
| Type | Parameter | Default | Description |
|---|
| string | logo_url | Required parameter | 新的徽标 |
| boolean | persist_to_config_file? | false
| 是否持久化保存到配置文件 |


SetMaxPlayers
设置服务器的最大玩家槽位数,可选择是否覆盖 Config.toml
Server.SetMaxPlayers(max_players, persist_to_config_file?)
Parameters
| Type | Parameter | Default | Description |
|---|
| integer | max_players | Required parameter | 最大玩家数 |
| boolean | persist_to_config_file? | false
| 是否持久化保存到配置文件 |
See also GetMaxPlayers.


SetName
设置服务器的名称,可选择是否覆盖 Config.toml
Server.SetName(name, persist_to_config_file?)
Parameters
| Type | Parameter | Default | Description |
|---|
| string | name | Required parameter | 新的名称 |
| boolean | persist_to_config_file? | false
| 是否持久化保存到配置文件 |
See also GetName.


SetPassword
设置服务器的密码,可选择是否覆盖 Config.toml
Server.SetPassword(password, persist_to_config_file?)
Parameters
| Type | Parameter | Default | Description |
|---|
| string | password | Required parameter | 新的密码 |
| boolean | persist_to_config_file? | false
| 是否持久化保存到配置文件 |


SetValue
在服务器端设置一个全局值,可以从任何地方访问(服务器端)
Server.SetValue(key, value, sync_on_client?)
Parameters
| Type | Parameter | Default | Description |
|---|
| string | key | Required parameter | 键 |
| any | value | Required parameter | 值 |
| boolean | sync_on_client? | false
| 如果启用,将把此值同步到所有客户端,可通过静态类 Client.GetValue() 进行访问 |
See also GetAllValuesKeys, GetValue, ValueChange.


Stop
停止服务器


Subscribe
订阅事件
local ret = Server.Subscribe(event_name, function)
Parameters
| Type | Parameter | Default | Description |
|---|
| string | event_name | Required parameter | 事件的名称 |
| function | function | Required parameter | 回调函数 |


Unban
通过账户 ID 解封玩家
Parameters
| Type | Parameter | Default | Description |
|---|
| string | account_id | Required parameter | nanos 账户 ID |


UnloadPackage
卸载一个包
注:该包实际上会在下一个服务器刻中被卸载
local ret = Server.UnloadPackage(package_folder_name)
Parameters
| Type | Parameter | Default | Description |
|---|
| string | package_folder_name | Required parameter | 你想卸载的包文件夹名称 |
See also LoadPackage, ReloadPackage.


Unsubscribe
退订此特定类和此特定包中所有已订阅的事件,可选择传递函数以仅退订该回调
Server.Unsubscribe(event_name, function?)
Parameters
| Type | Parameter | Default | Description |
|---|
| string | event_name | Required parameter | 事件的名称 |
| function | function? | nil
| 回调函数 |
🚀 事件

ChangeMap
当地图更改时调用。该事件总是在 Restart 事件触发前紧接着调用
Server.Subscribe("ChangeMap", function(old_map, new_map)
end)
Arguments
| Type | Argument | Description |
|---|
| string | old_map | No description provided |
| string | new_map | No description provided |

PlayerConnect
当玩家尝试连接到服务器时调用
在此事件内部,可以使用 Server.KickByAccountID() 或 Server.BanByAccountID() 来踢出或封禁玩家。
Server.Subscribe("PlayerConnect", function(IP, player_account_ID, player_name, player_steam_ID)
end)
Arguments
| Type | Argument | Description |
|---|
| string | IP | 玩家的 IP |
| string | player_account_ID | 玩家的账户 ID |
| string | player_name | 玩家名称 |
| string | player_steam_ID | 玩家的 SteamID |
See also KickByAccountID, BanByAccountID, PlayerDisconnect.

PlayerDisconnect
当玩家断开与服务器的连接时调用
Server.Subscribe("PlayerDisconnect", function(IP, player_account_ID, player_name, player_steam_ID, disconnect_reason)
end)
Arguments
| Type | Argument | Description |
|---|
| string | IP | 玩家的 IP |
| string | player_account_ID | 玩家的账户 ID |
| string | player_name | 玩家名称 |
| string | player_steam_ID | 玩家的 SteamID |
| string | disconnect_reason | 断开连接的原因 |
See also PlayerConnect.

Restart
服务器已重启
Server.Subscribe("Restart", function()
end)

Start
服务器已启动
Server.Subscribe("Start", function()
end)

Stop
服务器已停止
Server.Subscribe("Stop", function()
end)

Tick
默认每 33 毫秒触发一次
注意:此处应该只执行小型操作,否则可能导致服务器卡顿和延迟
Server.Subscribe("Tick", function(delta_time)
end)
Arguments
| Type | Argument | Description |
|---|
| float | delta_time | No description provided |

ValueChange
当通过 Server.SetValue() 更改值时触发
Server.Subscribe("ValueChange", function(key, value)
end)
Arguments
| Type | Argument | Description |
|---|
| string | key | 发生改变的键 |
| any | value | 新值 |
See also SetValue.