Difference between revisions of "MUDL:On command"

From SlothMUD Wiki
Jump to: navigation, search
(Global Variables)
 
(2 intermediate revisions by the same user not shown)
Line 23: Line 23:
 
| %a
 
| %a
 
| Character
 
| Character
| The character or mobile that initiated the command.
+
| The character or mobile that initiated the command (the actor).
 
|-
 
|-
 
| %c
 
| %c
 
| Character
 
| Character
| The mobile that the MUDL script is attached to.  This value is null if the script is attached to a room or object.
+
| The mobile that the MUDL script is attached to.  This value is null if the script is attached to a room, area or object.
 
|-
 
|-
 
| %o
 
| %o
 
| Object
 
| Object
| The object that the MUDL script is attached to.  This value is null if the script is attached to a room or mobile.
+
| The object that the MUDL script is attached to.  This value is null if the script is attached to a room, area or mobile.
 
|-
 
|-
| %r
+
| %room
 
| Room
 
| Room
| The room that the MUDL script is attached to. This value is null if the script is attached to a mobile or object.
+
| The room in the game where the script is being run.
 +
|-
 +
| %area
 +
| Area
 +
| The area (zone) in the game where the script is being run.
 +
|-
 +
| %parent
 +
| Character or Object or Room or Area
 +
| The in-game element that the MUDL script is attached to.  It will be identical to one of %c, %o, %room, or %area.
 +
|-
 +
| %procedure_index
 +
| Integer
 +
| The index of the current MUDL procedure on the %parent variable.
 
|-
 
|-
 
| %s
 
| %s
Line 42: Line 54:
 
|-
 
|-
 
|}
 
|}
 
  
 
= Return Values =
 
= Return Values =
Line 52: Line 63:
  
 
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]]

Latest revision as of 17:01, 18 May 2017

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 (the actor).
 %c Character The mobile that the MUDL script is attached to. This value is null if the script is attached to a room, area 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, area or mobile.
 %room Room The room in the game where the script is being run.
 %area Area The area (zone) in the game where the script is being run.
 %parent Character or Object or Room or Area The in-game element that the MUDL script is attached to. It will be identical to one of %c, %o, %room, or %area.
 %procedure_index Integer The index of the current MUDL procedure on the %parent variable.
 %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