Difference between revisions of "MUDL:Intercept command"
(→Example) |
(→Example) |
||
Line 134: | Line 134: | ||
=== Example === | === Example === | ||
<pre> | <pre> | ||
− | addproc | + | addproc <mobile> mudl |
− | setproc | + | setproc <mobile> 0 intercept_cast_i |
# Is this a spell we care about? | # Is this a spell we care about? | ||
− | if (%1 != | + | if (spell_name(%1) != 'fireball', |
( | ( | ||
− | # | + | # Wrong spell. |
return(false) | return(false) | ||
)), | )), | ||
Line 152: | Line 152: | ||
− | + | send_msgs_for_cast(%a, %1), | |
− | |||
− | |||
− | |||
− | |||
cmd(%c, 'say Your fire is no match for me!'), | cmd(%c, 'say Your fire is no match for me!'), | ||
# Mark spell as successful - full mana drain. | # Mark spell as successful - full mana drain. | ||
− | set(flag(%f, | + | set(flag(%f, 'procedure-flags', 'success'), true), |
# Stop future processing of this command | # Stop future processing of this command | ||
− | set(flag(%f, | + | set(flag(%f, 'procedure-flags', 'overrode-command'), true), |
return(true) | return(true) | ||
@ | @ | ||
− | setproc | + | setproc <mobile> 0 PROC_ENABLED 1 |
compile | compile | ||
</pre> | </pre> |
Revision as of 16:11, 4 March 2016
Contents
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. This can be compared against the result of the spell_id function to look for specific spells. |
%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