Players
Join and leave, messages, health, inventory, and who sees whom.
players.on_join(function(player) end) -> connectionplayers.on_leave(function(player) end) -> connectionplayers.list()players.get(name)player
player.nameplayer.uuidplayer.atplayer.dataplayer.gamemodeplayer.ui.title{ title = "RAVE", subtitle = "", color = "white", fade_in = 0.25, stay = 2, fade_out = 0.5 }player:message(text, color)player:sound(name, { at = player.at, volume = 1, pitch = 1, category = "record" })player:teleport(pos, { yaw = 0, pitch = 0 })player:move_to(room)player.room is the Room the player is inplayer:give("stone_pickaxe")player:give{ item = "arrow", count = 16 }player:held()id, a worn tool damageplayer:inventory()player:count("iron_ingot")player:take("coal", 8)player:set_held(item)player:supports("light")player.visible = falseplayer:hide(other)other; player:show(other) undoes itplayer:can_see(other)other is not visible or is hidden from this playersurvival: nil on a game version that has no such rule
player.healthplayer.max_healthplayer.foodplayer.saturationplayer.deadplayer:kill()player.health = 12player.max_health = 40nil"player:damage(4)players.on_death(function(player, cause, message, by) end) -> connectionplayers.on_respawn(function(player) end) -> connectionplayer:give, player:take, player:inventory and player:count work on
inventory stacks.
- A given stack merges into existing stacks, hotbar first.
- What does not fit is dropped from the give, not duplicated.
- Clicks in the player’s own window work as in the game, all seven click modes included.
- A pack’s own menu over the inventory is
player.ui.menu{}(see “Menus”). - A chest’s stacks are
world.container(see “containers”).
Who sees whom
A player sees others in their room who are in view. Two settings remove a player’s body from a client:
player.visible = false -- from everyone; true or nil brings it back
viewer:hide(player) -- from this viewer only; viewer:show(player) undoes it
viewer:can_see(player) -- what the two add up to
-- a lobby where nobody sees anyone
room.players.on_join(function(p) p.visible = false end)
room.players.on_leave(function(p) p.visible = true end)
-- teams: each side sees only its own
for _, a in players.list() do
for _, b in players.list() do
if a.data.team ~= b.data.team then a:hide(b) else a:show(b) end
end
end
- A hidden player is gone from that client: no body, name, armour or hitbox.
The
invisibilityeffect differs: it shows armour and the held item. - The tab list still shows hidden players.
- Both settings last across rooms.
hideis by account, so it lasts when the other player rejoins.- A new session resets both: nothing hidden, and
visibleis true.
Health, food and nil
player.health, player.max_health, player.food and player.saturation
are nil, not 0, on a game version with no rule for them. Every Alpha node
is one (a0.1.0 has no food and no damage). Across the engine, what a version
lacks is absent, not zero.
health is always the health of one individual now. max_health is always
the most it can be. This is the same for a player, for an entity in the world
and for a kind (a kind has max_health only).
player.max_health = ntakes 1 to 1024.nilgives the game’s own (20) back. Another type or a number out of range is an error. It is an error on a version with no damage rules.- A lower maximum takes
player.healthdown to it. A higher maximum does not heal. player.health = nwithnabove the maximum gives the maximum. Food, regeneration and peaceful healing stop at the maximum. A respawn fills to it.- Every Java client (1.7 to 26.3) draws the hearts of the maximum. A Bedrock client draws no health today.
- The maximum lasts for the session, also across rooms and deaths. Set it in
players.on_join.
cause in players.on_death is one of fall, drown, suffocate, void,
lava, fire, cactus, starve, attack (a mob’s or a player’s hit),
shot (an arrow), blast, magic and other (a pack’s own
player:damage). message is the broadcast English death line. by is the
player who hit or shot them, or nil.
A player is one value while connected. Every event passes the same
player:
a == bcompares players, and a player can be a table key.player.dataholds your own state. You need no table keyed by name.- In
players.on_leave,player.nameandplayer.datastill read.datais kept for 10 seconds after they leave; after that a value you still hold reads an empty table. datamay name the player (p.data.state = { player = p }, a function that usesp); it is let go with them all the same.- A player who rejoins is a new value with empty
data.
players.on_join(function(p) p.data.coins = 0 end)
players.on_leave(function(p) storage.set("coins." .. p.uuid, p.data.coins) end)