Changing the world

So far the scripts have observed and described. This chapter is about acting on the world: creating and destroying entities, moving them around, rewiring rooms, and sending mobs travelling. These are all action commands, so in the handle phase a successful one suppresses the event's default action (see Intercepting).

Spawning objects and mobs

oload loads a fresh object from its prototype; mload loads a mobile into a room. With no target, an object goes to the owner and a mob appears in the owner's room:

handle command (conjure) {
  oload 1                       # into the owner's inventory
  oload 1 [room $self]          # onto the floor of the owner's room
  mload 1 [room $actor]         # a mob into the actor's room
  do "say It is done."
}

Both take an optional max cap; a load that fails (unknown vnum, or the cap reached) does not suppress the default action. Pass an explicit target — a creature (carried), an object (placed inside), or a room (dropped) — to control where the object lands.

Receiving a gift

The give event fires on the mob being handed an item, with $object bound to it. A shopkeeper or collector reacts here:

after give {
  echo $actor "$self examines [name $object] and tucks it away."
}

Checking a prototype first

object and mob look up a prototype by vnum without loading it — returning null if none exists. Use them to validate before acting:

handle command (summon) {
  let proto [mob 1]
  if [isnull $proto] {
    do "say That creature is unknown to me."
  }
  if [exists $proto] {
    mload 1
    do "say [name $proto] answers my call."
  }
}

A prototype carries the template's data, so [name [object 1]] and [vnum [object 1]] read the prototype's name and number.

Removing things

opurge extracts every object of a given vnum that the owner directly holds; selfpurge removes the owner mob itself:

handle command (cleanup) {
  opurge 1                      # destroy the owner's copies of vnum 1
}

handle tick {
  if [eq [hour] 6] {
    do "say My work here is done."
    selfpurge                   # vanish at dawn — do this last
  }
}

Run any final message before selfpurge: once purged, the owner can no longer do anything.

Teleporting — trans

trans moves a creature or object straight to a room, with no path travelled. A creature is moved only if it is allowed to enter:

handle command (banish) {
  trans $actor [room 1]
  do "say Begone!"
}

Doors and exits

doorset sets or clears flags on a room's exit — open, close, lock, hide. The +/- chooses set or clear, and the flags are a space-separated string:

handle command (seal) {
  doorset [room 1] north + "closed locked"
}

handle command (open) {
  doorset [room 1] north - "closed locked"
}

doorexit changes where an exit leads (creating it if needed), or removes it with the literal "none":

handle command (reroute) {
  doorexit [room 1] north [room 3001]   # north now leads to 3001
}

handle command (wall) {
  doorexit [room 1] north "none"        # remove the north exit
}

Toggling behavior — mobflag

mobflag sets or clears the owner mob's action flags at run time, changing how it behaves from then on:

handle command (guard) {
  mobflag + sentinel            # stop wandering, hold this spot
}

handle command (relax) {
  mobflag - "aggressive wimpy"  # clear several at once
}

Making a mob travel

A mob can move under its own power. stepto takes a single step toward a room along the shortest path — call it repeatedly, typically on each tick:

handle tick {
  stepto [room 3001]            # one step closer each hour
}

walkto does the whole journey in one statement: it expands into a stepping loop that moves, pauses, and repeats until the mob arrives or gets stuck. The optional second argument is the ticks to wait between steps:

handle command (patrol) {
  walkto 3001 2                 # walk to 3001, pausing 2 ticks per step
}

driveto is the same for a mob operating a vehicle from a console in its room:

handle command (drive) {
  driveto 3001
}

All three need a mobile owner (and driveto needs a vehicle console present); from any other owner they do nothing.

Acting on freshly-loaded mobs — load

The load event fires once, just after the owner is created (zone reset, mload/oload, a spawn). It is after-only and deferred to the next tick. Use it to set a mob up on arrival:

after load {
  mobflag + sentinel
  ldesc "A weathered sentry stands watch here."
}

See also