MUDL:Intercept command

From WikiName
Revision as of 20:33, 4 March 2016 by Teker (talk | contribs)
Jump to: navigation, search

Overview

The MUDL intercept functions get called in the middle of processing a command. In most cases the game parses the command line and then calls the relevant intercept function with the pre-parsed data. In most cases this is easier to use than the corresponding on_command functions as the game is performing sanity checks so that the intercept function doesn't need to.


Command Syntax

addproc <room|mobile|object> mudl
setproc <room|mobile|object> ## intercept_<command>_<arguments>


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.
 %f Integer Procedure Flags used to track interaction between different procedures.
 %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 following the command that have not been processed by the game. See the particular commands below for details on which arguments have been processed and which ones have been left in this array.


Return Values

The return value from intercept functions are ignored. To modify game behavior after the intercept function, you should manipulate the Procedure Flags using the %f global variable.


Intercept Commands

The following intercept commands have been implemented.


intercept_ask_bss

Variables

The following local variables are available:

Name Type Description
 %1 Boolean TRUE if the player typed "ask mobile about". FALSE if the word "about" was omitted.
 %2 String Text spoken by the character. This may be different that what the player actually typed if the character is afflicted with a disease like donkeyitis that modifies speech.
 %3 String Text that will be heard by the mobile. This may be different from the %2 variable if the mobile is afflicted with a disease that modifies hearing.
 %s String Array The text contained in %3 broken into individual words.


Triggered Scripts

The only interrupts that are run are the ones attached to the mobile being asked the question. When the script is called you are guaranteed that the player can see the mobile, the mobile is awake, and that %2, %3, and %s contain one or more words of text.


Example

addproc <mobile> mudl
setproc <mobile> 0 intercept_ask_bss

if ('quest' = %s[1],
(
    send_msgs_for_ask(%a, %c, %1, %2, %3),

    cmd(%c, 'say Yes I have a quest for you!'),
    set(flag(%f, 'procedure-flags', 'overrode-command'), true),
    return(true)
)),
return(false)
@

setproc <mobile> 0 PROC_ENABLED 1
compile


intercept_cast_i

Variables

The following local variables are available:

Name Type Description
 %1 Integer Numeric id of the spell that was cast. The spell_name function can be used to compare the id against the name of a specific spell you are looking for.
 %s String Array The arguments typed after the spell name. Note that these could be anything to allow the intercept command to process spells cast at abnormal targets (doors, objects, miscellaneous keywords, etc).


Triggered Scripts

Interrupts are called on all room procedures and mobile procedures for all mobiles in the room. When the script is called you are guaranteed that the player is able to cast the spell and that a valid spell name was entered.


Example

addproc <mobile> mudl
setproc <mobile> 0 intercept_cast_i

# Is this a spell we care about?
if (spell_name(%1) != 'fireball',
(
    # Wrong spell.
    return(false)
)),

# Is this targeted at us?
if ((length(%s) < 1) OR !(char_in_room(%a, %s[1]) = %c),
(
    # Not targeting us.  Use normal processing.
    return(false)
)),


send_msgs_for_cast(%a, %1),

cmd(%c, 'say Your fire is no match for me!'),

# Mark spell as successful - full mana drain.
set(flag(%f, 'procedure-flags', 'success'), true),

# Stop future processing of this command
set(flag(%f, 'procedure-flags', 'overrode-command'), true),
return(true)
@


setproc <mobile> 0 PROC_ENABLED 1
compile


intercept_give_i

Variables

The following local variables are available:

Name Type Description
 %1 Integer The number of gold coins being given to the mobile.


Triggered Scripts

The only interrupts that are run are the ones attached to the mobile being given the coins. When the script is called you are guaranteed that the player can see the mobile and has enough gold coins to give.


Example

addproc <mobile> mudl
setproc <mobile> 0 intercept_give_i

# Let the give occur normally.
perform_give(%a, %c, %1),

if (%1 < 100,
(
    # Mob doesn't like this amount.
    cmd(%c, 'say Come on buddy, how can I survive on that?')
)),


# Stop future processing of this command
set(flag(%f, 'procedure-flags', 'overrode-command'), true),
return(true)
@


setproc <mobile> 0 PROC_ENABLED 1
compile


intercept_give_o

Variables

The following local variables are available:

Name Type Description
 %1 Object The object being given to the mobile.


Triggered Scripts

The only interrupts that are run are the ones attached to the mobile being given the object. When the script is called you are guaranteed that the player can see the mobile and has enough gold coins to give.


Example

addproc <mobile> mudl
setproc <mobile> 0 intercept_give_o

# Let the give occur normally.
perform_give(%a, %c, %1),

if (value(%1) < 100,
(
    # Mob doesn't like this amount.
    cmd(%c, 'say Come on buddy, how can I survive on that?')
)),


# Stop future processing of this command
set(flag(%f, 'procedure-flags', 'overrode-command'), true),
return(true)
@


setproc <mobile> 0 PROC_ENABLED 1
compile


intercept_play_ib

Variables

The following local variables are available:

Name Type Description
 %1 Integer Numeric id of the song that was played. The spell_name function can be used to compare the id against the name of a specific song you are looking for.
 %2 Boolean FALSE if this is the original play/sing and TRUE if this is a replay/resing of the song.
 %s String Array The arguments typed after the song name. Note that these could be anything to allow the intercept command to process songs played at abnormal targets (doors, objects, miscellaneous keywords, etc).


Triggered Scripts

Interrupts are called on all room procedures and mobile procedures for all mobiles in the room. When the script is called you are guaranteed that the player is able to play the song and that a valid song name was entered.


Example

addproc <mobile> mudl
setproc <mobile> 0 intercept_play_ib

if (spell_name(%1) != 'lion chorus',
(
    # Wrong song.
    return(false)
)),

if (false = %2,
(
    # Allow the initial play to run as normal.
    cmd(%a, 'play ~`lion chorus~` ' + concatenate(%s))
),
(
    # Show the replay messages.
    send_msgs_for_play(%a, %1, %2)
)),

if (false = %2,
(
    cmd(%c, 'say What a lovely song.')
),
(
    cmd(%c, 'say It keeps getting better!')
)),

# Mark song as successful - full mana drain.
set(flag(%f, 'procedure-flags', 'success'), true),

# Stop future processing of this command
set(flag(%f, 'procedure-flags', 'overrode-command'), true),
return(true)
@


setproc <mobile> 0 PROC_ENABLED 1
compile


intercept_sing_ib

Variables

The following local variables are available:

Name Type Description
 %1 Integer Numeric id of the song that was sung. The spell_name function can be used to compare the id against the name of a specific song you are looking for.
 %2 Boolean FALSE if this is the original play/sing and TRUE if this is a replay/resing of the song.
 %s String Array The arguments typed after the song name. Note that these could be anything to allow the intercept command to process songs sung at abnormal targets (doors, objects, miscellaneous keywords, etc).


Triggered Scripts

Interrupts are called on all room procedures and mobile procedures for all mobiles in the room. When the script is called you are guaranteed that the player is able to play the song and that a valid song name was entered.


Example

addproc template mudl
setproc template 0 intercept_sing_ib

if (spell_name(%1) != 'lion chorus',
(
    # Wrong song.
    return(false)
)),

if (false = %2,
(
    # Allow the initial sing to run as normal.
    cmd(%a, 'sing ~`lion chorus~` ' + concatenate(%s))
),
(
    # Show the replay messages.
    send_msgs_for_play(%a, %1, %2)
)),

if (false = %2,
(
    cmd(%c, 'say What a lovely song.')
),
(
    cmd(%c, 'say It keeps getting better!')
)),

# Mark song as successful - full mana drain.
set(flag(%f, 'procedure-flags', 'success'), true),

# Stop future processing of this command
set(flag(%f, 'procedure-flags', 'overrode-command'), true),
return(true)
@


setproc template 0 PROC_ENABLED 1
compile


intercept_tell_ss

Variables

The following local variables are available:

Name Type Description
 %1 String Text spoken by the character. This may be different that what the player actually typed if the character is afflicted with a disease like donkeyitis that modifies speech.
 %2 String Text that will be heard by the mobile. This may be different from the %2 variable if the mobile is afflicted with a disease that modifies hearing.
 %s String Array The text contained in %3 broken into individual words.


Triggered Scripts

The only interrupts that are run are the ones attached to the mobile receiving the tell. When the script is called you are guaranteed that the player can see the mobile, the mobile is awake, and that %2, %3, and %s contain one or more words of text.


Example

addproc <mobile> mudl
setproc <mobile> 0 intercept_tell_ss

# Allow normal processing.
send_msgs_for_tell(%a, %c, %1, %2),
if (room(%c) = room(%a),
(
    cmd(%c, 'say What are you trying to tell me?')
),
(
    cmd(%c, 'say Who said that?')
)),

# Stop future processing of this command
set(flag(%f, 'procedure-flags', 'overrode-command'), true),
return(true)
@

setproc <mobile> 0 PROC_ENABLED 1
compile


intercept_whisper_ss

Variables

The following local variables are available:

Name Type Description
 %1 String Text spoken by the character. This may be different that what the player actually typed if the character is afflicted with a disease like donkeyitis that modifies speech.
 %2 String Text that will be heard by the mobile. This may be different from the %2 variable if the mobile is afflicted with a disease that modifies hearing.
 %s String Array The text contained in %3 broken into individual words.


Triggered Scripts

The only interrupts that are run are the ones attached to the mobile receiving the whisper. When the script is called you are guaranteed that the player can see the mobile, the mobile is awake, and that %2, %3, and %s contain one or more words of text.


Example

addproc <mobile> mudl
setproc <mobile> 0 intercept_whisper_ss

# Allow normal processing.
send_msgs_for_whisper(%a, %c, %1, %2),
cmd(%c, 'say Speak up!  I can~`t hear you!'),

# Stop future processing of this command
set(flag(%f, 'procedure-flags', 'overrode-command'), true),
return(true)
@

setproc <mobile> 0 PROC_ENABLED 1
compile