Variables & Attributes:
Scripts support 2 basic types of variables: mud variables and script
variables. Mud variables are the ones that the mud passes to the script
when it calls on the script to run.
MUD VARIABLES
We support several types of built in or mud variables:
| variable |
mobile, object, room or area that 'contains' the script |
actor |
victim |
random |
object |
2nd_object |
| |
|
|
|
|
|
|
| name |
$i |
$n |
$t |
$r |
$o |
$p |
For objects,
$i = the object itself
$o = the direct object (ie, the object is receiving
the action)
$p = the indirect object (ie, the object is
the indirect object)
It is important to note that not all types of scripts define all the
variables. For example, when dealing with a @rand script on a mob, only
the $r and $i variables are defined, since there is no actor or victim.
@action scripts define the most variables, for example a mob observing
two people fighting would recieve $i, $n, $t, and $r variables.
Variable Attributes:
You can use the variables to make the script print out (or compare to)
the name of a player, mob, object or even room. You can also use these
variables to get to the attributes of the entity they refer to.
Eg. $n.level will return the level of the mob
represented by $n.
The following attributes are supported:
Player or Mob attributes:
| Attribute Name |
Type |
Description |
| |
|
|
| name |
String |
name of the player or mob |
| hp |
Integer |
hit points |
| room |
Reference |
room the player or mob is in |
| level |
Integer |
The level of the player or mob |
| master |
Reference |
whoever has charm control |
| leader |
Reference |
whoever the player/mob is following |
| opponent |
Reference |
opponent whoever the player/mob is fighting |
| pet |
Reference |
the pet of the player/mob |
| short_descr |
String |
short description |
| long_descr |
String |
long description |
| sex |
String |
sex (male, female, neuter) |
| class |
String |
class (mage, warrior, thief, cleric) |
| race |
String |
race (elf, human, dwarf, etc) |
| trust |
Integer |
trust (imm level) |
| mana |
Integer |
mana points |
| move |
Integer |
move points |
| gold |
Integer |
how rich the bastard is |
| position |
Integer |
sleeping:4 resting:5 sitting:6 fighting:7 standing:8 |
| carry_weight |
Integer |
amount in weight the player/mob is carrying |
| carry_number |
Integer |
number of items being carried |
| saving_throw |
Integer |
saving throw |
| alignment |
Integer |
alignment |
| size |
String |
small, human, huge, giant |
| weight |
Integer |
weight |
| timer |
Integer |
timer value |
| tribe |
Reference |
tribe (pc only) reference |
| title |
String |
title string (pc only) |
| is_chief |
Boolean |
true/false for if a chief (pc only) |
| action_flags |
|
action flags (npc only) |
| aggie_flags |
|
aggressive flags (npc only) |
| comm_flags |
|
communication flags (npc only) |
| immune_flags |
|
immunity flags |
| resist_flags |
|
resistance flags |
| vuln_flags |
|
vulnerability flags |
| offense_flags |
|
offense flags (npc only) |
| s |
String |
his/her/its |
| e |
String |
he/she/it |
| m |
String |
him/her/it |
| persname |
String |
Player name or mob short_description |
| vnum |
Integer |
mob vnum |
| quest |
Quest References |
Quest information |
| str |
Integer |
Strength |
| int |
Integer |
Intelligence |
| wis |
Integer |
Wisdom |
| dex |
Integer |
Dexterity |
| con |
Integer |
Constitution |
| id |
Integer |
Unique id that each player is assigned. Id is preserved in pfile,
so it doesn't change between logins. This id is good to use if you
want to keep a reference to a particular player... ie, better than
the 'name' because it's a much faster 'compare'. Either way works
of course. Note that this id will NOT work on mobs. It will error
out if you try. |
Note that some attributes are themselves references.
Ie, $n.master.name would display the $n's master's
name.
Be carefull when using an attribute that is either npc or pc only. You
should always test for the condition you are looking for before attempting
to use one of these attributes. For example if you wanted a mob that only
greeted members of a certain tribe, you could use something like this:
@greet 100~
{
if (@ispc($n) and $n.tribe) {
if ($n.tribe.title == "illum") {
say Greetings fellow member of the Illuminati.
}
}
}
First we tested to make sure who ever entered the room ($n) was a pc
and also we made sure that $n had a tribe, then we went on with the rest
of the script. The same would be true if you wanted to test an attribute
specific to an npc. Some of the attributes, namely short_descr
and long_descr are available on pcs, but are
always blank.
Object attributes:
| Attribute Name |
Type |
Description |
| |
|
|
| name |
String |
object name |
| vnum |
Integer |
vnum of the object |
| level |
Integer |
object's level |
| room |
Reference |
vnum of the room an object is in |
| has_contents |
Boolean |
true/false if a container has stuff in it (container only) |
| container |
|
|
| carried_by |
Reference |
whoever is carying the object |
| enchanted |
|
|
| short_descr |
String |
short description |
| long_descr |
String |
long description |
| type |
|
|
| wear_loc |
|
|
| wear_flag |
|
|
| weight |
Integer |
how much the object weighs |
| cost |
Integer |
how much the object costs |
| condition |
|
|
| material |
String |
what the object is made of (steel, paper, etc) |
| timer |
Integer |
object's timer |
| v0 |
Integer |
|
| v1 |
Integer |
|
| v2 |
Integer |
|
| v3 |
Integer |
|
| v4 |
Integer |
|
| spell_affects |
|
|
| exclusion_flags |
|
|
| spell_affects |
|
|
| extra_flags |
|
|
| id |
Integer |
Each object has a unique (runtime) id which can be used in 'set'
routines.. (set obj < id > v5 3) |
Room Attributes
| Attribute Name |
Type |
Description |
| |
|
|
| name |
String |
room name |
| vnum |
Integer |
room vnum |
| area |
Reference |
the area this room is in |
| has_people |
Boolean |
does the room have people in it? |
| has_objects |
Boolean |
are there objects in the room? |
| description |
String |
the room's description |
| flags |
Flag |
room flags |
| is_lit |
Boolean |
is the room lit? |
| sector_type |
Integer |
number of the sector type for this room |
Area Attributes
| Attribute Name |
Type |
Description |
| |
|
|
| name |
String |
area name |
| lowerlevel |
Integer |
Lower level bounds for area |
| higherlevel |
Integer |
Higher level bounds for area |
Room and Area attributes can only be referenced through a mob or object
variable. For example, if you wanted a mob that said the name of the area
every time it entered a room, you would do something like this:
@entry 100~
{
say This is a great room here in $i.room.area.name
}
The $i variable references the mob itself, the room attribute gets the
room info, area gets the area info for the room, and name is the attribute
of the area we're looking for.
Similarly if you wanted to get the vnum of a room, you could do so like
this:
@entry 100~
{
if ($i.room.vnum == 1234) {
say Cool! It's Estranged's room!
}
}
Tribe Attributes
| Attribute Name |
Type |
Description |
| |
|
|
| name |
String |
tribe name (ie, The Academy of Orion) |
| title |
String |
Title as it appears in 'who'... good for compares.. (ie, Vamps) |
| recall |
Room reference |
The tribal recall room. |
| qptrs |
Integer |
The tribal quest points so far. |
Quest Attributes
| Attribute Name |
Type |
Description |
| |
|
|
| state |
Integer |
The 'state' the quest is currently in. ($n.quest.17.state) |
| startdate |
Integer |
Start date (in seconds from 1970) of the quest. ($n.quest.17.startdate) |
| enddate |
integer |
The end date (in seconds) of the quest.. ($n.quest.17.enddate) |
| VARNAME |
VARTYPE |
Quests can have 'local' variables.. declared specifically for the
quest. You can access them from here ($n.quest.17.numkills) |
SCRIPT VARIABLES
Scripts also support script variables, or variables declared within
the script itself. For example
@speech p give me gold~
{
declare $amount number
$amount = 10;
give $amount $n
}
There are a few new concepts here. First we have the declaration
of the script variable. We define here what the name and the type of the
variable is to be. We currently support the following types of script variables:
number : a number
string : a string or 'list of letters'... such as a player's name, room's
description, etc.
person : a player or mob
object : an object like a cup, fountain, sword
room : a location
area : an area
boolean : TRUE or FALSE values
flag : action flags, etc, from mobs, rooms, etc.
tribe: a tribe reference
The declaration can occur anywhere within the script. However, you cannot
reference the variable until after it has been declared.
Important! All variables should be declared and referenced
using lowercase letters only. While you can declare $myFunkyCapsVar, trying
to have a mob "say $myFunkyCapsVar" will produce an error.
Second, we have the assignment. Assignemnt must
be terminated with a semi-colon (;), so we can tell this
is a variable asignment. Currently assignments are very simple types...
basically the = the . We do not currently
support full expression evaluation. For example, you can't:
$amount = $n.gold + 20;
At least, you can't right now. Subroutines (see functions) will be supplied
to do some of the basic things for now. So you will be able to do this:
$amount = @add($n.gold, 20);
Finally, there is the reference, or use, of
the variable. The only restriction is that the variable must be declared
before its use and used only within the scope of the code section. A code
section is deliminated by the curly braces ({, }). Example:
@speech p give me some gold~
{
declare $amount number
$amount = 10; if ($n.sex == female) {
declare $test string
$test = "Hi there";
say $test! -- ok, $test is in scope
$amount = 20; -- also ok, $amount is in scope (from previous
frame)
}
give $amount $n -- ok, $amount in scope
say $test again! -- ERROR! $test is out of scope
}
As they are right now, variables aren't VERY useful.. except! We now
introduce two more script types... init and init type scripts. These scripts
can be useful unto themselves, but are very useful in regards to script
variables.
We can declare special variables in init and init type scripts. These
special variables are called 'global' variables.
declare global $count number
Thus, for example, if we declared the above variable in a mob init script,
that variable would be 'in scope' or accessible to ALL scripts that the
mob has. Thus if one script set the value of $count to 10 and another
script referenced $count, the value would be $10 for that particular mob.
Another mob (of the same type) might have a different value for $count.
We can also declare global variables in init type scripts for mobs.
This would mean that the variable is in scope for ANY script and any mob
of that type. Thus ALL the green monkeys, for example, would have the
same value for the variable.
Finally, we also have an init script for the area. All script that are
declared for the area can reference global variables declared here. Thus
if we had $areaVariable declared in Bree, any script of the any green
monkey, any Bree hobbit, any Bree dart could use this variable and they
would all see the same value.
The following is the 'stack of frames' for scripts on different entites:
Room scripts:
[area init global variables]
[room init global variables]
[local script variables]
Mob scripts:
[area init global variables]
[mob init type global variables]
[mob init global variables]
[local script variables]
Object scripts:
[area init global variables]
[object init type global variables]
[object init global variables]
[local script variables]
We also support the idea of saving variables with the pfile in one particular
circumstance. Variables that are associated with OBJECTS
(not object types or area level variables, but simply object level variables)
may be declared as such:
declare global persistent $charge number
When this is done, the variable is saved with the player and the value
is reloaded when the character logs in again.
|