Passer au contenu principal
Version: latest - a1.73.x ⚖️

💻 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
Ban the player from the server by it's Account ID, ideal for banning from inside PlayerConnect event
Restarts the server in a new Map, restarts all packages and reconnects all players
of Gets a list of all values keys
Returns the server Compression Level being used
of Returns the Server Custom Settings passed as parameter or New Game screen
Returns the Server Description
Returns the server Public IP
Returns the current Map Package name
Returns the current Map Asset reference
Returns a list of the Custom Config of the current map (stored in the MAP_NAME.toml)
of Returns a list of the Spawn Points of the current map (stored in the MAP_NAME.toml)
Returns the Max Players configured
Returns the Server Name
of Returns a list of Packages running, optionally returns all Packages installed in the server
Returns the server Port
Returns the server QueryPort
Returns the Configured Tick Rate
Gets the Unix Epoch Time in milliseconds
Gets a value given a key
Returns the server version
Returns if the Server is announced in the Master List
Returns if a Package is currently loaded
Kicks the player from the server by it's Account ID, ideal for kicking from inside PlayerConnect event
Loads a Package
No description provided
Restarts the server, reloading all Packages and reconnecting all Players
Sets the description of the server, optionally overrides Config.toml
Sets the logo of the server, optionally overrides Config.toml
Sets the maximum player slots of the server, optionally overrides Config.toml
Sets the name of the server, optionally overrides Config.toml
Sets the password of the server, optionally overrides Config.toml
Sets a global value in the Server, which can be accessed from anywhere (server side)
Stops the server
Subscribes for an Event
Unbans a Player by it's account ID
Unloads a Package
Unsubscribes from all subscribed Events in this Class and in this Package, optionally passing the function to unsubscribe only that callback

BanByAccountID

Ban the player from the server by it's Account ID, ideal for banning from inside PlayerConnect event

Server.BanByAccountID(player_account_id, reason)
TypeParameterDefaultDescription
player_account_id Required parameter No description provided
reason Required parameter No description provided

ChangeMap

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

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

GetAllValuesKeys

Gets a list of all values keys

— Returns of (a list with all values keys).

local ret = Server.GetAllValuesKeys()

See also GetValue, SetValue.


GetCompressionLevel

Returns the server Compression Level being used

— Returns (the server Compression Level).

local ret = Server.GetCompressionLevel()

GetCustomSettings

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

— Returns of (a list of the Custom Settings ).

local ret = Server.GetCustomSettings()

GetDescription

Returns the Server Description

— Returns (the Server Description).

local ret = Server.GetDescription()

See also SetDescription.


GetIP

Returns the server Public IP

— Returns (the server Public IP).

local ret = Server.GetIP()

GetMap

Returns the current Map Package name

— Returns (the current map package).

local ret = Server.GetMap()

GetMapAsset

Returns the current Map Asset reference

— Returns (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 (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 of (a list of the Spawn Points of the current map ).

local ret = Server.GetMapSpawnPoints()

GetMaxPlayers

Returns the Max Players configured

— Returns (the max players configured).

local ret = Server.GetMaxPlayers()

See also SetMaxPlayers.


GetName

Returns the Server Name

— Returns (The Server Name).

local ret = Server.GetName()

See also SetName.


GetPackages

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

— Returns of (a list of Packages data ).

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

GetPort

Returns the server Port

— Returns (the server Port).

local ret = Server.GetPort()

GetQueryPort

Returns the server QueryPort

— Returns (the server QueryPort).

local ret = Server.GetQueryPort()

GetTickRate

Returns the Configured Tick Rate

— Returns (the server Tick Rate).

local ret = Server.GetTickRate()

GetTime

Gets the Unix Epoch Time in milliseconds

— Returns (the unix timestamp).

local ret = Server.GetTime()

GetValue

Gets a value given a key

— Returns (Value at key or fallback if key doesn't exist).

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

See also GetAllValuesKeys, SetValue.


GetVersion

Returns the server version

— Returns (the server version).

local ret = Server.GetVersion()

IsAnnounced

Returns if the Server is announced in the Master List

— Returns (if the Server is announced in the Master List).

local ret = Server.IsAnnounced()

IsPackageLoaded

Returns if a Package is currently loaded

— Returns (If the package is loaded).

local ret = Server.IsPackageLoaded(package_name)
TypeParameterDefaultDescription
package_name Required parameter No description provided

KickByAccountID

Kicks the player from the server by it's Account ID, ideal for kicking from inside PlayerConnect event

Server.KickByAccountID(player_account_id, reason)
TypeParameterDefaultDescription
player_account_id Required parameter No description provided
reason Required parameter No description provided

LoadPackage

Loads a Package

— Returns (if the Package was loaded).

local ret = Server.LoadPackage(package_folder_name)
TypeParameterDefaultDescription
package_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 (if the Package was found).

local ret = Server.ReloadPackage(package_folder_name)
TypeParameterDefaultDescription
package_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
description Required parameter The new description
persist_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
logo_url Required parameter The new logo
persist_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
max_players Required parameter The maximum players
persist_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
name Required parameter The new name
persist_to_config_file?falsePersist to config file

See also GetName.


SetPassword

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

Server.SetPassword(password, persist_to_config_file?)
TypeParameterDefaultDescription
password Required parameter The new password
persist_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
key Required parameter Key
value Required parameter Value
sync_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 (the function callback itself).

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

Unban

Unbans a Player by it's account ID

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

UnloadPackage

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

— Returns (if the Package was found).

local ret = Server.UnloadPackage(package_folder_name)
TypeParameterDefaultDescription
package_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
event_name Required parameter The name of the Events
function?nilCallback function

🚀 Events

NameDescription
Called when the map changes
Called when a player is attempting to connect to the server
Server has been restarted
Server has been started
Server has been stopped
Triggered 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
old_mapNo description provided
new_mapNo description provided

PlayerConnect

Called when a player is attempting to connect to the server

Use Server.KickByAccountID() or Server.BanByAccountID() to kick or ban the player from inside this event.
Server.Subscribe("PlayerConnect", function(IP, player_account_ID, player_name, player_steam_ID)
-- PlayerConnect was called
end)
TypeArgumentDescription
IPIP of the player
player_account_IDAccount ID of the player
player_namePlayer name
player_steam_IDSteamID of the player

See also KickByAccountID, BanByAccountID.


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
delta_timeNo description provided