Skip to main content
Version: bleeding-edge ๐Ÿฉธ

๐Ÿ’ป Server

Server represents all Server controls in the Server side.


๐Ÿ—ฟ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!

๐ŸŽ’ย 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
ChangeMapRestarts the server in a new Map, restarts all packages and reconnects all players
table of stringGetAllValuesKeysGets a list of all values keys
integerGetCompressionLevelReturns the server Compression Level being used
table of tableGetCustomSettingsReturns the Server Custom Settings passed as parameter or New Game screen
stringGetDescriptionReturns the Server Description
stringGetIPReturns the server Public IP
stringGetMapReturns the current Map Package name
stringGetMapAssetReturns the current Map Asset reference
tableGetMapConfigReturns a list of the Custom Config of the current map (stored in the MAP_NAME.toml)
table of tableGetMapSpawnPointsReturns a list of the Spawn Points of the current map (stored in the MAP_NAME.toml)
integerGetMaxPlayersReturns the Max Players configured
table of tableGetPackagesReturns a list of Packages running, optionally returns all Packages installed in the server
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
booleanLoadPackageLoads a Package
booleanReloadPackageNo description provided
RestartRestarts the server, reloading all Packages and reconnecting all Players
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 it's 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

ChangeMap

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

Server.ChangeMap(map_path)
TypeParameterDefaultDescription
stringmap_path Required parameter The new map to load

GetAllValuesKeys

Gets a list of all values keys

โ€” Returns table of string (a list with all values keys).

local ret = Server.GetAllValuesKeys()

See also GetValue, SetValue.


GetCompressionLevel

Returns the server Compression Level being used

โ€” Returns integer (the server Compression Level).

local ret = Server.GetCompressionLevel()

GetCustomSettings

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

โ€” Returns table of table (a list of the Custom Settings with this format).

local ret = Server.GetCustomSettings()

GetDescription

Returns the Server Description

โ€” Returns string (the Server Description).

local ret = Server.GetDescription()

See also SetDescription.


GetIP

Returns the server Public IP

โ€” Returns string (the server Public IP).

local ret = Server.GetIP()

GetMap

Returns the current Map Package name

โ€” Returns string (the current map package).

local ret = Server.GetMap()

GetMapAsset

Returns the current Map Asset reference

โ€” Returns string (the current map asset).

local ret = Server.GetMapAsset()

GetMapConfig

Returns a list of the Custom Config of the current map (stored in the MAP_NAME.toml)

โ€” Returns table (a list of the Custom Config of the current map).

local ret = Server.GetMapConfig()

GetMapSpawnPoints

Returns a list of the Spawn Points of the current map (stored in the MAP_NAME.toml)

โ€” Returns table of table (a list of the Spawn Points of the current map with this format).

local ret = Server.GetMapSpawnPoints()

GetMaxPlayers

Returns the Max Players configured

โ€” Returns integer (the max players configured).

local ret = Server.GetMaxPlayers()

See also SetMaxPlayers.


GetPackages

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

โ€” Returns table of table (a list of Packages data with this format).

local ret = Server.GetPackages(only_loaded?, package_type_filter?)
TypeParameterDefaultDescription
booleanonly_loaded?trueSet 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?-1Which Package type to return. Leave it default (-1) to return all types.

GetPort

Returns the server Port

โ€” Returns integer (the server Port).

local ret = Server.GetPort()

GetQueryPort

Returns the server QueryPort

โ€” Returns integer (the server QueryPort).

local ret = Server.GetQueryPort()

GetTickRate

Returns the Configured Tick Rate

โ€” Returns integer (the server Tick Rate).

local ret = Server.GetTickRate()

GetTime

Gets the Unix Epoch Time in milliseconds

โ€” Returns integer (the unix timestamp).

local ret = Server.GetTime()

GetValue

Gets a value given a key

โ€” Returns any (Value at key or fallback if key doesn't exist).

local ret = Server.GetValue(key, fallback)
TypeParameterDefaultDescription
stringkey Required parameter Key
anyfallback Required parameter Fallback Value if key doesn't exist

See also GetAllValuesKeys, SetValue.


GetVersion

Returns the server version

โ€” Returns string (the server version).

local ret = Server.GetVersion()

IsAnnounced

Returns if the Server is announced in the Master List

โ€” Returns boolean (if the Server is announced in the Master List).

local ret = Server.IsAnnounced()

LoadPackage

Loads a Package

โ€” Returns boolean (if the Package was loaded).

local ret = Server.LoadPackage(package_folder_name)
TypeParameterDefaultDescription
stringpackage_folder_name Required parameter The package to load

See also ReloadPackage, UnloadPackage.


ReloadPackage

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

โ€” Returns boolean (if the Package was found).

local ret = Server.ReloadPackage(package_folder_name)
TypeParameterDefaultDescription
stringpackage_folder_name Required parameter The package to reload

See also LoadPackage, UnloadPackage.


Restart

Restarts the server, reloading all Packages and reconnecting all Players

Server.Restart()

SetDescription

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

Server.SetDescription(description, persist_to_config_file?)
TypeParameterDefaultDescription
stringdescription Required parameter The new description
booleanpersist_to_config_file?falsePersist to config file

See also GetDescription.


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

Server.SetLogo(logo_url, persist_to_config_file?)
TypeParameterDefaultDescription
stringlogo_url Required parameter The new logo
booleanpersist_to_config_file?falsePersist to config file

SetMaxPlayers

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

Server.SetMaxPlayers(max_players, persist_to_config_file?)
TypeParameterDefaultDescription
integermax_players Required parameter The maximum players
booleanpersist_to_config_file?falsePersist to config file

See also GetMaxPlayers.


SetName

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

Server.SetName(name, persist_to_config_file?)
TypeParameterDefaultDescription
stringname Required parameter The new name
booleanpersist_to_config_file?falsePersist to config file

SetPassword

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

Server.SetPassword(password, persist_to_config_file?)
TypeParameterDefaultDescription
stringpassword Required parameter The new password
booleanpersist_to_config_file?falsePersist to config file

SetValue

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

Server.SetValue(key, value, sync_on_client?)
TypeParameterDefaultDescription
stringkey Required parameter Key
anyvalue Required parameter Value
booleansync_on_client?falseIf enabled will sync this value through all clients, accessible through Client.GetValue() static class.

See also GetAllValuesKeys, GetValue.


Stop

Stops the server

Server.Stop()

Subscribe

Subscribes for an Event

โ€” Returns function (the function callback itself).

local ret = Server.Subscribe(event_name, function)
TypeParameterDefaultDescription
stringevent_name Required parameter The name of the Event
functionfunction Required parameter Callback function

Unban

Unbans a Player by it's account ID

Server.Unban(account_id)
TypeParameterDefaultDescription
stringaccount_id Required parameter nanos account ID

UnloadPackage

Unloads a Package
Note: the package is effectively unloaded in the next server tick

โ€” Returns boolean (if the Package was found).

local ret = Server.UnloadPackage(package_folder_name)
TypeParameterDefaultDescription
stringpackage_folder_name Required parameter The package you want unload

See also LoadPackage, ReloadPackage.


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, function?)
TypeParameterDefaultDescription
stringevent_name Required parameter The name of the Events
functionfunction?nilCallback function

๐Ÿš€ย Eventsโ€‹

NameDescription
ChangeMapCalled when the map changes
PlayerConnectCalled when a player is attempting to connect to the server
RestartServer has been restarted
StartServer has been started
StopServer has been stopped
TickTriggered every 33ms by default

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)
TypeArgumentDescription
stringold_mapNo description provided
stringnew_mapNo description provided

PlayerConnect

Called when a player is attempting to connect to the server

Return false to do not allow the player to connect
Server.Subscribe("PlayerConnect", function(IP, player_account_ID, player_name, player_steam_ID)
-- PlayerConnect was called
end)
TypeArgumentDescription
stringIPIP of the player
stringplayer_account_IDAccount ID of the player
stringplayer_namePlayer name
stringplayer_steam_IDSteamID of the player

Restart

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

Start

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

Stop

Server has been stopped
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)
TypeArgumentDescription
floatdelta_timeNo description provided