Docs/API
Player
Fields and methods of a player handle in rtv-mp scenario scripts: name, identity, health, position, area, plus tell, give and teleport.
A player handle refers to one connection: two handles are == when their peer ID and identity match. After a reconnect, use the new handle from the hooks or server.players().
| Field | Type | Description |
|---|---|---|
id | number | Peer ID, as shown by /players. Reused by later connections. |
name | string | Display name. |
identity | string | The player's identity as a SHA-256 hash (64 hexadecimal characters). Stable across reconnects; use it as a key for per-player data. |
online | boolean | false once this connection has left. |
ready | boolean | In the world: finished loading and not travelling. |
area | string | The map name ("Village", "Cabin"), without the hideout owner. |
position | position | Current position. |
health | number | 0 to 100. |
dead | boolean | |
admin | boolean | Listed as a server administrator. |
Every field except id, name, identity and online is nil once the player has left.
player:tell(message, [color])#
Returns: —
Sends a private chat line to this player. See chat messages.
player:give(item, [amount])#
Returns: message, or nil, err
Gives one item like /give. An amount over one stack is split into stacks, if it fits. Pass an array of item records to add several things at once:
player:give({
{ item = "M4A1", count = 1, attachments = { "Leopard" } },
{ item = "Bandage", count = 2 },
{ item = "Ammo_223", amount = 200 },
})
Item names, file IDs and resource paths use the same exact matching as /give. The whole batch must fit and validate, or nothing is added. Each record accepts:
| Field | Description |
|---|---|
item | The item name, file ID or resource path. Required. |
count | How many copies, 1 to 64. Default 1. |
amount | Rounds in a magazine, or items in a stack, up to the game's stack maximum for the item (300 for ammunition, shown as max_amount by /items). Omitted stackable amounts use the item's default. For more than one stack, use count. |
equipment_slot | Wears or holds the item at once: Primary, Secondary, Knife, Grenade1, Grenade2, or Helmet, Backpack, Rig for a matching item. |
magazine_item, magazine_rounds, chambered | Loads a weapon: the magazine item, how many rounds are in it, and whether one is chambered. |
attachments | Array of item names. They must be compatible with a weapon entry, or be one compatible armour plate for a plate-carrier rig. |
player:teleport(area, [position])#
Returns: message, or nil, err
Starts an area teleport like /tparea. Hideouts require the player's key. The move completes over the next moments, as the player's client reloads. With a position ({x=, y=, z=}) in a public map, the player lands there, or moves there at once when already in that map. A blocked spot falls back to the map's normal arrival point.
player:inventory()#
Returns: array, or nil, err
Returns an array. Each entry has item (resource path), name, type, equipped, and slot when equipped. It also has amount and attachments (resource paths) when present.
player:clear_inventory()#
Returns: message, or nil, err
Removes everything the player carries or wears. The furniture catalog stays. Validated and saved like give.
player:current_area()#
Returns: area, or nil, err
The area instance the player is in, private hideouts included.
give and teleport need the player alive, fully loaded, not travelling, disconnecting or in the middle of an item transfer or another teleport. The array form of give is a direct authoritative inventory update; the script should enforce any permissions (for example, an admin check). Right after spawning the starting kit may still be transferring, so wait a few seconds before giving items in player_spawn. give also accepts the armour slots Helmet, Backpack and Rig (a rig takes one plate through attachments); player:clear_inventory() empties the player first, and player:inventory() reads what they carry.
Found a mistake or missing detail? Tell us in the Discord.
rtv-mp