Skip to main content
Version: latest - a1.7.0 βš–οΈ

πŸ’» Server

Server represents all Server controls in the Server side

info

🟦 Authority: This can be accessed only on Server.

πŸ—Ώ Static Class: This is a Static Class. You can access it’s methods directly with .. It is not possible to initialize or create new instances.

Usage​

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

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

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

-- sends a chat message to everyone
Server.BroadcastChatMessage("Welcome to the server!")

Functions​

ReturnsNameDescription
BroadcastChatMessageSends a chat message to everyone
ChangeMapRestarts the server in a new Map, restarts all packages and reconnects all players
ReloadPackageReloads a Package
SendChatMessageSends a chat message to Player only
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)
GetValueGets a value given a key
StopStops the server
functionSubscribeSubscribes for an Event
UnloadPackageUnloads a Package
UnsubscribeUnsubscribes from all subscribed Events in this Class and in this Package, optionally passing the function to unsubscribe only that callback
stringGetMapReturns the current Map
tableGetMapConfigReturns a list of the Custom Config of the current map (stored in the MAP_NAME.toml)
tableGetMapsReturns a list of all Maps installed on the server
tableGetPackagesReturns a list of Packages folder names available in the server, optionally returns only loaded and running packages
stringGetVersionReturns the server version
stringGetIPReturns the server Public IP
numberGetPortReturns the server Port
numberGetQueryPortReturns the server QueryPort
numberGetMaxPlayersReturns the Max Players configured
numberGetDescriptionReturns the Server Description
numberGetTickRateReturns the Configured Tick Rate
numberIsAnnouncedReturns if the Server is announced in the Master List

Events​

NameDescription
ChatCalled when a player types something in the chat - return false to do not send the message
ConsoleCalled when a console command is submitted
LogEntryCalled when a Server log is received
StartServer has been started.
PlayerConnectCalled when a player is attempting to connect to the server - return false to do not allow it
StopServer has been stopped.
TickIs called every 30 ms by default. Only small operations should be performed here, otherwise this can lead the server to delays.

Functions Detailed​

BroadcastChatMessage​

Sends a chat message to everyone

Server.BroadcastChatMessage(message)
TypeParameterDefault ValueDescription
stringmessage

ChangeMap​

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

Server.ChangeMap(map_path)
TypeParameterDefault ValueDescription
stringmap_path

ReloadPackage​

Reloads a Package

Server.ReloadPackage(package_folder_name)
TypeParameterDefault ValueDescription
stringpackage_folder_name

SendChatMessage​

Sends a chat message to Player only

Server.SendChatMessage(player, message)
TypeParameterDefault ValueDescription
Playerplayer
stringmessage

SetDescription​

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

Server.SetDescription(description, persist_to_config_file)
TypeParameterDefault ValueDescription
stringdescription
booleanpersist_to_config_filefalse

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

Server.SetLogo(logo_url, persist_to_config_file)
TypeParameterDefault ValueDescription
stringlogo_url
booleanpersist_to_config_filefalse

SetMaxPlayers​

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

Server.SetMaxPlayers(max_players, persist_to_config_file)
TypeParameterDefault ValueDescription
numbermax_players
booleanpersist_to_config_filefalse

SetName​

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

Server.SetName(name, persist_to_config_file)
TypeParameterDefault ValueDescription
stringname
booleanpersist_to_config_filefalse

SetPassword​

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

Server.SetPassword(password, persist_to_config_file)
TypeParameterDefault ValueDescription
stringpassword
booleanpersist_to_config_filefalse

SetValue​

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)
TypeParameterDefault ValueDescription
stringkeyKey
anyvalueValue

GetValue​

Gets a value given a key. Please refer to Entity Values for more information

Returns any

Server.GetValue(key, fallback)
TypeParameterDefault ValueDescription
stringkeyKey
anyfallbackFallback Value if key doesn't exist

Stop​

Stops the server

Server.Stop()

Subscribe​

Subscribes for an Event

Returns the function callback itself

Server.Subscribe(event_name, callback)
TypeParameterDescription
stringevent_name
functionfunction

UnloadPackage​

Unloads a Package

Server.UnloadPackage(package_folder_name)
TypeParameterDefault ValueDescription
stringpackage_folder_name

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)
TypeParameterDefault ValueDescription
stringevent_name
functionfunctionnil

GetMap​

Returns the current Map

Returns string

Server.GetMap()

GetMapConfig​

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

Returns table

Server.GetMapConfig()

GetMaps​

Returns a list of all Maps installed on the server

Returns a table in the format {{ key, author, compatible_game_modes }, ...}

Server.GetPackages(only_loaded)
TypeParameterDefault ValueDescription
booleanonly_loadedtrue

GetPackages​

Returns a list of Packages folder names available in the server, optionally returns only loaded and running packages

Returns table

Server.GetPackages(only_loaded)
TypeParameterDefault ValueDescription
booleanonly_loadedtrue

GetVersion​

Gets the server Version

Returns string

Server.GetVersion()

GetIP​

Gets the server IP

Returns string

Server.GetIP()

GetPort​

Gets the server Port

Returns number

Server.GetPort()

GetQueryPort​

Gets the server QueryPort

Returns number

Server.GetQueryPort()

GetMaxPlayers​

Gets the server Max Players allowed

Returns number

Server.GetMaxPlayers()

GetDescription​

Gets the server Description

Returns string

Server.GetDescription()

GetTickRate​

Gets the configured Tick Rate

Returns number

Server.GetTickRate()

IsAnnounced​

Gets if the server is announced in the Master List

Returns boolean

Server.IsAnnounced()

Events Detailed​

Chat​

Called when a player types something in the chat - return false to do not send the message

TypeParameterDescription
stringtext
Playersender
Server.Subscribe("Chat", function(text, sender)

end)

Console​

Called when a console command is submitted

TypeParameterDescription
stringtext
Server.Subscribe("Console", function(text)

end)

LogEntry​

Called when a Server log is received

TypeParameterDescription
stringtext
LogTypetype
Server.Subscribe("LogEntry", function(text, type)

end)

Start​

Server has been started.

Server.Subscribe("Start", function()

end)

PlayerConnect​

Called when a player is attempting to connect to the server Return false to do not allow it

TypeParameterDescription
stringIP
stringplayer_account_ID
stringplayer_name
stringplayer_steam_ID
Server.Subscribe("PlayerConnect", function(IP, player_account_ID, player_name, player_steam_ID)

end)

Stop​

Server has been stopped.

Server.Subscribe("Stop", function()

end)

Tick​

Is called every 30 ms by default. Only small operations should be performed here, otherwise this can lead the server to delays.

TypeParameterDescription
numberdelta_time
Server.Subscribe("Tick", function(delta_time)

end)