Skip to main content

Create an item

SCRIPT_CREATE_ITEM · opcode 0xea · 7 to 10 bytes

Script virtual machine · Opcode list · Scripted item creation

Creates a new item as a copy of an existing one, optionally changes its value, flags or icon, and puts it in the player's hand or in a block.

Encoding​

Offsets count from the opcode byte. Words are little-endian. Up to three optional bytes follow, one for each override bit set, in the order below.

OffsetTypeFieldMeaning
0u8opcode0xea
1u16letemplate_itemIndex of the item to copy.
3u16ledestinationBlock index, or a special ScriptItemDestination value.
5s8positionFor an ordinary block destination, stored as the item's position_raw: 0–3 a floor quarter, 8 a niche.
6u8overridesScriptItemOverrideFlags: which optional bytes follow.
7u8valuePresent if SCRIPT_ITEM_OVERRIDE_VALUE is set.
…u8item_flagsPresent if SCRIPT_ITEM_OVERRIDE_FLAGS is set.
…u8iconPresent if SCRIPT_ITEM_OVERRIDE_ICON is set.

The size is 7 bytes plus one per override bit set. Other bits of overrides add no bytes; preserve them as found.

Example (constructed, not from a level): ea 05 00 fe ff 00 01 07 copies item 5 into the current block, with its value set to 7.

Behavior​

  1. The template item is duplicated.
  2. The selected overrides are written to the new item's value, flags and icon fields (ItemRuntime), in that order.
  3. The item is placed:1
destinationPlacement
SCRIPT_ITEM_DESTINATION_HELD_OR_CURRENT (0xffff)On the mouse pointer if it is empty, otherwise in the party's block, in one of its two front quarters chosen at random.
SCRIPT_ITEM_DESTINATION_CURRENT_BLOCK (0xfffe)In the party's block, in one of its two front quarters chosen at random; position is ignored.
Any other valueIn that block of the current level, at position: 0 to 3 the north-west, north-east, south-west and south-east quarters, 8 a wall niche, 4 to 7 a flight position with no flight.

The copy is made by the game's ordinary item creation: the template must not be an unused entry, and nothing is created when the 600 item entries are all in use. An item placed on the pointer prints its name and "taken." in the message area. Placing an item in a block sends no event and requests no scene update.1

Edge cases and unknowns​

Anomaly

The overrides are written before the handler checks whether the copy succeeded. When the item table is full, the copy's index is 0 and the value, flags and icon overrides are written into item entry 0, the "no item" entry that item conditions read when nothing is held. A faithful reimplementation writes them there too.

Anomaly

SCRIPT_ITEM_DESTINATION_HELD_OR_CURRENT tests the mouse pointer directly, whereas the other item commands use the held-item rule that also covers keyboard control. In keyboard control the pointer stays empty (inferred), so the new item goes into the selected slot through the placement rule. An item already there is replaced, is no longer referenced, and its entry is never freed. When that slot is a hand holding a cursed item, the game prints the refusal messages and the new item falls on the party's block.

  • Any template index is accepted: the 14 bytes at that index are copied unless their location word is −1 (see values passed on); the original scripts use only the first hundred entries of ITEM.DAT, which are templates.

Observed use​

The reference scripts contain 43 instructions of this kind. They use the override masks 0, 1, 2, 3 and 5, and the destinations SCRIPT_ITEM_DESTINATION_HELD_OR_CURRENT (9 times), SCRIPT_ITEM_DESTINATION_CURRENT_BLOCK (once) and ordinary blocks (33 times, at positions 0 (13), 1 (6), 2 (7), 3 (3) and 8 (4)).

Sources​

Footnotes​

  1. Handler for 0xea, the item duplication routine, the held-item setter, the item insertion and the launch and drop positions. Comparative source: oeob_createItem_v2 in REF-SCUMM-003. Statistics come from decoding the scripts reachable in the 16 reference INF files. ↩ ↩2