net (GuiVM)#

The net singleton, when exposed in the GuiVM, provides networking, multiplayer session, and chat functionality intended for use from the main menu or UI layer, for example: custom multiplayer server browser mods, chat overlays, or connection management tools.

Note

net is also exposed to the MissionVM with a different, mission-scoped set of capabilities focused on server-side scripting rather than UI interaction. See net (MissionVM) for that variant.

Functions#

net.log(message)#

Writes a message to the network log.

Parameters:

message (string) – Text to log.

Example:

net.log('Attempting connection to server...')
net.get_server_list()#

Returns a list of visible multiplayer servers, as seen from the server browser.

Returns:

A table of server descriptor tables.

Return type:

table

Example:

local servers = net.get_server_list()
for _, server in ipairs(servers) do
    net.log('Found server: ' .. tostring(server.name))
end
net.connect_server(address, password)#

Attempts to connect to the multiplayer server at the given address, optionally supplying a password.

Parameters:
  • address (string) – Server address (host:port).

  • password (string) – Optional server password.

Example:

net.connect_server('123.45.67.89:10308')
net.disconnect()#

Disconnects from the current multiplayer session, if any.

Example:

net.disconnect()
net.get_my_player_id()#

Returns the local player’s ID for the current session.

Returns:

Local player ID.

Return type:

number

Example:

local myId = net.get_my_player_id()
net.get_player_list()

Returns a table of player IDs currently connected to the session.

Returns:

Connected player IDs.

Return type:

table

Example:

local players = net.get_player_list()
net.send_chat(message, all)

Sends a chat message. If all is true, the message is sent to all players; otherwise it may be scoped to a smaller audience depending on context.

Parameters:
  • message (string) – Chat message text.

  • all (boolean) – Optional; broadcast to all players.

Example:

net.send_chat('Hello from the main menu!', true)

Footnotes#

  • Availability of certain functions (e.g. player list, chat) depends on whether the GuiVM currently has an active multiplayer connection.

  • This page documents the GuiVM’s view of net; function availability and behaviour may differ from the MissionVM’s net singleton.