Functions are what make your if checks work, and often are used by mpset and mpsetvar for various reasons. They can be fairly simple, and they can be massively complicated. There are quite a few of them, but knowing how and where to use them is rewarding if you want to have truly unique and intelligent mobprogs. There are more details on how to use some of these functions in the Complex Mobprogs section of this tutorial.
atoi bankamt clanrank class fighting goldamt groupgrep hitprcnt idnum inclan inroom isaffected ischarmed isclanally isclanenemy isclanleader isfight isfollow isgood isimmort isnpc isoutlaw ispc isqueued iswearing level log MakeFirstLetterUpper name number objcost objtype objval? position premulticlass race rand sex stat strcat strrem time transformed var vinroom vinroomnum vnotinroom
Operators and Basic Functions
Numeric Operators
These operators function on numeric calculations. They are fairly obvious to anyone who knows a little about math. How they are generally used is something along the lines of the following: ==( , ) >( , ) !=( , ) The first empty space would be where you put a function that you want to measure, such as goldamt, stat, etc. The second part is something to compare what value is returned to. So if you wanted to see if a player’s goldamt was greater than 1000, you would do: if >(goldamt($n),1000) These functions can get complicated. Look at Complex Mobprogs for more details.
== = These operators mean ‘equal to’
!= <> >< These operators mean ‘not equal to’
> This
operator means ‘greater than’
< This
operator means ‘less than’
>= => These operators mean ‘equal or greater than’
<= =< These operators mean ‘equal or less than’
String operators
These operators function on strings, that is to say, any non-integer. So if you want to compare something like a name, you would simply use: if ==(name($n),”guard”). Or if you wanted to see if the string “guard” was contained in an actor, you’d use: if /(var-actor,”guard”). These work much the same as numeric operators.
== This operator means ‘equal to’
!= This operator means ‘not equal to’
/ This operator means ‘second string contained in first’
!/ This operator means ‘second string not in first string’
Math Functions
These are the functions used to do math. The general use is something along the following lines: +( , ) -( ) -( , ) *( , ) /( , ) %( , ) These should only be done to integers of course. Mobprog functions currently do not handle decimals or fractions. Example, if you want to add 3 to a variable you would use: mpsetvar variable $(+(var-variable,3)) See Complex Mobrpogs for greater detail.
+ This is for addition.
-(x) Negation. Turns positive to negative and vice versa.
-(x,y) This is subtraction. Subtract y from x.
* This is multiplication.
/ This is integer division.
% This is modulus division. Returns the remainder.
AND, OR, NOT
These functions only work when used in conjunction with others. The general use is: or( , , , , …) and( , , , , …) not( ) !( ) An example of the use of each is provided below. See Complex Mobprogs for more details.
or if or(=(var-salsa,3),ispc($n),==(inroom($i),10045))
ie: if var-salsa = 3, $n is a pc, or $i is in room 10045
and if and(isnpc($n),ischarmed($n),==(stat($i,”con”),16))
ie: if $n is an npc, and is charmed, and $i’s con is16
not ! if not(isgood($n)) if $n is not good
ie: if !(inroom($i),10045)) ie: if $i is not in room 10045
Mobprog Functions
Usage: atoi(variable)
This will convert a variable to an integer value if it is a valid argument. A good example of this would be to change a captured string (for example “1”) from a regular expression mobprog (such as speech_prog r) in a variable to an integer so mathematic functions can be applied to it correctly. See the Regular Expressions page for more information.
EXAMPLES:
mpsetvar me realcount atoi($[counter])
mpsetvar xxxguardxxx passcode atoi($1)
Usage: bankamt(character)
This returns the value of the amount of gold the character variable as in the bank. This only works on player characters.
EXAMPLE:
if >(bankamt($n),1000000)
mpadd mpecho The actor has more than a million coins in the bank.
else
mpadd mpecho The actor has less than a million coins in the bank.
endif
Usage: clanrank(clan number)
This function returns the clanrank of the clan whose number it is set to check.
EXAMPLES:
if >(clanrank(3),100000)
mpadd mpecho The clanrank of clan three is greater than 100000.
else
mpadd mpecho The clanrank of clan three is less than or equal to 100000.
endif
mpsetvar me tempclanrank clanrank(4)
Usage: class(character)
This checks the class of the character variable. For mobs, this is the C field found in the mob file. For players, this is their class, or in the case of a multi-classed character, the class they multied into. Check the FAQ section for class numbers.
EXAMPLE:
if ==(class($n),7)
mpadd mpecho The actor triggering me is a bard.
else
mpadd mpecho The actor triggering me is not a bard.
endif
mpsetvar me myclass $(class($o))
Usage: fighting(character)
This returns the character variable that the character variable listed is fighting.
EXAMPLES:
if ==(fighting($i),$i)
mpadd mpecho This would mean I am fighting myself. Silly.
else
mpadd mpecho I am not fighting myself.
endif
if ==(name(fighting($i)),"larry guard")
mpadd mpecho The person I am fighting has keywords larry and guard.
else
mpadd mpecho I am not fighting anyone with keywords larry and guard.
endif
if isnpc(fighting($i))
mpadd mpecho The person I am fighting is a mob.
else
mpadd mpecho The person I am fighting is not a mob.
endif
Usage: goldamt(character)
This returns the amount of gold that the character variable has on hand.
EXAMPLES:
if <(goldamt($n),10000)
mpadd mpecho The actor has over 10000 coins on hand.
else
mpadd mpecho The actor has 10000 coins or less on hand.
endif
mpsetvar me plrgold $(goldamt($n))
Usage: groupgrep(character,”function”)
This function has a number of uses, but in its basic form will allow a mob to keep track of who or what is in a group. In the below examples, treat $1 as an “empty” variable; a wild card for the moment. The $1 is used to determine information about the group in question.
EXAMPLES:
if groupgrep($i,"ispc($1)")
mpadd mpecho There is a player character in my group.
else
mpadd mpecho There is not a player character in my group.
endif
if groupgrep($[mob],"==($1,$[othermob])")
mpadd mpecho The mob stored in $[othermob] is in the same group as the mob stored in $[mob].
else
mpadd mpecho The mob stored in $[othermob] is not in the same group as the mob stored in $[mob].
endif
if groupgrep($i,"==(number($1), 10050)")
mpadd mpecho I am in a group with a mob with vnum 10050.
else
mpadd mpecho I am not in a group with a mob with vnum 10050.
endif
Usage: hitprcnt(character)
This returns the percent of hit points that the character variable has.
EXAMPLES:
if <(hitprcnt($i),25)
mpadd mpecho This means I have less than 25% of my hit points left.
else
mpadd mpecho I have greater than 25% of my hit points left.
endif
if >(hitprcnt($n),50)
mpadd mpecho The actor has more than 50% of its hit points left.
else
mpadd mpecho The actor has less than 50% of its hit points left.
endif
Usage: idnum(character)
This returns the unique ID number of the character, typically a player. This number is unique to the player and is never used again, so is useful for keeping track of a player regardless of their name or other information.
EXAMPLES:
if ==(idnum($n),57801)
mpadd mpecho The unique ID number of the actor is 57801.
else
mpadd mpecho The unique ID number of the actor is not 57801.
endif
if !=(idnum($n),idnum($[myvictim])
mpadd mpecho The unique ID number of the actor is not the same as the unique ID number of character variable myvictim.
else
mpadd mpecho The unique ID number of the actor is the same as the unique ID number of character variable myvictim.
endif
if >(idnum($r),$[lucky_number])
mpadd mpecho The unique ID number of the random actor is greater than the number stored in the lucky_number variable.
else
mpadd mpecho The unique ID number of the random actor is equal or less than the number stored in the lucky_number variable.
endif
mpsetvar me tempplrid $(idnum($n))
Usage: inclan(character)
This returns the clan, if any, of a character variable. This is done with operators.
EXAMPLES:
if ==(inclan($n),1)
mpadd mpecho This means the actor is in clan 1.
else
mpadd mpecho This means the actor is not in clan 1.
endif
if ==(inclan($n),inclan(var-mymaster))
mpadd mpecho This means the actor is in the same clan as the character contained in the mymaster variable.
else
mpadd mpecho This means the actor is not in the same clan as the character contained in the mymaster variable.
endif
Usage: inroom(character)
This checks to see if the character variable is in a room. This is done with operators.
EXAMPLES:
if ==(inroom($i),10001)
mpadd mpecho This means I am in room 10001.
else
mpadd mpecho I am not in room 10001.
endif
if !=(inroom($i),20001)
mpadd mpecho I am not in room 20001.
else
mpadd mpecho I am in room 20001.
endif
if ==(inroom($i),inroom($n))
mpadd mpecho I am in the same room as the actor.
else
mpadd mpecho I am not in the same room as the actor.
endif
mpsetvar me myroom $(inroom($i))
Usage: isaffected(character,affect number)
This checks to see if the character variable is affected by a specific affect. The affect number is usually the same as the F field numbers in the object file. Note: the following examples are the ONLY ways to get this function to work.
EXAMPLES:
if >((isaffected($n,3)),0)
mpadd mpecho The person triggering my prog is affected by detinvis.
else
mpadd mpecho The person triggering me can not see invis.
endif
if !(isaffected($i,7))
mpadd mpecho This means I am not affected by sanctuary.
else
mpadd mpecho I am affected by sanctuary.
endif
Usage: ischarmed(character)
This checks to see if the character variable is charmed. Note that charmed mobs have their mobprogs turned off, so it is pointless to do a if ischarmed($i).
EXAMPLE:
if ischarmed($n)
mpadd mpecho This means the person triggering me is charmed.
else
mpadd mpecho This person triggering my prog is not charmed.
endif
Usage: isclanally(character, clan number)
This checks to see if the character variable is a member of a clan that is an ally of the clan number given.
EXAMPLE:
if isclanally($n,1)
mpadd mpecho This means the person triggering me is in a clan that is an ally of clan 1.
else
mpadd mpecho This person triggering my prog is not in a clan that is an ally of clan 1.
endif
Usage: isclanenemy(character, clan number)
This checks to see if the character variable is a member of a clan that is an enemy of the clan number given.
EXAMPLE:
if isclanenemy($n,1)
mpadd mpecho This means the person triggering me is in a clan that is an enemy of clan 1.
else
mpadd mpecho This person triggering my prog is not in a clan that is an enemy of clan 1.
endif
Usage: isclanleader(character)
This checks to see if the character variable is a clanleader.
EXAMPLE:
if isclanleader($n)
mpadd mpecho This means the person triggering me is a clanleader.
else
mpadd mpecho This person triggering my prog is not a clanleader.
endif
Usage: isfight(character)
This checks to see if the character variable is in combat.
EXAMPLE:
if isfight($i)
mpadd mpecho I am fighting right now.
else
mpadd mpecho I am not fighting.
endif
Usage: isfollow(character)
This checks to see if the character variable’s master (the person they are following) is in the room.
EXAMPLE:
if isfollow($i)
mpadd mpecho I am following someone and they are in the room with me.
else
mpadd mpecho I am not following someone, or they are not in the room.
endif
Usage: isgood(character)
This checks to see if the character variable is good aligned.
EXAMPLES:
if isgood($n)
mpadd mpecho The actor setting my prog off is good aligned.
else
mpadd mpecho The actor setting my prog off is not good.
endif
if !(isgood($n))
mpadd mpecho The actor setting my prog off not good aligned.
else
mpadd mpecho The actor setting my prog off is good aligned.
endif
Usage: isimmort(character)
This checks to see if the character variable is level 32 or higher.
EXAMPLE:
if isimmort($n)
mpadd mpecho The person triggering my prog is an immortal or lord.
else
mpadd mpecho The person triggering my prog is a mortal.
endif
Usage: isnpc(character)
This checks to see if a character variable is a mob.
EXAMPLE:
if isnpc($n)
mpadd mpecho The actor setting my prog off is a mob.
else
mpadd mpecho The actor setting my prog off is a player character.
endif
Usage: isoutlaw(character)
This checks to see if a character variable is a killer, thief, or criminal.
EXAMPLE:
if isoutlaw($n)
mpadd mpecho The actor setting my prog off is a killer, thief, or criminal.
else
mpadd mpecho The actor setting my prog off is not an outlaw.
endif
Usage: ispc(character)
This checks to see if a character variable is a player character.
EXAMPLE:
if ispc($n)
mpadd mpecho The actor setting my prog off is a player character.
else
mpadd mpecho The actor setting my prog off is not a player character.
endif
Usage: isqueued(character)
This function checks to see if the character variable already has commands in its queue. This normally only works on mobs, usually $i.
EXAMPLE:
if isqueued($i)
mpadd mpecho I have commadns in my queue already.
else
mpadd mpecho I do not have any commands queued at the moment.
endif
Usage: iswearing(character,object vnum)
This checks to see if the character variable is wearing or using an object of a specified vnum. Note: the following examples are the ONLY ways to get this function to work.
EXAMPLES:
if >((iswearing($i,10001)),0)
mpadd mpecho This means I am wearing object 10001.
else
mpadd mpecho I am not wearing object 10001.
endif
if !(iswearing($i,20001))
mpadd mpecho This means I am not wearing object 20001.
else
mpadd mpecho I am wearing object 20001.
endif
Usage: level(character)
This checks the level of the character variable.
EXAMPLES:
if <=(level($n),15)
mpadd mpecho The actor triggering me is 15th level or less.
else
mpadd mpecho The actor triggering me is above 15th level.
endif
if >(level($n),level($i))
mpadd mpecho The actor triggering me is higher level than me.
else
mpadd mpecho The actor triggering me is my level or under.
endif
mpsetvar me victimlevel $(level($n))
Usage: log(string) (See examples.)
This mobprog simply logs a message of your choosing into the syslog. This is good for keeping track of players interactions with mobs, but most zone builders will not be interested in using it unless they have administrative access and need to log information for other administrators and themselves to check on. The message logged must be a string, and thus anything you wish to log must already be a string or be formatted to be a string.
EXAMPLE:
mpsetvar me logstr "$n reset me."
if log($[logstr])
else
endif
Usage: MakeFirstLetterUpper(variable)
This function will take the first letter of a string contained in a variable and make the first letter uppercase. In some instances, variables that have been captured will default to lower case and you need it to be upper case (a name, for instance), or you may wish to make a variable string that is normally lower case capitalized (to start a sentence, for instance). See the Regular Expressions page for more details.
EXAMPLES:
mpsetvar me newvariable MakeFirstLetterUpper($[oldvariable])
mpsetvar xxxdragonxxx myfriend MakeFirstLetterUpper($1)
Usage: name(character/object)
Returns the name of the character variable or object.
EXAMPLES:
if ==(name($n),”guard sven tall”)
mpadd mpecho The keywords of the actor include guard, sven, and tall.
else
mpadd mpecho It isn’t Sven the Tall guard that’s triggering me.
endif
if ==(name($o),”gold ring fancy”)
mpadd mpecho The keywords of this object are gold, ring, and fancy.
else
mpadd mpecho The object is not a fancy gold ring.
endif
mpsetvar me nameofactor $(name($n))
Usage: number(character/object) or number(integer x,integer y)
This function has a few uses. First of all, it can return the vnum of a character variable or an object. Secondly, it can be used to generate a random numbe between x and y.
EXAMPLES:
if ==(number($n),10045)
mpadd mpecho The vnum of the actor is 10045.
else
mpadd mpecho The vnum of the actor is not 10045.
endif
if ==(number($o),1123)
mpadd mpecho The vnum of the object is 1123.
else
mpadd mpecho The vnum of the object is not 1123.
endif
mpsetvar me diceone number(1,6)
Usage: objcost(object)
Returns the gold value of an object.
EXAMPLE:
if ==(objcost($o),0)
mpadd mpecho The object has a gold value of 1000.
else
mpadd mpecho The object does not have a gold value of 1000.
endif
mpsetvar me price $(objcost($o))
Usage: objtype(object)
Returns the type of object that an object is.
EXAMPLE:
if ==(objtype($o),5)
mpadd mpecho The object is type 5, a weapon.
else
mpadd mpecho The object is not a weapon, since it is not type 5.
endif
Usage: objval?(object)
This function returns the ?th value of the object, where ? is a number from 0 to 3. This returns numbers from the line in the object file where there are four values that vary by obj type.
EXAMPLES:
if ==(objval1($o),2)
mpadd mpecho The second number on the misc value line of the object is 2.
else
mpadd mpecho The second number on the misc value line of the object isn’t 2.
endif
if and(==(objtype($o),9),>=(objval0($o),5))
mpadd mpecho The object is type armor, and has an acap of 5 or better.
else
mpadd mpecho The object is not armor, or is armor but worse acap than 5.
endif
Usage: position(character)
This checks the position of the character variable. The position is a number; you can see what value each position has by looking at the docs on mob creation in the main building docs on the Age of Chaos web site.
EXAMPLES:
if ==(position($n),8)
mpadd mpecho This means that the actor is standing.
else
mpadd mpecho This means the actor is not standing.
endif
if <(position($n),5)
mpadd mpecho The actor triggering me is SLEEPING or worse.
else
mpadd mpecho The actor triggering me is RESTING or better.
endif
Usage: premulticlass(character)
This checks the class of the character variable before multiclass. This only works on multiclassed player characters, and so can be used to check this fact.
EXAMPLE:
if ==(premulticlass($n),7)
mpadd mpecho The actor triggering me was a bard before multi.
else
mpadd mpecho The actor triggering me was not a bard before multi.
endif
Usage: race(character)
This function returns the race of the character variable. Note that mobs don’t have a race technically, unless they set themselves to have one first. For race integer values, check out the FAQ’s page.
EXAMPLE:
if ==(race($n),2)
mpadd mpecho The actor is race 2, or elf.
else
mpadd mpecho The actor is not an elf, because it is not race type 2.
endif
Usage: rand(integer)
This generates a random number and checks to see if it is under the integer. This is best used for random events where there are only two outcomes.
EXAMPLE:
if rand(40)
mpadd mpecho This is under 40% chance for me to echo this.
else
mpadd mpecho Not under 40%.
endif
Usage: sex(character)
This checks the sex of the character variable, usually using operators.
EXAMPLES:
if ==(sex($n),1)
mpadd mpecho The actor triggering me is a male.
else
mpadd mpecho The actor triggering me is not a male.
endif
if ==(sex($n),2)
mpadd mpecho The actor triggering me is a female.
else
mpadd mpecho The actor triggering me is not a female.
endif
if !=(sex($n),sex($i))
mpadd mpecho The actor triggering me is the opposite sex of me.
else
mpadd mpecho The actor triggering me is not the opposite sex of me.
endif
Usage: stat(character,string)
This returns the value of the stat in the string position
for a character variable. Valid values for the stat include “str” “stradd” “intel” “
EXAMPLES:
if <(stat($i,”con”),16)
mpadd mpecho My con is less than 16.
else
mpadd mpecho My con is 16 or greater.
endif
if >(stat($i,”cha”),stat($n,”cha”))
mpadd mpecho My charisma is greater than the charisma of the actor.
else
mpadd mpecho The actor has a charisma equal to or greater than mine.
endif
Usage: mpsetvar me (variable name) strcat(string,string,…,…)
The strcat function takes multiple strings and places them all inside a single variable. This is useful for creating lists of information. A good use for this, for example, would be to create and store a list of players that you want the mob to remember. Any number of strings can be contained inside the variable. This function works in conjunction with the strrem function, which removes strings from the lists contained in variables created with the strcat function. Note that only strings may be stored in this manner, and so items stored in the variable must be strings or be converted into them. The / and !/ operators for strings are useful for searching through these lists (see example). See the examples on the Complex Mobprog page for more information on this function.
EXAMPLES:
mpsetvar me weird strcat(“Indeed “,$[grubby])
mpadd mpecho The above stores the word “Indeed ” and the variable contained in $[grubby] to variable weird.
mpsetvar me playerlist strcat(strcat($[playerlist],$[tempplayer])," : ")
mpadd mpecho The above adds the string stored in $[tempplayer] to the string “ : “ and adds that new string to the string contained in playerlist.
mpsetvar me tostore var-actor Store $n or var-actor to a variable called tostore.
mpsetvar me storethis “$[tostore]” Store variable tostore in a new string variable called storethis.
if /(var-questlist,var-storethis)
mpadd mpecho This means the variable contained in storethis (the name of $n) is already stored in the variable questlist.
else
mpsetvar me questlist strcat(“$[questlist]”,var-storethis)
mpadd mpecho The above sets the contents of the variable questlist to the old contents of questlist and adds storethis to the end of it.
endif
Usage: mpsetvar me (variable name) strrem(string variable,string)
This function will remove strings that are inside of variables that have been set to contain multiple strings using the strcat function. The strrem function will remove the first occurrence of the string inside of the variable if one matches the string inputted. This function only operates with strings, and so arguments must be strings or be forced into string format before being used. See strcat for further details on the uses of these functions, including the benefits of using the / and !/ operators (see example).
EXAMPLES:
mpsetvar me weird strrem(“$[weird]”,var-chocolate)
mpadd mpecho The above removes any strings matching the variable chocolate stored in the variable weird.
mpsetvar me tostore var-actor Store $n or var-actor to a variable called tostore.
mpsetvar me storethis “$[tostore]” Store variable tostore in a new string variable called storethis.
if !/(var-questlist,var-storethis)
mpadd mpecho This means the variable contained in storethis (the name of $n) is not stored in the variable questlist.
else
mpsetvar me questlist strrem(“$[questlist]”,var-storethis)
mpadd mpecho The above sets the variable questlist to the contents of questlist, erasing the first occurrence of storethis.
endif
Usage: time
This returns the integer number of seconds since 1970 at the current time the function is called on. Simply put, the time function is a way of using time in your mobprog, allowing you to create deadlines or timers or lifespans. It is useful for all time related mobprogs. Most of the time you will be comparing time to a variable previously set using the time function in order to create an actual “timer.”
EXAMPLES:
mpsetvar me starttimer time
mpadd mpecho The above takes a time stamp when the mobprog was called and sets starttimer to that time.
if >(-(time,300),$[starttimer])
mpadd mpecho Time is up (this means time minus 5 minutes is greater than starttimer).
else
mpadd mpecho Time is not up (more than 300 seconds have not yet passed since the creation of starttimer).
endif
$[endtimer] := +(time,300)
mpadd mpecho The above creates a variable set to the current time plus 300 seconds.
if <($[endtimer],time)
mpadd mpecho Time is up (the endtimer variable, set to time plus five minutes, is less than the current time).
else
mpadd mpecho Time is not up (300 seconds have not yet passed and time is still smaller than endtimer).
endif
Usage: transformed(character)
This checks to see if the character, a player, is transformed (transed) or not.
EXAMPLES:
if transformed($n)
mpadd mpecho The actor is transformed, so is level t31 or above.
else
mpadd mpecho The actor is not transformed, so is level 30 or below.
endif
if transformed($[myvictim])
mpadd mpecho The character variable held in myvictim is transformed, so is level t31 or above.
else
mpadd mpecho The character variable held in myvictim is not transformed, so is level 30 or below.
endif
Usage: var(string) or var(string,character)
This function returns the value of the variable in the string space. If this function is called with a character variable, use that mob’s variable list instead of the calling mob. Currently you can only have a mob take a variable from another mob if it is an integer, although you can achieve the same effect with all variable types using shared variables or by having a mob set another mob’s variables. See Fun With Variables for more information.
EXAMPLE:
if ==(var(“actor”),$r)
mpadd mpecho The actor is also the random actor.
else
mpadd mpecho The actor and the random actor are different people.
endif
mpsetvar me genvar $(var(“salsa”,$n))
Usage: vinroom(integer)
This function checks to see if a mob of a certain vnum is in the room.
EXAMPLE:
if vinroom(10045)
mpadd mpecho There is a mob of vnum 10045 in the room.
else
mpadd mpecho There is not a mob of vnum 10045 in the room.
endif
Usage: vinroomnum(character)
This function returns whether the character variable, usually $i in this case, is the 1st, 2nd, 3rd, etc. mob of its vnum in the room.
EXAMPLE:
if ==(vinroomnum($i),2)
mpadd mpecho This means I am the 2nd mob of the same vnum in this room.
else
mpadd mpecho I am not the second mob of the same vnum in this room.
endif
Usage: vnotinroom(integer)
This function checks to see if no mob of a specific vnum is in the room.
EXAMPLE:
if vnotinroom(10035)