Ir para o conteúdo principal
Version: latest - a1.172.0 ⚖️

💻 Server

Server represents all Server controls in the Server side

🗿Static ClassServer Only🧑‍💻API Source

🎒 Examples​

Server/Index.lua
-- prints "Server started" when the server is starting
Server.Subscribe("Start", function()
Console.Log("Server started")
end)

-- prints "Server stopped" when the server stops / shutdown
Server.Subscribe("Stop", function()
Console.Log("Server stopped")
end)

-- prints the delta time about every 33 ms
Server.Subscribe("Tick", function(delta_time)
Console.Log("Tick: " .. delta_time)
end)

🗿 Static Functions​

Data
GetAllValuesKeys: table of stringGets a list of all values keys
GetValue: anyGets a value given a key
SetValueSets a global value in the Server, which can be accessed from anywhere (server side)
Diagnostics
GetLogLevel: integerReturns the current log level
GetTickRate: integerReturns the Configured Tick Rate
GetTime: integerGets the Unix Epoch Time in milliseconds
GetVersion: stringReturns the server version
Lifecycle
RestartRestarts the server, reloading all Packages and reconnecting all Players
StopStops the server
Subscribe: functionSubscribes for an Event
UnsubscribeUnsubscribes from all subscribed Events in this Class and in this Package, optionally passing the function to unsubscribe only that callback
Moderation
BanBySteamIDBans the player from the server by its Steam ID, ideal for banning from inside PlayerConnect event
KickBySteamIDKicks the player from the server by its Steam ID, ideal for kicking from inside PlayerConnect event or while holding the connection
UnbanUnbans a Player by its Steam ID
Network
GetConnectionCount: integerReturns the number of connected players (including players in the process of connecting)
GetHeldConnections: table of tableReturns all players currently held in the loading screen
GetIP: stringReturns the server Public IP
GetPort: integerReturns the server Port
GetQueryPort: integerReturns the server QueryPort
HoldConnection: booleanHolds a connecting player in the loading screen with a message, before he starts downloading the server files
IsAnnounced: booleanReturns if the Server is announced in the Master List
ReleaseConnection: booleanLets a held player in, he starts downloading the server files and joins as usual
Packages
GetPackages: table of tableReturns a list of Packages running, optionally returns all Packages installed in the server
IsPackageLoaded: booleanReturns if a Package is currently loaded
LoadPackage: booleanLoads a Package
ReloadPackage: booleanReloads a Package on the next server tick
UnloadPackage: booleanUnloads a Package
Settings
GetCustomSettings: table of tableReturns the Server Custom Settings passed as parameter or New Game screen
GetDefaultEntityDimension: integerReturns the default entity dimension
GetDefaultPlayerDimension: integerReturns the default player dimension
GetDescription: stringReturns the Server Description
GetMaxPlayers: integerReturns the Max Players configured
GetName: stringReturns the Server Name
IsUnsafeLibsEnabled: booleanReturns if the server was started with --enable_unsafe_libs
SetDefaultEntityDimensionSets the default server dimension that entities will spawn in
SetDefaultPlayerDimensionSets the default server dimension that players will spawn in
SetDescriptionSets the description of the server, optionally overrides Config.toml
SetLogoSets the logo of the server, optionally overrides Config.toml
SetMaxPlayersSets the maximum player slots of the server, optionally overrides Config.toml
SetNameSets the name of the server, optionally overrides Config.toml
SetPasswordSets the password of the server, optionally overrides Config.toml
World
AddMapSpawnPointAdds a spawn point to the current map's spawn points list
ChangeMapRestarts the server in a new Map, restarts all packages and reconnects all players
GetActorsInRadius: table of Base ActorReturns the actors within the specified radius
GetEntityByID: Base Entity or nilReturns the entity with the specified ID
GetMap: stringReturns the current Map Package name
GetMapAsset: stringReturns the current Map Asset reference
GetMapConfig: tableReturns a list of the Custom Config of the current map (defined in the map package's Package.toml)
GetMapSpawnPoints: table of tableReturns a list of the Spawn Points of the current map (defined in the map package's Package.toml)
GetPlayersInRadius: table of PlayerReturns the players within the specified radius

Datastatic functions​

GetAllValuesKeysModerate​

Gets a list of all values keys

local ret = Server.GetAllValuesKeys()
Returns
TypeDescrição
table of stringa list with all values keys

See also GetValue, SetValue.

GetValueModerate​

Gets a value given a key

local ret = Server.GetValue(key, fallback)
Parameters
NameTypeDescrição
keystringKey
fallbackanyFallback Value if key doesn't exist
Returns
TypeDescrição
anyValue at key or fallback if key doesn't exist

See also GetAllValuesKeys, SetValue.

SetValueModerate​

Sets a global value in the Server, which can be accessed from anywhere (server side)

Please refer to Entity Values for more information

Server.SetValue(key, value, sync_on_client?)
Parameters
NameTypeDescrição
keystringKey
valueanyThe value, can be any serializable type (not functions)
sync_on_client?booleanIf enabled will sync this value through all clients, accessible through Client.GetValue() static class Default false

See also GetAllValuesKeys, GetValue, ValueChange.

Diagnosticsstatic functions​

GetLogLevelOptimal​

Returns the current log level

local ret = Server.GetLogLevel()
Returns
TypeDescrição
integerthe log level

GetTickRateOptimal​

Returns the Configured Tick Rate

local ret = Server.GetTickRate()
Returns
TypeDescrição
integerthe server Tick Rate

GetTimeOptimal​

Gets the Unix Epoch Time in milliseconds

local ret = Server.GetTime()
Returns
TypeDescrição
integerthe unix timestamp

GetVersionOptimal​

Returns the server version

local ret = Server.GetVersion()
Returns
TypeDescrição
stringthe server version

Lifecyclestatic functions​

RestartSlow​

Restarts the server, reloading all Packages and reconnecting all Players

Server.Restart()

StopSlow​

Stops the server

Server.Stop()

SubscribeOptimal​

Subscribes for an Event

local ret = Server.Subscribe(event_name, callback)
Parameters
NameTypeDescrição
event_namestringThe name of the Event
callbackfunctionCallback function
Returns
TypeDescrição
functionthe function callback itself

UnsubscribeOptimal​

Unsubscribes from all subscribed Events in this Class and in this Package, optionally passing the function to unsubscribe only that callback

Server.Unsubscribe(event_name, callback?)
Parameters
NameTypeDescrição
event_namestringThe name of the Events
callback?functionCallback function Default nil

Moderationstatic functions​

BanBySteamIDModerate​

Bans the player from the server by its Steam ID, ideal for banning from inside PlayerConnect event

The Steam ID is added to banned_ids in the Config.toml, and the player is kicked if connected. It also works for players who are not connected

Server.BanBySteamID(player_steam_id, reason)
Parameters
NameTypeDescrição
player_steam_idstringThe Player's Steam ID (SteamID64)
reasonstringThe reason shown to the Player

KickBySteamIDModerate​

Kicks the player from the server by its Steam ID, ideal for kicking from inside PlayerConnect event or while holding the connection

Server.KickBySteamID(player_steam_id, reason)
Parameters
NameTypeDescrição
player_steam_idstringThe Player's Steam ID (SteamID64)
reasonstringThe reason shown to the Player

UnbanModerate​

Unbans a Player by its Steam ID

Server.Unban(player_steam_id)
Parameters
NameTypeDescrição
player_steam_idstringThe Player's Steam ID (SteamID64)

Networkstatic functions​

GetConnectionCountOptimal​

Returns the number of connected players (including players in the process of connecting)

local ret = Server.GetConnectionCount()
Returns
TypeDescrição
integerNumber of connected players

GetHeldConnectionsModerate​

Returns all players currently held in the loading screen

Useful to rebuild your queue after reloading the package

local ret = Server.GetHeldConnections()
Returns
TypeDescrição
table of tableThe held players
Table keys
NameTypeDescrição
steam_idstringSteam ID (SteamID64)
account_idstringnanos world account ID
namestringPlayer name
ipstringIP of the player

See also HoldConnection, ReleaseConnection.

GetIPOptimal​

Returns the server Public IP

local ret = Server.GetIP()
Returns
TypeDescrição
stringthe server Public IP

GetPortOptimal​

Returns the server Port

local ret = Server.GetPort()
Returns
TypeDescrição
integerthe server Port

GetQueryPortOptimal​

Returns the server QueryPort

local ret = Server.GetQueryPort()
Returns
TypeDescrição
integerthe server QueryPort

HoldConnectionModerate​

Holds a connecting player in the loading screen with a message, before he starts downloading the server files

Only works from inside the PlayerConnect event, or on a connection already held, which only updates its message (e.g. his position in your queue). The player waits until you call Server.ReleaseConnection() or kick him, which lets you verify him asynchronously (database, web API) or build your own queue.

Held players are not counted in max_players nor shown in the server list. If the server is full, new connections only get in up to max_held_connections from the Config.toml, which is 0 by default (full servers refuse new players)

local ret = Server.HoldConnection(player_steam_id, message)
Parameters
NameTypeDescrição
player_steam_idstringThe Player's Steam ID (SteamID64)
messagestringPlain text shown in the loading screen, up to 256 bytes
Returns
TypeDescrição
booleanIf the connection is now held

See also ReleaseConnection, GetHeldConnections, PlayerConnect.

IsAnnouncedOptimal​

Returns if the Server is announced in the Master List

local ret = Server.IsAnnounced()
Returns
TypeDescrição
booleanif the Server is announced in the Master List

ReleaseConnectionModerate​

Lets a held player in, he starts downloading the server files and joins as usual

Returns false if the server is full (max_players is always respected) or the player is not held, in which case he stays held

local ret = Server.ReleaseConnection(player_steam_id)
Parameters
NameTypeDescrição
player_steam_idstringThe Player's Steam ID (SteamID64)
Returns
TypeDescrição
booleanIf the player was let in

See also HoldConnection, GetHeldConnections.

Packagesstatic functions​

GetPackagesSlow​

Returns a list of Packages running, optionally returns all Packages installed in the server

local ret = Server.GetPackages(only_loaded?, package_type_filter?)
Parameters
NameTypeDescrição
only_loaded?booleanSet to true the function return only loaded and running packages. Caution: setting to false will retrieve Packages list from disk, which is a slow operation! Default true
package_type_filter?PackageTypeWhich Package type to return. Leave it default to return all types Default PackageType.All
Returns
TypeDescrição
table of tablea list of Packages data
Table keys
NameTypeDescrição
titlestringNo description provided
namestringNo description provided
typePackageTypeNo description provided
versionstringNo description provided
authorstringNo description provided

IsPackageLoadedOptimal​

Returns if a Package is currently loaded

local ret = Server.IsPackageLoaded(package_name)
Parameters
NameTypeDescrição
package_namestringThe package folder name
Returns
TypeDescrição
booleanIf the package is loaded

LoadPackageSlow​

Loads a Package

local ret = Server.LoadPackage(package_folder_name)
Parameters
NameTypeDescrição
package_folder_namestringThe package to load
Returns
TypeDescrição
booleanif the Package was loaded

See also ReloadPackage, UnloadPackage.

ReloadPackageSlow​

Reloads a Package on the next server tick

Reloads a Package
Note: the package is effectively reloaded in the next server tick

local ret = Server.ReloadPackage(package_folder_name)
Parameters
NameTypeDescrição
package_folder_namestringThe package to reload
Returns
TypeDescrição
booleanif the Package was found

See also LoadPackage, UnloadPackage.

UnloadPackageSlow​

Unloads a Package

Note: the package is effectively unloaded in the next server tick

local ret = Server.UnloadPackage(package_folder_name)
Parameters
NameTypeDescrição
package_folder_namestringThe package you want unload
Returns
TypeDescrição
booleanif the Package was found

See also LoadPackage, ReloadPackage.

Settingsstatic functions​

GetCustomSettingsSlow​

Returns the Server Custom Settings passed as parameter or New Game screen

local ret = Server.GetCustomSettings()
Returns
TypeDescrição
table of tablea list of the Custom Settings with this format

GetDefaultEntityDimensionOptimal​

Returns the default entity dimension

local ret = Server.GetDefaultEntityDimension()
Returns
TypeDescrição
integerDefault entity dimension

See also SetDefaultEntityDimension.

GetDefaultPlayerDimensionOptimal​

Returns the default player dimension

local ret = Server.GetDefaultPlayerDimension()
Returns
TypeDescrição
integerDefault player dimension

See also SetDefaultPlayerDimension.

GetDescriptionOptimal​

Returns the Server Description

local ret = Server.GetDescription()
Returns
TypeDescrição
stringthe Server Description

See also SetDescription.

GetMaxPlayersOptimal​

Returns the Max Players configured

local ret = Server.GetMaxPlayers()
Returns
TypeDescrição
integerthe max players configured

See also SetMaxPlayers.

GetNameOptimal​

Returns the Server Name

local ret = Server.GetName()
Returns
TypeDescrição
stringThe Server Name

See also SetName.

IsUnsafeLibsEnabledOptimal​

Returns if the server was started with --enable_unsafe_libs

local ret = Server.IsUnsafeLibsEnabled()
Returns
TypeDescrição
booleanWhether the server was started with --enable_unsafe_libs

SetDefaultEntityDimensionOptimal​

Sets the default server dimension that entities will spawn in

You can change it before spawning an entity and restore it afterwards to just spawn a specific entity directly on it

Server.SetDefaultEntityDimension(default_dimension)
Parameters
NameTypeDescrição
default_dimensionintegerThe new default server dimension that entities will spawn in

See also GetDefaultEntityDimension.

SetDefaultPlayerDimensionOptimal​

Sets the default server dimension that players will spawn in

Server.SetDefaultPlayerDimension(default_dimension)
Parameters
NameTypeDescrição
default_dimensionintegerThe new default server dimension that players will spawn in

See also GetDefaultPlayerDimension.

SetDescriptionOptimal​

Sets the description of the server, optionally overrides Config.toml

Server.SetDescription(description, persist_to_config_file?)
Parameters
NameTypeDescrição
descriptionstringThe new description
persist_to_config_file?booleanPersist to config file Default false

See also GetDescription.

Sets the logo of the server, optionally overrides Config.toml

Server.SetLogo(logo_url, persist_to_config_file?)
Parameters
NameTypeDescrição
logo_urlstringThe new logo
persist_to_config_file?booleanPersist to config file Default false

SetMaxPlayersOptimal​

Sets the maximum player slots of the server, optionally overrides Config.toml

Server.SetMaxPlayers(max_players, persist_to_config_file?)
Parameters
NameTypeDescrição
max_playersintegerThe maximum players
persist_to_config_file?booleanPersist to config file Default false

See also GetMaxPlayers.

SetNameOptimal​

Sets the name of the server, optionally overrides Config.toml

Server.SetName(name, persist_to_config_file?)
Parameters
NameTypeDescrição
namestringThe new name
persist_to_config_file?booleanPersist to config file Default false

See also GetName.

SetPasswordOptimal​

Sets the password of the server, optionally overrides Config.toml

Server.SetPassword(password, persist_to_config_file?)
Parameters
NameTypeDescrição
passwordstringThe new password
persist_to_config_file?booleanPersist to config file Default false

Worldstatic functions​

AddMapSpawnPointOptimal​

Adds a spawn point to the current map's spawn points list

Server.AddMapSpawnPoint(location, rotation?)
Parameters
NameTypeDescrição
locationVectorSpawn location
rotation?RotatorSpawn rotation Default Rotator()

See also GetMapSpawnPoints.

ChangeMapSlow​

Restarts the server in a new Map, restarts all packages and reconnects all players

Server.ChangeMap(map_path)
Parameters
NameTypeDescrição
map_pathstringThe new map to load

GetActorsInRadiusModerate​

Returns the actors within the specified radius

local ret = Server.GetActorsInRadius(location, radius, only_classes?, dimension?)
Parameters
NameTypeDescrição
locationVectorThe center location of the search
radiusnumberThe search radius
only_classes?table of stringOnly actors of these classes will be returned (pass empty for all classes) Default []
dimension?integerThe dimension to search in (pass 0 for all dimensions) Default 0
Returns
TypeDescrição
table of Base ActorThe actors found in radius

GetEntityByIDModerate​

Returns the entity with the specified ID

local ret = Server.GetEntityByID(entity_id)
Parameters
NameTypeDescrição
entity_idintegerThe entity ID
Returns
TypeDescrição
Base Entity or nilthe entity

GetMapOptimal​

Returns the current Map Package name

local ret = Server.GetMap()
Returns
TypeDescrição
stringthe current map package

GetMapAssetOptimal​

Returns the current Map Asset reference

local ret = Server.GetMapAsset()
Returns
TypeDescrição
stringthe current map asset

GetMapConfigSlow​

Returns a list of the Custom Config of the current map (defined in the map package's Package.toml)

local ret = Server.GetMapConfig()
Returns
TypeDescrição
tablea list of the Custom Config of the current map

GetMapSpawnPointsModerate​

Returns a list of the Spawn Points of the current map (defined in the map package's Package.toml)

local ret = Server.GetMapSpawnPoints()
Returns
TypeDescrição
table of tablea list of the Spawn Points of the current map
Table keys
NameTypeDescrição
locationVectorNo description provided
rotationRotatorNo description provided

See also AddMapSpawnPoint.

GetPlayersInRadiusModerate​

Returns the players within the specified radius

local ret = Server.GetPlayersInRadius(location, radius, dimension?)
Parameters
NameTypeDescrição
locationVectorThe center location of the search
radiusnumberThe search radius
dimension?integerThe dimension to search in Default 0
Returns
TypeDescrição
table of PlayerThe players found in radius

🚀 Events​

ChangeMapCalled when the map changes
PackageLoadTriggered when any package is loaded
PackageUnloadTriggered when any package is unloaded
PlayerConnectCalled when a player is attempting to connect to the server, after Steam authenticated him
PlayerDisconnectCalled when a player is disconnecting from the server
RestartTriggered when the server is restarting
StartTriggered once when the server has started and all packages are loaded
StopTriggered when the server is stopping
TickTriggered every 33ms by default
ValueChangeTriggered when a Value is changed with Server.SetValue()

ChangeMap​

Called when the map changes

This is always called just before Restart event

Server.Subscribe("ChangeMap", function(old_map, new_map)
-- ChangeMap was called
end)
Arguments
NameTypeDescrição
old_mapstringThe previous map
new_mapstringThe new map

PackageLoad​

Triggered when any package is loaded

Server.Subscribe("PackageLoad", function(package_name)
-- PackageLoad was called
end)
Arguments
NameTypeDescrição
package_namestringThe package name (its folder name)

See also GetPackages, IsPackageLoaded, LoadPackage, UnloadPackage, ReloadPackage.

PackageUnload​

Triggered when any package is unloaded

Server.Subscribe("PackageUnload", function(package_name)
-- PackageUnload was called
end)
Arguments
NameTypeDescrição
package_namestringThe package name (its folder name)

See also GetPackages, IsPackageLoaded, LoadPackage, UnloadPackage, ReloadPackage.

PlayerConnect​

Called when a player is attempting to connect to the server, after Steam authenticated him

It is called before the Player entity is created and before he starts downloading the server files.

To refuse the connection, call Server.KickBySteamID() or Server.BanBySteamID() with the player_steam_id (returning false is deprecated). To decide later (e.g. after an asynchronous check, or to make him wait in a queue), call Server.HoldConnection()

Server.Subscribe("PlayerConnect", function(ip, player_account_id, player_name, player_steam_id)
-- PlayerConnect was called
end)
Arguments
NameTypeDescrição
ipstringIP of the player
player_account_idstringAccount ID of the player
player_namestringPlayer name
player_steam_idstringSteamID of the player

See also KickBySteamID, BanBySteamID, HoldConnection, PlayerDisconnect.

PlayerDisconnect​

Called when a player is disconnecting from the server

It is also called for players who never fully connected, including the ones held with Server.HoldConnection()

Server.Subscribe("PlayerDisconnect", function(ip, player_account_id, player_name, player_steam_id, disconnect_reason)
-- PlayerDisconnect was called
end)
Arguments
NameTypeDescrição
ipstringIP of the player
player_account_idstringAccount ID of the player
player_namestringPlayer name
player_steam_idstringSteamID of the player
disconnect_reasonstringReason for disconnection

See also PlayerConnect.

Restart​

Triggered when the server is restarting

Server.Subscribe("Restart", function()
-- Restart was called
end)

Start​

Triggered once when the server has started and all packages are loaded

Server.Subscribe("Start", function()
-- Start was called
end)

Stop​

Triggered when the server is stopping

Server.Subscribe("Stop", function()
-- Stop was called
end)

Tick​

Triggered every 33ms by default

Caution: Only small operations should be performed here, otherwise this can lead to server lag and delays

Server.Subscribe("Tick", function(delta_time)
-- Tick was called
end)
Arguments
NameTypeDescrição
delta_timefloatSeconds since the last tick

ValueChange​

Triggered when a Value is changed with Server.SetValue()

Server.Subscribe("ValueChange", function(key, value)
-- ValueChange was called
end)
Arguments
NameTypeDescrição
keystringThe key that changed
valueanyThe new value

See also SetValue.