Table of Contents

Script Law — Items

Item-shell scripting detail for new creators. This page assumes you can already create and attach an item SpecProc (Script objects) and that the object prototype exists (Objects).

If you only remember one teaching point: many “item quests” are really mobile scripts that inspect var.item. Put behavior on the entity whose event actually fires. This page documents what you can do when the item proc runs, and the item-side primitives mobile scripts call.

Hub: Script Law.

Attach reminder (then come back here)

> @proc item new my_sword_proc
Okay.
> @proc item script my_sword_proc
(paste Beanshell that branches on var.STATE; end with return false;)
> @load item 3100
> @item proc my_sword_proc
> @examine item
> @save item
> create item 3100
>

Full attach pedagogy: Script objects.

What ''var'' looks like for items

Item procs receive an ItemEvent.Var. Fields you will read or branch on:

Always branch on var.STATE (or named constants like var.STATE_POST_INTERPRETER). Return false unless you mean to block the triggering command.

Why branching matters: the same script text can be invoked for different STATEs. A stub that only chatters on STATE_SCRIPT will look “broken” if you were testing a give/drop path that never hits that STATE.

Item shell APIs (proven patterns)

Scripts call methods on shells rather than inventing verbs. From code and live world usage, item shells expose (illustrative — not an exhaustive javadoc dump):

Every eval also binds util: roll, chance, limit, max, min, getPosInt, tokenizerNoFill, …

Rule for new creators: before you invent a call, run @proc item examine <existing> or index proc_item and copy a pattern that already works. Only methods on ItemShell / script subclasses are legal. Fabricating var.item.doSomethingCool() will fail at eval time.

Pattern: type guard

Use when ambient item logic should only run for weapons (or keys, …):

if (var.STATE == var.STATE_SCRIPT) {
  if (var.item.isWeapon()) {
    // weapon-only flavor — keep it cheap
  }
}
return false;

If an is… method is missing at eval time, you invented it — examine a live proc or shell source; do not guess.

Pattern: identity + purge (usually from a **mobile** proc)

Quest turn-ins typically live on the mobile (see thanksgiving on Script mobiles). The item-side primitives those scripts rely on:

Teaching checklist when something “eats the give” wrong:

Pattern: when to put logic on the item vs the mobile

Editing and re-test loop

> @proc item script my_sword_proc
(revise Beanshell, finish writer)
> purge sword
> create item 3100
(exercise the trigger again)
>

If a zone loads the object, @save the script then zone reset so you are not staring at an old mental model of “stale instances.” Script text lives on the SpecProc row; the prototype must still @item proc that name.

Safety

Common mistakes