You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
adding a few new event functions and a ContainerObject (#598)
# DESCRIPTION
Adds two new pre-condition script hooks (`onTryPurchase` for items, `onTryEnter` for rooms) and a new `ContainerObject` scripting type that replaces the previous string-only container API. All three additions follow the existing hook conventions and are documented in the admin scripting pages.
## CHANGES
- **`onTryPurchase` item hook** — fires on the item's script after the buyer's gold is confirmed sufficient but before any gold is deducted or stock removed. Return `false` to silently block the purchase. Signature: `onTryPurchase(user ActorObject, item ItemObject, room RoomObject)`.
- **`onTryEnter` room hook** — fires on the *destination* room's script before a player enters, for both normal movement and combat fleeing. Return `false` to block the movement. Not called for admin teleports, spawns, or script-driven `MoveRoom` calls. Signature: `onTryEnter(user ActorObject, room RoomObject)`.
- **`ContainerObject`** — new scripting type returned by `RoomObject.GetContainers()` (previously returned `[]string`). Exposes the following methods:
- `Name()` — the container's name key
- `HasLock()` — true if a lock is configured
- `IsLocked()` — true if currently locked
- `Lock()` / `Unlock()` — set lock state
- `GetItems()` — returns all items as `[]ItemObject`
- `FindItem(itemName)` — fuzzy-searches container contents, returns `ItemObject` or null
- `AddItem(item)` / `RemoveItem(item)` — mutate container contents
- `GetGold()` — returns gold amount
- `AddGold(amount)` / `RemoveGold(amount)` — mutate container gold; `RemoveGold` returns the actual amount removed
- `Count(itemId)` — count of items matching a spec ID
- `IsTemporary()` — true if the container has a despawn round set
- **`RoomObject.GetContainers()`** return type changed from `[]string` to `[]ContainerObject`.
- Updated `/admin/scripting-items` with `onTryPurchase` hook documentation.
- Updated `/admin/scripting-rooms` with `onTryEnter` hook documentation.
- Updated `/admin/scripting-functions` with a new `ContainerObject` reference section and updated `GetContainers` return type.
- Updated scripting schema (`GetScriptFunctionsSchema`) with all new hooks and the `ContainerObject` type definition.
<divclass="fn-body"><pclass="fn-desc">Returns all containers in the room as <ahref="#container">ContainerObject</a> instances. Each object exposes the container's name, lock state, items, and gold.</p></div>
1155
1156
</details>
1156
1157
1157
1158
<detailsclass="fn-card" data-search="GetExits exits array object room direction lock secret">
<pclass="fn-group-desc">Returned by <ahref="#room">RoomObject</a>.GetContainers(). Represents a named container inside a room and provides access to its contents, lock state, and gold.</p>
1629
+
<divclass="fn-list">
1630
+
1631
+
<detailsclass="fn-card" data-search="ContainerObject Name name string container">
<divclass="fn-body"><pclass="fn-desc">Returns <code>true</code> if the container has a lock configured (difficulty > 0), regardless of whether it is currently locked or unlocked.</p></div>
<divclass="fn-body"><pclass="fn-desc">Returns <code>true</code> if this container is temporary (it has a despawn round set and will disappear over time).</p></div>
<pclass="hook-desc">Called after the player has been confirmed to have enough gold, but before any gold is deducted or stock removed. Return <code>false</code> to block the purchase entirely — no gold is spent and the item is not removed from the shop.</p>
218
+
<divclass="hook-returns"><strong>Return value:</strong><code>false</code> = block the purchase. Any other return value (or none) = allow it.</div>
<tr><tdclass="arg-name">user</td><tdclass="arg-type"><ahref="/admin/scripting-functions#actor">ActorObject</a></td><td>The player attempting the purchase.</td></tr>
221
+
<tr><tdclass="arg-name">item</td><tdclass="arg-type"><ahref="/admin/scripting-functions#item">ItemObject</a></td><td>The item being purchased.</td></tr>
<pclass="hook-desc">Called on the <strong>destination</strong> room before a player enters it. Return <code>false</code> to block the movement. This fires for both normal movement and combat fleeing. It is not called for admin teleports, spawns, or script-driven <code>MoveRoom</code> calls.</p>
272
+
<divclass="hook-returns"><strong>Return value:</strong><code>false</code> = block the movement. Any other return value (or none) allows it.</div>
<tr><tdclass="arg-name">user</td><tdclass="arg-type"><ahref="/admin/scripting-functions#actor">ActorObject</a></td><td>The player attempting to enter.</td></tr>
277
+
<tr><tdclass="arg-name">room</td><tdclass="arg-type"><ahref="/admin/scripting-functions#room">RoomObject</a></td><td>The room being entered (this room).</td></tr>
0 commit comments