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 these functions in the Complex Mobprogs section of this tutorial.
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 detail.
== = 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 generaly 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.
* 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 sue of each is provided below. See Complex Mobprogs for more details.
or if or(=(var-salsa,3),ispc($n),==(inroom($i),10045))
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))
if $n is an npc, and is charmed, and $i’s con is16
not ! if not(isgood($n)) if $n is not good
if !(inroom($i),10045)) if $i is not in room 10045
assert
Usage: assert(any x)
This returns true if the expression converted into an integer using the int function returned a valid argument. Currently this function is rarely, if ever, used.
EXAMPLE:
if >(assert(var-count),0)
mpadd mpecho Variable count returned a valid argument when converted by int.
else
mpadd mpecho Variable count did not return a valid argument.
endif
bankamt
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
class
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
fighting
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
goldamt
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 plrgold $(goldamt($n))
hitprcnt
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
inroom
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
int
Usage: int(any x)
This function converts anything to an integer or boolean value, regardless of of what type it used to be. This function is currently rarely, if ever, used.
EXAMPLES:
int($i)
int(var-myvictim)
isaffected
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
ischarmed
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
isfight
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
isfollow
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
isgood
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
isimmort
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
isnpc
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
ispc
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
isqueued
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
iswearing
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
level
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
name
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
number
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 diceone number(1,6)
objtype
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
objval?
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
position
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
premulticlass
Usage: premulticlass(character)
This checks the class of the character variable before multiclass. This only works on multiclassed player characters.
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
race
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
rand
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
sex
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
stat
Usage: stat(character,string)
This returns the value of the stat in the string position for a character variable. Valid values for the stat are “str” “stradd” “intel” “wis” “dex” “con” “cha” “hit” “maxhit” “mana” “maxmana” “move” “maxmove”
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
var
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. 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 genvar $(var(“salsa”,$n))
vinroom
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
vinroomnum
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
vnotinroom
Usage: vnotinroom(integer)
This function checks to see if no mob of a specific vnum is in the room.
EXAMPLE:
if vnotinroom(10035)
mpadd mpecho There is no mob of vnum 10035 in this room.
else
mpadd mpecho There is a mob of vnum 10035 in the room.
endif