Difference between revisions of "MUDL:On command"

From SlothMUD Wiki
Jump to: navigation, search
Line 52: Line 52:
  
 
MUDL attached to rooms are always triggered by on_something functions.  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.
 
MUDL attached to rooms are always triggered by on_something functions.  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.
 +
 +
 +
= Examples =
 +
 +
== Follow ==
 +
<pre>
 +
addproc <mobile> mudl
 +
setproc <mobile> 0 on_follow
 +
 +
# Check to see if player is following themselves.
 +
if (char_in_room(%a, %s[1]) = %a,
 +
(
 +
    # Is the player leaving our group?
 +
    if (master(%a) = %c,
 +
    (
 +
        # Make the game process the command
 +
        cmd(%a, 'follow ' + %s[1]),
 +
 +
        # React
 +
        cmd(%c, 'say Come back soon!'),
 +
 +
        # Stop future processing of this command
 +
        return(true)
 +
    )),
 +
 +
    # Player is leaving another group.  Use normal processing.
 +
    return(false)
 +
)),
 +
 +
# Check to see if the player is following us
 +
if (char_in_room(%a, %s[1]) != %c,
 +
(
 +
    # Not following us.  Use normal processing.
 +
    return(false)
 +
)),
 +
 +
 +
if (false = can_see(%c, %a),
 +
(
 +
    # Player can't see us.  Use normal processing.
 +
    return(false)
 +
)),
 +
 +
if (master(%a) = %c,
 +
(
 +
    # Player is already following us.  Use normal processing.
 +
    return(false)
 +
)),
 +
 +
# Make the game process the command
 +
cmd(%a, 'follow ' + %s[1]),
 +
 +
# Make the mob respond
 +
cmd(%c, 'say Yes I am group leader!'),
 +
 +
# Stop future processing of this command
 +
return(true)
 +
@
 +
 +
 +
setproc <mobile> 0 PROC_ENABLED 1
 +
compile
 +
 +
</pre>
  
  
 
[[Category:Building]]
 
[[Category:Building]]
 
[[Category:MUDL|On_command]]
 
[[Category:MUDL|On_command]]

Revision as of 23:27, 2 March 2016

Overview

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.


Command Syntax

addproc <room|mobile|object> mudl
setproc <room|mobile|object> ## on_command


Global Variables

The following global variables are available:

Name Type Description
 %a Character The character or mobile that initiated the command.
 %c Character The mobile that the MUDL script is attached to. This value is null if the script is attached to a room or object.
 %o Object The object that the MUDL script is attached to. This value is null if the script is attached to a room or mobile.
 %r Room The room that the MUDL script is attached to. This value is null if the script is attached to a mobile or object.
 %s String array The arguments the player typed after the command.


Return Values

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.


Triggered Scripts

MUDL attached to rooms are always triggered by on_something functions. 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.


Examples

Follow

addproc <mobile> mudl
setproc <mobile> 0 on_follow

# Check to see if player is following themselves.
if (char_in_room(%a, %s[1]) = %a,
(
    # Is the player leaving our group?
    if (master(%a) = %c,
    (
        # Make the game process the command
        cmd(%a, 'follow ' + %s[1]),

        # React
        cmd(%c, 'say Come back soon!'),

        # Stop future processing of this command
        return(true)
    )),

    # Player is leaving another group.  Use normal processing.
    return(false)
)),

# Check to see if the player is following us
if (char_in_room(%a, %s[1]) != %c,
(
    # Not following us.  Use normal processing.
    return(false)
)),


if (false = can_see(%c, %a),
(
    # Player can't see us.  Use normal processing.
    return(false)
)),

if (master(%a) = %c,
(
    # Player is already following us.  Use normal processing.
    return(false)
)),

# Make the game process the command
cmd(%a, 'follow ' + %s[1]),

# Make the mob respond
cmd(%c, 'say Yes I am group leader!'),

# Stop future processing of this command
return(true)
@


setproc <mobile> 0 PROC_ENABLED 1
compile