Skip to main content
Version: latest - a1.156.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​

ReturnsNameDescription
AddMapSpawnPointAdds a spawn point to the current map's spawn points list
BanByAccountIDBan the player from the server by its Account ID, ideal for banning from inside PlayerConnect event
ChangeMapRestarts the server in a new Map, restarts all packages and reconnects all players
table of Base ActorGetActorsInRadiusReturns the actors within the specified radius
table of stringGetAllValuesKeysGets a list of all values keys
integerGetCompressionLevelReturns the server Compression Level being used
integerGetConnectionCountReturns the number of connected players (including players in the process of connecting)
table of tableGetCustomSettingsReturns the Server Custom Settings passed as parameter or New Game screen
integerGetDefaultEntityDimensionReturns the default entity dimension
integerGetDefaultPlayerDimensionReturns the default player dimension
stringGetDescriptionReturns the Server Description
Base Entity or nilGetEntityByIDReturns the entity with the specified ID
stringGetIPReturns the server Public IP
integerGetLogLevelReturns the current log level
stringGetMapReturns the current Map Package name
stringGetMapAssetReturns the current Map Asset reference
tableGetMapConfigReturns a list of the Custom Config of the current map (defined in the map package's Package.toml)
table of tableGetMapSpawnPointsReturns a list of the Spawn Points of the current map (defined in the map package's Package.toml)
integerGetMaxPlayersReturns the Max Players configured
stringGetNameReturns the Server Name
table of tableGetPackagesReturns a list of Packages running, optionally returns all Packages installed in the server
table of PlayerGetPlayersInRadiusReturns the players within the specified radius
integerGetPortReturns the server Port
integerGetQueryPortReturns the server QueryPort
integerGetTickRateReturns the Configured Tick Rate
integerGetTimeGets the Unix Epoch Time in milliseconds
anyGetValueGets a value given a key
stringGetVersionReturns the server version
booleanIsAnnouncedReturns if the Server is announced in the Master List
booleanIsPackageLoadedReturns if a Package is currently loaded
booleanIsUnsafeLibsEnabledReturns if the server was started with --enable_unsafe_libs
KickByAccountIDKicks the player from the server by its Account ID, ideal for kicking from inside PlayerConnect event
booleanLoadPackageLoads a Package
booleanReloadPackageReloads a Package on the next server tick
RestartRestarts the server, reloading all Packages and reconnecting all Players
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
SetValueSets a global value in the Server, which can be accessed from anywhere (server side)
StopStops the server
functionSubscribeSubscribes for an Event
UnbanUnbans a Player by its account ID
booleanUnloadPackageUnloads a Package
UnsubscribeUnsubscribes from all subscribed Events in this Class and in this Package, optionally passing the function to unsubscribe only that callback

Optimal

AddMapSpawnPoint​

Adds a spawn point to the current map's spawn points list
Server.AddMapSpawnPoint(location, rotation?)

Parameters

TypeParameterDefaultDescription
Vectorlocation Required parameter Spawn location
Rotatorrotation?Rotator()
Spawn rotation

See also GetMapSpawnPoints.


Moderate

BanByAccountID​

Ban the player from the server by its Account ID, ideal for banning from inside PlayerConnect event
Server.BanByAccountID(player_account_id, reason)

Parameters

TypeParameterDefaultDescription
stringplayer_account_id Required parameter The Player's nanos world account ID
stringreason Required parameter The reason shown to the Player

Slow

ChangeMap​

Restarts the server in a new Map, restarts all packages and reconnects all players
Server.ChangeMap(map_path)

Parameters

TypeParameterDefaultDescription
stringmap_path Required parameter The new map to load

Moderate

GetActorsInRadius​

Returns the actors within the specified radius
local ret = Server.GetActorsInRadius(location, radius, only_classes?, dimension?)

Parameters

TypeParameterDefaultDescription
Vectorlocation Required parameter The center location of the search
numberradius Required parameter The search radius
table of stringonly_classes?[]
Only actors of these classes will be returned (pass empty for all classes)
integerdimension?0
The dimension to search in (pass 0 for all dimensions)

Returns

TypeDescription
table of Base ActorThe actors found in radius

Moderate

GetAllValuesKeys​

Gets a list of all values keys
local ret = Server.GetAllValuesKeys()

Returns

TypeDescription
table of stringa list with all values keys

See also GetValue, SetValue.


Optimal

GetCompressionLevel​

Returns the server Compression Level being used
local ret = Server.GetCompressionLevel()

Returns

TypeDescription
integerthe server Compression Level

Optimal

GetConnectionCount​

Returns the number of connected players (including players in the process of connecting)
local ret = Server.GetConnectionCount()

Returns

TypeDescription
integerNumber of connected players

Slow

GetCustomSettings​

Returns the Server Custom Settings passed as parameter or New Game screen
local ret = Server.GetCustomSettings()

Returns

TypeDescription
table of tablea list of the Custom Settings with this format

Optimal

GetDefaultEntityDimension​

Returns the default entity dimension
local ret = Server.GetDefaultEntityDimension()

Returns

TypeDescription
integerDefault entity dimension

See also SetDefaultEntityDimension.


Optimal

GetDefaultPlayerDimension​

Returns the default player dimension
local ret = Server.GetDefaultPlayerDimension()

Returns

TypeDescription
integerDefault player dimension

See also SetDefaultPlayerDimension.


Optimal

GetDescription​

Returns the Server Description
local ret = Server.GetDescription()

Returns

TypeDescription
stringthe Server Description

See also SetDescription.


Moderate

GetEntityByID​

Returns the entity with the specified ID
local ret = Server.GetEntityByID(entity_id)

Parameters

TypeParameterDefaultDescription
integerentity_id Required parameter The entity ID

Returns

TypeDescription
Base Entity or nilthe entity

Optimal

GetIP​

Returns the server Public IP
local ret = Server.GetIP()

Returns

TypeDescription
stringthe server Public IP

Optimal

GetLogLevel​

Returns the current log level
local ret = Server.GetLogLevel()

Returns

TypeDescription
integerthe log level

Optimal

GetMap​

Returns the current Map Package name
local ret = Server.GetMap()

Returns

TypeDescription
stringthe current map package

Optimal

GetMapAsset​

Returns the current Map Asset reference
local ret = Server.GetMapAsset()

Returns

TypeDescription
stringthe current map asset

Slow

GetMapConfig​

Returns a list of the Custom Config of the current map (defined in the map package's Package.toml)
local ret = Server.GetMapConfig()

Returns

TypeDescription
tablea list of the Custom Config of the current map

Moderate

GetMapSpawnPoints​

Returns a list of the Spawn Points of the current map (defined in the map package's Package.toml)
local ret = Server.GetMapSpawnPoints()

Returns

TypeDescription
table of tablea list of the Spawn Points of the current map with this format

See also AddMapSpawnPoint.


Optimal

GetMaxPlayers​

Returns the Max Players configured
local ret = Server.GetMaxPlayers()

Returns

TypeDescription
integerthe max players configured

See also SetMaxPlayers.


Optimal

GetName​

Returns the Server Name
local ret = Server.GetName()

Returns

TypeDescription
stringThe Server Name

See also SetName.


Slow

GetPackages​

Returns a list of Packages running, optionally returns all Packages installed in the server
local ret = Server.GetPackages(only_loaded?, package_type_filter?)

Parameters

TypeParameterDefaultDescription
booleanonly_loaded?true
Set 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!
PackageTypepackage_type_filter?PackageType.All
Which Package type to return. Leave it default to return all types.

Returns

TypeDescription
table of tablea list of Packages data with this format

Moderate

GetPlayersInRadius​

Returns the players within the specified radius
local ret = Server.GetPlayersInRadius(location, radius, dimension?)

Parameters

TypeParameterDefaultDescription
Vectorlocation Required parameter The center location of the search
numberradius Required parameter The search radius
integerdimension?0
The dimension to search in

Returns

TypeDescription
table of PlayerThe players found in radius

Optimal

GetPort​

Returns the server Port
local ret = Server.GetPort()

Returns

TypeDescription
integerthe server Port

Optimal

GetQueryPort​

Returns the server QueryPort
local ret = Server.GetQueryPort()

Returns

TypeDescription
integerthe server QueryPort

Optimal

GetTickRate​

Returns the Configured Tick Rate
local ret = Server.GetTickRate()

Returns

TypeDescription
integerthe server Tick Rate

Optimal

GetTime​

Gets the Unix Epoch Time in milliseconds
local ret = Server.GetTime()

Returns

TypeDescription
integerthe unix timestamp

Moderate

GetValue​

Gets a value given a key
local ret = Server.GetValue(key, fallback)

Parameters

TypeParameterDefaultDescription
stringkey Required parameter Key
anyfallback Required parameter Fallback Value if key doesn't exist

Returns

TypeDescription
anyValue at key or fallback if key doesn't exist

See also GetAllValuesKeys, SetValue.


Optimal

GetVersion​

Returns the server version
local ret = Server.GetVersion()

Returns

TypeDescription
stringthe server version

Optimal

IsAnnounced​

Returns if the Server is announced in the Master List
local ret = Server.IsAnnounced()

Returns

TypeDescription
booleanif the Server is announced in the Master List

Optimal

IsPackageLoaded​

Returns if a Package is currently loaded
local ret = Server.IsPackageLoaded(package_name)

Parameters

TypeParameterDefaultDescription
stringpackage_name Required parameter The package folder name

Returns

TypeDescription
booleanIf the package is loaded

Optimal

IsUnsafeLibsEnabled​

Returns if the server was started with --enable_unsafe_libs
local ret = Server.IsUnsafeLibsEnabled()

Returns

TypeDescription
booleanWhether the server was started with --enable_unsafe_libs

Moderate

KickByAccountID​

Kicks the player from the server by its Account ID, ideal for kicking from inside PlayerConnect event
Server.KickByAccountID(player_account_id, reason)

Parameters

TypeParameterDefaultDescription
stringplayer_account_id Required parameter The Player's nanos world account ID
stringreason Required parameter The reason shown to the Player

Slow

LoadPackage​

Loads a Package
local ret = Server.LoadPackage(package_folder_name)

Parameters

TypeParameterDefaultDescription
stringpackage_folder_name Required parameter The package to load

Returns

TypeDescription
booleanif the Package was loaded

See also ReloadPackage, UnloadPackage.


Slow

ReloadPackage​

Reloads a Package
Note: the package is effectively reloaded in the next server tick
local ret = Server.ReloadPackage(package_folder_name)

Parameters

TypeParameterDefaultDescription
stringpackage_folder_name Required parameter The package to reload

Returns

TypeDescription
booleanif the Package was found

See also LoadPackage, UnloadPackage.


Slow

Restart​

Restarts the server, reloading all Packages and reconnecting all Players
Server.Restart()

Optimal

SetDefaultEntityDimension​

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

TypeParameterDefaultDescription
integerdefault_dimension Required parameter The new default server dimension that entities will spawn in

See also GetDefaultEntityDimension.


Optimal

SetDefaultPlayerDimension​

Sets the default server dimension that players will spawn in
Server.SetDefaultPlayerDimension(default_dimension)

Parameters

TypeParameterDefaultDescription
integerdefault_dimension Required parameter The new default server dimension that players will spawn in

See also GetDefaultPlayerDimension.


Optimal

SetDescription​

Sets the description of the server, optionally overrides Config.toml
Server.SetDescription(description, persist_to_config_file?)

Parameters

TypeParameterDefaultDescription
stringdescription Required parameter The new description
booleanpersist_to_config_file?false
Persist to config file

See also GetDescription.


Optimal
Sets the logo of the server, optionally overrides Config.toml
Server.SetLogo(logo_url, persist_to_config_file?)

Parameters

TypeParameterDefaultDescription
stringlogo_url Required parameter The new logo
booleanpersist_to_config_file?false
Persist to config file

Optimal

SetMaxPlayers​

Sets the maximum player slots of the server, optionally overrides Config.toml
Server.SetMaxPlayers(max_players, persist_to_config_file?)

Parameters

TypeParameterDefaultDescription
integermax_players Required parameter The maximum players
booleanpersist_to_config_file?false
Persist to config file

See also GetMaxPlayers.


Optimal

SetName​

Sets the name of the server, optionally overrides Config.toml
Server.SetName(name, persist_to_config_file?)

Parameters

TypeParameterDefaultDescription
stringname Required parameter The new name
booleanpersist_to_config_file?false
Persist to config file

See also GetName.


Optimal

SetPassword​

Sets the password of the server, optionally overrides Config.toml
Server.SetPassword(password, persist_to_config_file?)

Parameters

TypeParameterDefaultDescription
stringpassword Required parameter The new password
booleanpersist_to_config_file?false
Persist to config file

Moderate

SetValue​

Sets a global value in the Server, which can be accessed from anywhere (server side)
Server.SetValue(key, value, sync_on_client?)

Parameters

TypeParameterDefaultDescription
stringkey Required parameter Key
anyvalue Required parameter Value
booleansync_on_client?false
If enabled will sync this value through all clients, accessible through Client.GetValue() static class

See also GetAllValuesKeys, GetValue, ValueChange.


Slow

Stop​

Stops the server
Server.Stop()

Optimal

Subscribe​

Subscribes for an Event
local ret = Server.Subscribe(event_name, callback)

Parameters

TypeParameterDefaultDescription
stringevent_name Required parameter The name of the Event
functioncallback Required parameter Callback function

Returns

TypeDescription
functionthe function callback itself

Moderate

Unban​

Unbans a Player by its account ID
Server.Unban(account_id)

Parameters

TypeParameterDefaultDescription
stringaccount_id Required parameter nanos account ID

Slow

UnloadPackage​

Unloads a Package
Note: the package is effectively unloaded in the next server tick
local ret = Server.UnloadPackage(package_folder_name)

Parameters

TypeParameterDefaultDescription
stringpackage_folder_name Required parameter The package you want unload

Returns

TypeDescription
booleanif the Package was found

See also LoadPackage, ReloadPackage.


Optimal

Unsubscribe​

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

TypeParameterDefaultDescription
stringevent_name Required parameter The name of the Events
functioncallback?nil
Callback function

🚀 Events​

NameDescription
ChangeMapCalled when the map changes
PlayerConnectCalled when a player is attempting to connect to the server
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

TypeArgumentDescription
stringold_mapThe previous map
stringnew_mapThe new map

PlayerConnect​

Called when a player is attempting to connect to the server, before the Player entity is created.

To refuse the connection, call Server.KickByAccountID() or Server.BanByAccountID() with the player_account_id (returning false is deprecated).
Server.Subscribe("PlayerConnect", function(ip, player_account_id, player_name, player_steam_id)
-- PlayerConnect was called
end)

Arguments

TypeArgumentDescription
stringipIP of the player
stringplayer_account_idAccount ID of the player
stringplayer_namePlayer name
stringplayer_steam_idSteamID of the player

See also KickByAccountID, BanByAccountID, PlayerDisconnect.


PlayerDisconnect​

Called when a player is disconnecting from the server
Server.Subscribe("PlayerDisconnect", function(ip, player_account_id, player_name, player_steam_id, disconnect_reason)
-- PlayerDisconnect was called
end)

Arguments

TypeArgumentDescription
stringipIP of the player
stringplayer_account_idAccount ID of the player
stringplayer_namePlayer name
stringplayer_steam_idSteamID of the player
stringdisconnect_reasonReason 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

TypeArgumentDescription
floatdelta_timeSeconds 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

TypeArgumentDescription
stringkeyThe key that changed
anyvalueThe new value

See also SetValue.