Mob Scripts

Revision History

Kas 1.0 - Original Version
Kas 1.1 - if-then-else loops work correctly
Kas 1.2 - $set now works properly.  "$set while" and "$set pos"
          implemented.
R/N     - Mobs can now execute scripts while sleeping, resting, standing
          and fighting, as default.  The script writer may opt to turn
          any or all of these off.
Kas     - $goto and "$set script" removed.
Kas 1.3 - Targetting available.
Kas     - You can now $mark and $ret to go back to a place.
Kas     - $if can be used with =, >, <, >= and <=
Kas     - Fixed bug where mpsetscript only worked on mobs that already had
          scripts.

What are mob scripts?
In an attempt to make MUDs more interactive, many steps have been taken.
Here I focus upon those given to mobiles, or mobs.  Special Functions, or
spec_funs are the most common type.  They provide the MUD with some degree
of interaction by allowing mobs certain routines from casting spells
during combat to the Midgaard Mayor's task of opening and closing the gates.
However, it is not really practical to add a function each time a mob with
a slightly different lifestyle comes along.  Because of this, Mob-programs,
or Mobprogs were born.

Mobprogs took the interactiveness out of the coders hands, and into the
builders, which is where it should be.  They are small macros that react
to certain events.  For example, a "fight_prog" macro means that, while
fighting, the mob will perform the given commands within the program.

All this is very well, but it still does not give the total feel that the
mob is "alive", since a triggered program will do all of its commands at
the same time, every time.  This is where mob-scripts come in.

Mob-scripts are also mini-programs.  However, they are not triggered, and
they do not perform all of their actions at once.  Instead, they are either
set when the mob is loaded into the game, or can be set dynamically, and
perform a single scripted function during the mob-autonomy step (the bit
where mobs walk around) during the normal game-loop cycle.

Scripts consist both of normal, everyday commands, like those used by
players, the special mob (mp*) commands, and some special scripting tools,
all of which begin with the "$" (dollar/string) symbol.  Each command is
ended with a "~" (tilde) character.  A script must end with the "|" symbol
(pipe/bar)

Key: % : given argument as string
     & : given argument as number

Script-commands:
$rep                    returns to the top of the script
$set                    sets various things:
     long   %           sets the long description of the mob
     short  %           sets the short description of the mob
     race   %           sets the race of the mob
     pos                sets the position of the mob
         sleeping
         resting
         standing
     while              sets whether the script should run on a given pos.
         sleeping
         resting
         standing
         fighting
                  on
                  off
$if                     performs a conditional check
     room   &           returns true if a roomflag is true
     race   %           returns true if the races match
     sector &           returns true if the room sectors match
     roomvnum &         returns true if the mob's room vnum matches
     time &             returns true if it is a given hour (mud-time)
     null
          mtarg         returns true if %mtarg is null
          otarg         returns true if %otarg is null
     =  &1 &2           returns true if &1 equals &2
     >  &1 &2           returns true if &1 is greater than &2
     <  &1 &2           returns true if &1 is less than &2
     >= &1 &2           returns true if &1 is greater than or equal to &2
     <= &1 &2           returns true if &1 is less than or equal to &2
$else                   performed if $if returns false
$endif                  marks the end of an $if command
$quick                  performs two commands in quick succession
$get                    sets otarg and mtarg with references
     first
           otarg        sets %otarg with the first object in the room
           mtarg        sets %mtarg with the first mobile/pc in the room
     next
           otarg        sets %otarg to the next object
           mtarg        sets %mtarg to the next mobile/pc
     inv                sets %otarg to the first item in inventory
     self               sets %mtarg to the scripted mob
$mark                   sets a point of reference to return to
$ret                    returns to it

Targetting:
As shown, targetting can now be achived.  Each time a command is parsed,
it is checked for targets and translated as such. The currently available
fields are:

%mtarg.name
       level
       short_descr
       long_descr
       level
       class
%otarg.name
       level
       short_descr
       description
       item_type - note, this is numeric
       value0
       value1
       value2
       value3

Thoughts:
* Delays can be achieved by having a ~ on its own.
* Mob commands, such as mpgoto, mpmload, mpoload and mpsetscript can all be
  used from scripts.

Known Flaws:
* You cannot use punctuation or any other letters on the end of targets.
  Actually, you might be able to like this: (untested)
  %mtarg.'level'.

In Next Release:
* target for person fighting
* %global.stuff.  E.g: %global.class_cleric
* %otarg.%item_type and %mtarg.%class to give the string version?
  along with %mtarg.%race?
* %self target - $if = %self.race %mtarg.race ...
                 or
               - $if < %self.level %mtarg.level~
                 emote shivers in his boots.

In Future Release:
* random number generator
* Any good suggested improvements.

Example Scripts:

How to read out a mob's inventory.


say Ahh... what do I have today?~
emote rummages through his pockets.~
$get inv~
$mark~
$if null otarg~
  say That's it!~
$else~
  say I have a level %otarg.level %otarg.short_descr~
  $get next otarg~
  $ret~
$endif~
|


A janitor who picks up and junks trash as he walks around


$get first otarg~
$mark~
$if null otarg~
  ~
  $rep~
$endif~
$if = %otarg.item_type 13~
  $quick~
  get %otarg.name~
  mpjunk %otarg.name~
  $rep~
$endif~
$get next otarg~
$ret~
|