Jason@Dragoness Home | MUDL documentation | MUDL tutorials
MUDL code takes the form of "functions" attached to items and mobs. Each MUDL proc can have many functions associated with it; you create one function with one setproc command. The name of a MUDL function determines in what circumstances it is called. There are presently seven kinds of MUDL functions:
This MUDL function gets called whenever someone types the given command. So, if you wanted something to happen whenever someone in the room bows, then you would create a MUDL function "on_bow". Note that the MUDL is called BEFORE the command is executed.
Your "on_something" MUDL function should return a boolean. If it returns true, that means the command has been intercepted and the MUD should act as if it didn't happen; if it returns false, then the MUD will proceed with the command as normal.
In "on_something" MUDL functions, %a set to is the being who issued the command. %s is set to the array of arguments of the command, not including the command itself. Arguments are broken at whitespace, thus if you had an "on_cast" function and someone cast magic missile at the big ogre with the MUD command
> cast 'magic missile' big-ogre
Then %s would be the array ['magic, missile', big-ogre].
For MUDL on mobs, on_something functions get called whenever anybody in the room issues a command. Ditto for objects on the floor. For objects in inventory, it gets called whenever the owner issues a command, unless it's in a container in which case it doesn't get called at all. For MUDL on worn/ wielded items it will be called whenever anybody in the room issues a command.
This type of MUDL function is called periodically. [Interval] should be an integer which represents how often. The fastest is every_1, which is called every round (if the function is on a mob in combat or an item borne by someone in combat) or about every 5 seconds otherwise.
The return value of this MUDL function doesn't matter. No variables are set to anything unusual.
Every_death functions are called when somebody in the room dies. The return value is not meaningful. This function is called after the death cry, but before the corpse is made or anything else happens. Inside this function, the newly dead person or mob is %a. The slayer is represented by %x - this may be null, if the deceased died in such a manner that there is not any "slayer".
This function is called by the MUDL on a mob when that mob corpses. Unlike most other MUDL, it isn't ever called for objects, nor is it called for other mobs in the room. It is specifically designed for messing with the corpse (putting items in the corpse, replacing the corpse with something else, etc.).
In an every_corpse function, the corpse will be %o. The mob that just died will be %c.
The return value of this function is not important. If you wish to not leave a corpse, just call destroy() on the corpse object inside the MUDL code - the MUD can handle this.
Every_departure functions get called when someone tries to leave the room. This function must return a boolean; if it returns true, then that person or mob is prevented from leaving; if it returns false, the leaving happens as usual. This check is done only after all other checks have already been passed, so if, for example, the person couldn't leave anyway because he was grappled, every_departure MUDL functions would not be called.
In this function, the leaving person is %a and the direction he is attempting to leave in is %s[1] as a full word ("north", "east", etc.)
* NOTE: For groups, this function is only called once when the leader leaves the room! ** NOTE: It is also for departures from immortal goto but not portals. *** NOTE: This will NOT work on mudl teleport command!
This function is called when someone arrives in the room. It may not block the arrival - if you want to block movement, you must do it with the every_departure function. However, it can suppress the automatic issuance of a "look" command. This is useful if you want to show something after the "look"; then just suppress the default "look", cmd(%a,'look'), and then add your own things afterwards. To suppress look, return true; otherwise return false. Note that suppressing look doesn't work for immortal methods of transport for security reasons.
In this function, the arriving person is %a and the direction he moved to arrive in is %s[1] as a full word ("north", "east", etc.)
* NOTE: For groups, this function is only called once when the leader enters the room! ** NOTE: It is also for arrivals from portals and immortal goto. *** NOTE: This will NOT work on mudl teleport command!
It's often nice for clarity to divide up the MUDL code on a mob or object into multiple functions. Each function has a return type and zero or more arguments. The return type, which is what sort of thing the function evaluates to (e.g. a boolean (true or false), a name, or a list of rooms) and the argument types are specified in the function name. The general form is:
The return type and the argument types must be chosen from the following list:
Thus if the function returned a boolean, was called "doitall", and took as arguments 1, 2, and 3 a string array, a character, and a room, respectively, it would be "fn_b_doitall_ascr". If the function returned an array of rooms and took no arguments, it would be called "fn_ar_doitall".