Difference between revisions of "MUDL:Intercept command"

From WikiName
Jump to: navigation, search
(Variables)
Line 108: Line 108:
 
compile
 
compile
 
</pre>
 
</pre>
 +
  
 
== intercept_cast_i ==
 
== intercept_cast_i ==
Line 125: Line 126:
 
| 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).
 
| 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 ===
 
=== Triggered Scripts ===
Line 156: Line 158:
  
 
# Mark spell as successful - full mana drain.
 
# 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
 +
</pre>
 +
 +
 +
== intercept_play_ib ==
 +
 +
=== Variables ===
 +
 +
The following local variables are available:
 +
{|class="abilitiestable" border="0" cellspacing="0" cellpadding="0"
 +
! 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.
 +
|-
 +
| %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 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 ===
 +
<pre>
 +
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),
 
set(flag(%f, 'procedure-flags', 'success'), true),
  

Revision as of 12:31, 4 March 2016

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_play_ib

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.
 %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 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_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