net (MissionVM)#
The net singleton, when exposed in the MissionVM, provides server-side networking
and player management functionality for use in mission scripts, for example: sending
chat messages, kicking players, or querying connected players from a trigger or AI
Tasking script.
Note
net is also exposed to the GuiVM with a different, UI-scoped set of
capabilities. See net (GuiVM) for that variant.
Functions#
- net.send_chat(message, all)#
Sends a chat message to all connected players (if
allis true) or to the server-side chat log.- Parameters:
message (
string) – Chat message text.all (
boolean) – Optional; broadcast to all players.
Example:
net.send_chat('Mission started!', true)
- net.send_chat_to(message, playerId, fromId)#
Sends a chat message to a specific player, optionally attributing it as being from another player ID.
- Parameters:
message (
string) – Chat message text.playerId (
number) – Player to receive the message.fromId (
number) – Optional; player ID to attribute the message to.
Example:
net.send_chat_to('Welcome to the server!', 3)
- net.get_player_list()#
Returns a table of player IDs currently connected to the mission.
- Returns:
Connected player IDs.
- Return type:
table
Example:
local players = net.get_player_list() for _, playerId in ipairs(players) do env.info('Connected player: ' .. tostring(playerId)) end
- net.get_player_info(playerId, attribute)#
Returns information about a connected player, such as name, ping, or slot. If
attributeis omitted, returns a table of all available attributes.- Parameters:
playerId (
number) – Player to query.attribute (
string) – Optional; a single attribute name (e.g."name","ping","side","slot") to retrieve.
- Returns:
Requested attribute value, or a table of all attributes.
Example:
local name = net.get_player_info(1, 'name') env.info('Player 1 is ' .. tostring(name))
- net.get_name(playerId)#
Returns the name of the given player. Equivalent to
net.get_player_info(playerId, 'name').- Parameters:
playerId (
number) – Player to query.- Returns:
Player name.
- Return type:
string
- net.get_slot(playerId)#
Returns the side ID and slot ID of the given player. Equivalent to
net.get_player_info(playerId, 'side')andnet.get_player_info(playerId, 'slot').- Parameters:
playerId (
number) – Player to query.- Returns:
Side ID and slot ID.
- Return type:
number, number
- net.set_slot(sideId, slotId)#
Moves the local player into the given side/slot.
- Parameters:
sideId (
number) –0spectators,1red,2blue.slotId (
string) – Slot ID matching a client unit ID. Combined Arms and multicrew slots additionally append"_<seat>".
- net.force_player_slot(playerId, sideId, slotId)#
Forces the specified player into the given side/slot.
- Parameters:
playerId (
number) – Player to move.sideId (
number) –0spectators,1red,2blue.slotId (
string) – Slot ID matching a client unit ID. Combined Arms and multicrew slots additionally append"_<seat>".
- Returns:
Whether the player was successfully moved.
- Return type:
boolean
- net.get_my_player_id()
Returns the local player’s ID. Always
1for the server.- Returns:
Local player ID.
- Return type:
number
- net.get_server_id()#
Returns the server’s player ID. Currently always
1.- Returns:
Server player ID.
- Return type:
number
- net.recv_chat(message, from)#
Callback invoked when a chat message is received; assign a function to this field to handle incoming chat rather than calling it directly.
- Parameters:
message (
string) – Chat message text.from (
number) – Player ID the message came from.
- net.lua2json(value)#
Converts a Lua value to a JSON string.
- Parameters:
value – Lua value to convert.
- Returns:
JSON-encoded string.
- Return type:
string
- net.json2lua(json)#
Converts a JSON string to a Lua value.
- Parameters:
json (
string) – JSON-encoded string.- Returns:
Decoded Lua value.
- net.dostring_in(state, dostring)#
Executes a Lua string inside the specified engine Lua state.
- Parameters:
state (
string) – Target state:"config"(wheremain.cfg/autoexec.cfgrun),"mission"(the current mission), or"export"(runsExport.luaand the export API).dostring (
string) – Lua source code to execute in that state.
- Returns:
The result of executing the string, as a string.
- Return type:
string
- net.log(message)
Writes a message to the network log.
- Parameters:
message (
string) – Text to log.
- net.trace(level, message)#
Writes a message to the network trace log at the given verbosity level.
- Parameters:
level (
number) – Trace verbosity level.message (
string) – Text to log.
- net.kick(playerId, message)#
Disconnects the specified player from the server, optionally displaying a message.
- Parameters:
playerId (
number) – Player to disconnect.message (
string) – Optional message shown to the player.
Example:
net.kick(3, 'You have been removed from the server.')
- net.get_stat(playerId, statId)#
Returns a statistic value (e.g. kills, deaths) for the specified player.
- Parameters:
playerId (
number) – Player to query.statId (
number) – Statistic identifier (seenet.PSenumerator, e.g.net.PS.PING,net.PS.CRASH,net.PS.KILLS).
- Returns:
The requested statistic value.
- Return type:
number
Example:
local kills = net.get_stat(3, net.PS.KILLS)
Enumerators#
net.PS identifies which statistic to read via get_stat():
Value |
Meaning |
|---|---|
|
Player’s current network ping. |
|
Number of times the player has crashed. |
|
Total kills credited to the player. |
|
Number of successful landings. |
|
Number of times the player has ejected. |
|
Number of times the player has died. |
|
Overall player score. |
|
Accumulated penalty points. |
Footnotes#
These functions are primarily useful on dedicated servers or hosted sessions; behaviour in single-player is limited since there is only one local player.
This page documents the MissionVM’s view of
net; function availability and behaviour may differ from the GuiVM’snetsingleton.