NEW MOB-PROGRAMMING CAPABILITIES ============================================================ SCRIPTING ============================================================ If you'd like to run a series of timed actions, they can be orchestrated via a textfile containing a script. The script is initiated via the command: script filename Directorial commands have the syntax: # mobname tickdelay The named mob carries out the following block of commands. The tickdelay is the number of two-second ticks to wait AFTER performing the following block of commands. At the start of the script, the optional line #ABORT self/other/both/neither controls what happens if the script is triggered again while it's already running. If omitted, the default is "abort self", i.e., do nothing, and let the original copy continue running. The end of the script is indicated by: #END The following extract from the parrot sketch seen in the Castle petshop (and stored as "parrot.txt") should make this all clear: On the shopkeeper, named "owner seller_parrot": >speech_prog p parrot sketch script parrot.txt | parrot.txt: #ABORT self # seller_parrot 1 mpquiet get all mpjunk all mpunquiet , tidies up his shop. # seller_parrot 0 mpquiet load mob 3 1 mset dummymob name buyer_parrot customer mset buyer_parrot sex 1 mset buyer_parrot short the customer mset buyer_parrot long An irate customer stands here fuming. mpunquiet # buyer_parrot 4 load obj 65 1 oname 'dummy container' name parrotcage oname parrotcage short a parrot cage oset parrotcage v0 10 load obj 63 1 oname trash name parrot deadparrot oname deadparrot short a (dead) parrot oname deadparrot long A dead parrot is here on the floor. oset deadparrot ed 'parrot deadparrot' This blue corpse was once a parrot. oset deadparrot weight 1 mpquiet put deadparrot parrotcage mpunquiet mpecho An irate customer enters the pet shop carrying a parrot cage. # buyer_parrot 4 ''Ello, I wish to register a complaint. # seller_parrot 4 , does not respond. # buyer_parrot 4 'Ello, Miss? # seller_parrot 4 'What do you mean, "Miss"? # buyer_parrot 4 'I'm sorry, I have a cold. I wish to make a complaint! # seller_parrot 4 'We're closin' for lunch. ... #END ============================================================ Two new groups of additions to the mob-programming command set allow working with variables, and with text files stored outside of the mud. These are brand-new, so please let me know if you need modifications or additions, or if something doesn't seem to work correctly. ------------------- MPSET ------------------- The central command for working with variables is mpset. The broad syntax is: mpset $letter something The letter can be any of the following: mobs/players intrxcw objects opq numbers 123 text !@& Currently, the following "somethings" are available. Adding to the list is easy, and will done upon request. =================== Mobs/players: mpset $letter master mpset $letter foe nameoftarget (in same room as mob) (returns NULL if target is not fighting) mpset $letter room nameoftarget (in same room as mob) mpset $letter owner $letter example: mpset $w master This sets $w to the mob/player the programmed mob is currently following. Avoid using $i, $n, $t, and $r, which typically have their values set automatically when a program triggers. example: mpset $w foe fred This sets $w to whomever 'fred' is fighting, or to NULL if there is no foe. example: mpset $w room fred This sets $w to the mob or player named 'fred' if they're in the same room as the mob, and NULL otherwise. mpset $letter owner $letter The second $letter MUST be an object variable pointing to a non-NULL object; the first will hold NULL is the object is not held by someone, and otherwise will point to the owner. "if objstatus($o) == whatever" can test the precise status, where whatever = d (deleted), s (stored in a locker), r (on the floor of a room), w (worn), i (in immediate inventory), f (in a container in a room), h (in a carried container). =================== Objects: mpset $letter uname + mpset $letter uname - mpset $letter inv objname The uname command doesn't actually set the object variable. Instead, it adds (+) a world-unique name to the front of the indicated object's namelist, or removes (-) the first name from the namelist. example: >trap_act_prog 'looks at a picture' if objexists($o) mpset $o uname + oset $o timer 1 mpset $o uname - endif If there were several pictures in the room, the use of uname would guarantee that the correct one (the one looked at) is the one referenced in the oset. (The "if" is to ensure that the prog wasn't triggered by an emote.) example: mpset $q inv guestbook This sets the variable to the named object in the mob's current carried inventory. Avoid using $o or $p if they get a value set automatically when the program triggers. mpset $letter firstinworld vnum mpset $letter nextinworld The first command sets $o to point to the first instance of an object with the specified vnum found anywhere online (including in the to-be-deleted-next-tick list). The second requires that the variable already point to an object, and finds the next in the world-list with the same vnum. Both return NULL if no object of the sought-for type is found. "if objexists($letter)" can be used to see if an item was found. Combined with the "while...wend" structure and the "if objstatus($o) == whatever" command, these commands can be used to process all online instances of any object. Example: >speech_prog 'go fetch' mpset $1 = 0 mpset $o firstinworld 1234 while objexists($o) mpset $1 = $1 + 1 mpset $o nextinworld wend 'I found $1 of 'em, boss! =================== Numbers: mpset $letter = formula example: mpset $1 = 3*(4+5) This sets the variable to a numeric value (in the example, 27). The formula can also use other numeric variables: mpset $1 = $1+5 increases $1 by 5 mpset $1 = $2+$3 adds two other variables Permissible mathematical operations are + (plus), - (minus), * (times), / (integer division), % (modulo), & (and), | (or), ^ (xor), and ~ (not). In addition, random numbers can be included in the formula as dice-rolls: mpset $1 = 5+3d7 adds 5 to the roll of three 7-sided dice (dice with 1-7 on their sides) mpset $2 = 1d$2 loads a random number between 1 and $2 ------------------- Various character (mob or player) statistics can be loaded into a variable: mpset $1 xxxx $target (The target can be any of intrxcw.) where xxxx = level, hitpts, mana, moves, alignment, drunk, full, thirst, int, wis, dex, str, con, gold, timer, in_room, race, or size. mpset $1 mpcalc $target questfieldname firstbit bitlength mpset $1 xxxx $target (The target can be any of opq.) where xxxx = value0, value1, value2, value3, containscount, or level. =================== Text: mpset $letter ie objname edkeyword mpset $letter we objname edkeyword mpset $letter re objname edkeyword Example: mpset $1 ie wallet secret This sets the variable to the description field of an "extra description" on an object in the mob's inventory (ie) or worn equipment (we), or in the same room (re). (The description is what is seen when you "look edkeyword" or "read edkeyword".) mpset $letter = text This assigns a text string to the variable. =================== Several text-related mpset options exist for writing games: mpset $1 stringlength textstring mpset $1 putletter $! $@ $& (all the arguments here must be string variables) mpset $1 countletters $! $@ (same here) mpset $! scramble textstring... mpset $! clearletters textstring... mpset $! getfromlist index list_of_words_or_single-quoted_phrases Examples: mpset $& = Mickey Mouse mpset $1 stringlength $& returns "12" mpset $! = e mpset $1 countletters $! $& returns "2" (the two e's in "Mickey Mouse") mpset $@ clearletters $& returns "______ _____" mpset $1 putletters $! $@ $& returns "2", and sets $@ to "____e_ ____e" mpset $@ = hello mpset $! scramble $@ returns a random scrambling of $@, e.g., "elohl" mpset $! getfromlist $1 Fred Mary 'Edward the Feeble' Tom Since a speech_prog automatically fills $1 with the index number of the found word or phrase, getfromlist can be used to have the prog vary its response depending on how it was triggered. Example: >speech_prog 'i love you' 'i hate you' mpset $! getfromlist $1 adore despise 'And I $! you! ------------------- USAGE OF VARIABLES ------------------- Variables can be used just about anywhere in a mob program. In particular, the numeric and text variables are substituted into commands directly as text: If $1 is 7, then you can mset self level $1 mob is now level 7 say Wow! My level is now $1! "Wow! My level is now 7!" oset self short $1 of 9 mob's short description is "7 of 9" if level($n) > $1 tests actor's level against 7 The only places where variable substitutions do NOT take place are before the comparison operator in an if statement, and in the variable name at the beginning of an mpset statement. This means that you must be careful about using $ anywhere as plain text. If you must do so, use $$, which will appear as a single dollar-sign. ------------------- IF VAR() ------------------- Syntax: if var($letter) comparison target This if-check compares a numeric or text variable with a value. For example, if var($1) <= 5+$2 compares the value of $1 with the result of adding 5 to the variable $2. ------------------- TEXTFETCH ------------------- Syntax: textfetch objname filename firstline totallines Example: textfetch quizbook questions.txt 5 2 The textfetch command reads consecutive lines from a text file, and loads them onto an object in the mob's carried inventory as extra descriptions associated with the keywords fetch1, fetch2, etc. In the example, lines 5 and 6 (2 lines) are read from the file "questions.txt", and loaded into the extra descriptions with keywords "fetch1" and "fetch2" on the quizbook. In combination with the mpset command, this allows a mob to vary its actions. For example, assume that questions.txt contains 20 lines, consisting of 10 questions, each followed immediately by an answer. mpset $1 = 2*1d10-1 loads $1 with a random number from 1, 3, ..., 19 textfetch quizbook questions.txt $1 2 reads a question and answer mpset $! ie quizbook fetch1 loads $! with the question say $! .... wait a while .... mpset $@ ie quizbook fetch2 loads $@ with the answer say The answer is: $@. ------------------- CHANT_PROG ------------------- There's also a new program type: chant_prog. The trigger is currently not used, and should be left at the default value of 100. If a player (or mob) chants anything in the programmed mob's presence, the program is triggered and whatever was chanted is stored as text variable $!. If the answers in the previous example were the single letters 'a' through 'd' (i.e., if the questions were multiple-choice), then the following program (assuming that fetch2 holds the answer) will hug those who answer correctly, and bonk all others. Note: The chant is NOT "heard" by anyone except the triggered mob. >chant_prog 100 mpechoat $n You chant an answer. mpechoaround $n $N chants an answer. mpset $@ ie quizbook fetch2 if var($@) == $! hug $n '$N got it! else bonk $n '$N blew it! endif ------------------- WHILE...WEND LOOPS ------------------- If you need to loop through a segment of code several times, until some condition is satisfied, the while...wend structure (typically combined with the use of mpset variables) will do the trick for you. Syntax: while ... lines of code ... wend The in-between code will be run repeatedly until the if-test is false. (If it's false the first time around, the code in the middle will be skipped entirely, just as if an if...endif structure had been used instead.) ------------------- OBJ_TRAP_INVOKE ------------------- The trigger to this object program is either 0, or a "word of invocation". The syntax of the "invoke" command is: invoke objectname invoke objectname [wordofinvocation!] invoke objectname targetperson [wordofinvocation!] invoke objectname at otherobject [wordofinvocation!] The command only works on an equipped object. If there is no word of invocation used in the command (or if an unrecognized word of invocation is used), then the invoke-prog with trigger 0 is run. Otherwise, the invoke-prog with the appropriate trigger-word is run. This permits one object to be invoked in multiple ways. $i = supermob $o = invoked object $n = invoker $p = other object, if any $t = target, if any $c = invoker (if no or valid trigger-word) or NULL (invalid trigger-word) ------------------- MEDIT ... SOCIAL ------------------- Under normal circumstances, a mob which is the target of a social ignores the social 4 times in 16, mirrors it 7 times in 16, slaps the socialer 4 times in 16, and, if the mob is lower in level the socialer, attacks the socialer 1 time in 16. While mediting a mob, you can change the times (out of 16) that each of the four responses occurs, and replace the "slap" with any other social. Type "social" while in medit mode to get the details. NOTE: The new social information that you enter is stored in a dummy mob-program. Don't edit this mob-program directly. Use the "social" command to change or remove your settings. ------------------------------- SPEECH_, CHANT_, and TELL_PROGS ------------------------------- All three now place the entire message into $! when the program is triggered.