Multiplayer: host, join, messages, the automatic sync, other players.
# net.allowed () → boolean
Whether the player allowed your mod to use the network.
# net.request (reason? ) → boolean
Asks the player for permission (once; the answer is remembered and changeable in F1 → Network). net_consent tells the answer.
Parameter Type
reason optional string shown to the player
Returns
boolean true when already allowed
copy if not net .request("for co-op hunts" ) then print ("waiting for the player" ) end
# net.join (address , port? , name? ) → boolean|nil
Joins a session. Asynchronous: net_joined for peer 0 means you are in; net_left for peer 0 carries the reason it failed.
Parameter Type
addressstring IPv4 address or host name
port optional integer default 27015
name optional string your player name
Returns
boolean|nil true when the attempt started, or nil and an error
# net.leave ()
Leaves the session (the host ends it for everyone).
# net.kick (peer , reason? )
The host removes a player.
Parameter Type
peerinteger
reason optional string
# net.active () → boolean
Hosting, joining or joined.
# net.connected () → boolean
Hosting, or accepted by the host.
# net.peers () → table
Everyone in the session, you included.
Returns
table a list of {id, name, ping, host, self}
# net.send (to , topic , data , reliable? ) → boolean|nil
Parameter Type
tointeger|nil a player id, nil = everyone else
topicstring your message name, e.g. "mymod:score"
dataany string, number, boolean or table (as JSON)
reliable optional boolean default true; false for small, frequent state
Returns
boolean|nil true, or nil and an error
copy net .send(nil , "arena:score" , {red = 3 , blue = 1 })
# net.on (topic , fn , priority? ) → integer
Listens for messages of one topic.
Parameter Type
topicstring
fnfunction fn(e): e.from, e.topic, e.data, e.reliable
priority optional integer
Returns
integer listener id (events.off)
copy net .on ("arena:score" , function (e) score = e.data end )
# net.discover (port? ) → boolean|nil
Asks the local network for games (answers in net.lanGames a moment later).
Parameter Type
port optional integer default 27015
# net.lanGames () → table
Games found on the local network.
Returns
table a list of {address, port, name, players, maxPlayers}
# net.sync (on? ) → boolean
The automatic sync of creatures, players and hits (switch it on in every game).
Parameter Type
on optional boolean
Returns
boolean whether the automatic sync is on
# net.syncSettings (settings? ) → table
Tunes the automatic sync.
Parameter Type
settings optional table {rate, nearRadius, sweepSeconds, hits, hunters}
Returns
table the current settings
# net.huntRemotes (on? ) → boolean
Whether creatures notice and attack the other players too (default on).
Parameter Type
on optional boolean
# net.mirroring () → boolean
Whether this game shows the host's creatures.
# net.standIn (peer ) → Creature|nil
The figure of another player in your game.
Parameter Type
peerinteger
# net.standInPeer (c ) → integer|nil
The player a figure stands for (nil: a normal creature).
# net.remoteHunter (peer ) → table|nil
Another player's latest state.
Parameter Type
peerinteger
Returns
table|nil {x, y, z, yaw, pitch, weapon, health, inHunt, hidden}
# net.hostIndex (c ) → integer|nil
The creature's index in the host's game: the same number in every game.
# net.creature (hostIndex ) → Creature|nil
This game's handle for the host's creature.
Parameter Type
hostIndexinteger
# net.lastHitBy (c ) → integer|nil
Host: the player whose shot last hurt it.
# net.packCreatures (filter? ) → table
Your own sync: the creatures' state.
Parameter Type
filter optional table {huntableOnly, aliveOnly, radius}
Returns
table chunks (strings) to send
# net.applyCreatures (chunk ) → integer
Your own sync: follow the host's creatures.
Parameter Type
chunkstring
Returns
integer creatures in it, -1 = not applicable
# net.packHunter () → string
Your own sync: your hunter's state.
# net.applyHunter (peer , data ) → boolean
Your own sync: show a player's figure.
Parameter Type
peerinteger
datastring
# net.packHit (c , damage , kill ) → string
Your own sync: a hit for the host.
Parameter Type
cCreature
damagenumber
killboolean
# net.applyHit (peer , data ) → boolean
Host: apply a player's hit.
Parameter Type
peerinteger
datastring