OnPlayerOpenContainer
A player wants to open a container - return false to refuse.
Nothing has opened yet. Return false and the container stays shut for them, without a word: what the player is told is
yours to decide. Return a text after the false and their chat shows it (return false, "The guild's seal holds it shut.",
in the colour of the game’s own refusal lines). A refusal that says nothing is also the way to open a screen of your own on a
container, such as a chest on your web interface. Otherwise their client’s loot window opens on
the record’s contents (GetContainerItems) and they hold the container until they close it - or for five minutes at most.
The server has checked the request first: the player within about eight metres of the container’s place, no more than four
requests a second from one player, and nobody else holding the container. What they take and what they put in is checked
against the record: a take is explained only by what the record held when they opened it, and a put counts only for what
the server’s records let go of - an item they never had is never booked in the container. What the container cannot hold
(a chest keeps 200 stacks) comes back to the player, and so does a put from too far away or after the server freed
their hold.
Syntax
Section titled “Syntax”function OnPlayerOpenContainer(pid, key) -- ...end| Parameter | Type | |
|---|---|---|
pid |
number | the player |
key |
string | the container’s key - its level name, or <name>@<x>,<y>,<z> for one of several the level gives that name |
Returns
Section titled “Returns”false refuses saying nothing, false, "text" refuses and tells the player that text; anything else lets them open it
Example
Section titled “Example”function OnPlayerOpenContainer(pid, key) if IsPlayerInZone(pid, arena) then return false, "No rummaging mid-duel." end -- the mode's own chest page instead of the game's window: refused without a word, then the page opens if CHESTS[key] then SendPlayerWebMessage(pid, "chest", { key = key, items = GetContainerItems(key) or {} }) ShowPlayerWebFrame(pid, "chest") return false endendSee also
Section titled “See also”OnPlayerCloseContainer · GetContainerItems · GetContainerUser · the Doors and containers group of the index
