💻 Server
Server represents all Server controls in the Server side.
.
. It's not possible to spawn new instances.🎒 Examples
-- 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
Returns | Name | Description | |
---|---|---|---|
ChangeMap | Restarts the server in a new Map, restarts all packages and reconnects all players | ||
table of string | GetAllValuesKeys | Gets a list of all values keys | |
integer | GetCompressionLevel | Returns the server Compression Level being used | |
table of table | GetCustomSettings | Returns the Server Custom Settings passed as parameter or New Game screen | |
string | GetDescription | Returns the Server Description | |
string | GetIP | Returns the server Public IP | |
string | GetMap | Returns the current Map Package name | |
string | GetMapAsset | Returns the current Map Asset reference | |
table | GetMapConfig | Returns a list of the Custom Config of the current map (stored in the MAP_NAME.toml) | |
table of table | GetMapSpawnPoints | Returns a list of the Spawn Points of the current map (stored in the MAP_NAME.toml) | |
integer | GetMaxPlayers | Returns the Max Players configured | |
table of table | GetPackages | Returns a list of Packages running, optionally returns all Packages installed in the server | |
integer | GetPort | Returns the server Port | |
integer | GetQueryPort | Returns the server QueryPort | |
integer | GetTickRate | Returns the Configured Tick Rate | |
integer | GetTime | Gets the Unix Epoch Time in milliseconds | |
any | GetValue | Gets a value given a key | |
string | GetVersion | Returns the server version | |
boolean | IsAnnounced | Returns if the Server is announced in the Master List | |
boolean | LoadPackage | Loads a Package | |
boolean | ReloadPackage | No description provided | |
Restart | Restarts the server, reloading all Packages and reconnecting all Players | ||
SetDescription | Sets the description of the server, optionally overrides Config.toml | ||
SetLogo | Sets the logo of the server, optionally overrides Config.toml | ||
SetMaxPlayers | Sets the maximum player slots of the server, optionally overrides Config.toml | ||
SetName | Sets the name of the server, optionally overrides Config.toml | ||
SetPassword | Sets the password of the server, optionally overrides Config.toml | ||
SetValue | Sets a global value in the Server, which can be accessed from anywhere (server side) | ||
Stop | Stops the server | ||
function | Subscribe | Subscribes for an Event | |
Unban | Unbans a Player by it's account ID | ||
boolean | UnloadPackage | Unloads a Package | |
Unsubscribe | Unsubscribes 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)
Type | Parameter | Default | Description |
---|---|---|---|
string | map_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()
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?)
Type | Parameter | Default | Description |
---|---|---|---|
boolean | only_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! |
PackageType | package_type_filter? | -1 | Which 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)
Type | Parameter | Default | Description |
---|---|---|---|
string | key | Required parameter | Key |
any | fallback | 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)
Type | Parameter | Default | Description |
---|---|---|---|
string | 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 boolean (if the Package was found).
local ret = Server.ReloadPackage(package_folder_name)
Type | Parameter | Default | Description |
---|---|---|---|
string | 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?)
Type | Parameter | Default | Description |
---|---|---|---|
string | description | Required parameter | The new description |
boolean | persist_to_config_file? | false | Persist to config file |
See also GetDescription.
SetLogo
Sets the logo of the server, optionally overrides Config.toml
Server.SetLogo(logo_url, persist_to_config_file?)
Type | Parameter | Default | Description |
---|---|---|---|
string | logo_url | Required parameter | The new logo |
boolean | persist_to_config_file? | false | Persist to config file |
SetMaxPlayers
Sets the maximum player slots of the server, optionally overrides Config.toml
Server.SetMaxPlayers(max_players, persist_to_config_file?)
Type | Parameter | Default | Description |
---|---|---|---|
integer | max_players | Required parameter | The maximum players |
boolean | persist_to_config_file? | false | Persist to config file |
See also GetMaxPlayers.
SetName
Sets the name of the server, optionally overrides Config.toml
Server.SetName(name, persist_to_config_file?)
Type | Parameter | Default | Description |
---|---|---|---|
string | name | Required parameter | The new name |
boolean | persist_to_config_file? | false | Persist to config file |
SetPassword
Sets the password of the server, optionally overrides Config.toml
Server.SetPassword(password, persist_to_config_file?)
Type | Parameter | Default | Description |
---|---|---|---|
string | password | Required parameter | The new password |
boolean | persist_to_config_file? | false | Persist 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?)
Type | Parameter | Default | Description |
---|---|---|---|
string | key | Required parameter | Key |
any | value | Required parameter | Value |
boolean | sync_on_client? | false | If 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)
Type | Parameter | Default | Description |
---|---|---|---|
string | event_name | Required parameter | The name of the Event |
function | function | Required parameter | Callback function |
Unban
Unbans a Player by it's account ID
Server.Unban(account_id)
Type | Parameter | Default | Description |
---|---|---|---|
string | account_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)
Type | Parameter | Default | Description |
---|---|---|---|
string | 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?)
Type | Parameter | Default | Description |
---|---|---|---|
string | event_name | Required parameter | The name of the Events |
function | function? | nil | Callback function |
🚀 Events
Name | Description | |
---|---|---|
ChangeMap | Called when the map changes | |
PlayerConnect | Called when a player is attempting to connect to the server | |
Restart | Server has been restarted | |
Start | Server has been started | |
Stop | Server has been stopped | |
Tick | 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)
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)
Type | Argument | Description |
---|---|---|
string | IP | IP of the player |
string | player_account_ID | Account ID of the player |
string | player_name | Player name |
string | player_steam_ID | SteamID 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)
Type | Argument | Description |
---|---|---|
float | delta_time | No description provided |