Aardwolf MUD Home Page Link

Location: Home / Lua Coding / Ch Properties

The table below lists character properties visible from Lua at the time of writing. If your prog needs to access character data not in this list, contact Lasher.

PropertyDescription
AimedReturns a 'ch' variable for current combat target.
AlignCurrent alignment
CapnameSame as ch.name, but capitalized.
ClanCharacter's clan.
ClassPrimary class .
ClonesReturns number of same type of mob in the room, excluding self. Always 0 for players.
ConCurrent Constitution.
DamtypeCharacter's primary damtype - compare to FOCUS_ variables below.
*DescCharacter description - settable on mobs only.
DexCurrent Dexterity.
*ExploredNumber of rooms the character has explored.
*ExploredHereNumber of rooms the character has explored in the current area.
*GoldGold on hand
HesheHe/She/It name for current char.
HimherHim/Her/It name for current char.
HisherHis/Hers/Its name for current char.
HpCurrent hit points
MaxhpMax hit points
HppctPercentage of HP remaining
IngameNumber of same mob in-game
FollowingReturn name of character the target is following
GidUnique integer ID on each char - used for comparison.
GroupsizeNumber of other people in player's group in room
GtargetSame as target, but the previously remembered char does not still have to be in the same room.
IngameNumber of instances of this Mob in the game. Mobs only.
IntCurrent Intelligence.
ItemsCarriedNumber of items the player is carrying.
ItemsCapacityNumber of items the player can carry.
KeyMob key of character, blank for a player
KeywordsMob only - returns keywords of the mob. Useful with give etc.
LastroomRoom the character was last in. See the Lua howto page for example use.
LeaderReturn name of the character's group leader
LevelLevel of character.
*LongnameDescription of mob as seen in room - settable on mobs only.
LuckCurrent Luck.
ManaCurrent mana
MaxmanaMax mana
ManapctPercentage of mana remaining
MobkillsNumber of mobs the player has killed.
MovesCurrent moves
MaxmovesMax moves
MovepctPercentage of moves remaining
*NameCharacter Name. (Settable on mobs only)
OrderReturns order of current mob in room. Useful when you have multiple mobs of same type and only want a prog to fire once.
OwnerReturn name of character's owner - only applies to pet
PositionCurrent position of character
*PracticesPractices on hand, player only.
QuestsdoneNumber of quests the player has completed.
RaceCharacter Race.
RacenameCharacter Racename.
RoomReturns room character is in as a ROOM type variable.
RoomkeyReturns key of room character is currently in.
SavesCurrent saves
SexIf you're offering, submit applications to webmaster.
*SpouseName of the player's spouse.
StrCurrent Strength.
SubclassCharacter subclass.
TargetReturns mob's target as 'CH' type. See below.
TierCurrent tier of character.
TimeHereNumber of seconds in the current room.
TotlevelTotal level as it would appear in rank 1.
*TrainsTraining sessions on hand, player only.
WeightCarriedTotal weight the player is carrying.
WeightCapacityTotal weight the player can carry.
WisCurrent Wisdom.
 
data1See below
data2See below
data3See below
data4See below
data5See below

MUD Table Definitions

When using properties such as race, class, subclass and clan, the values returned are numbers. If you happen to know that Troll is race number 11, you could write something like:

if ch.race == 11 then
   say("Hi Troll!")
end

While this works, it is not very convenient. To help with comparing values in tables, several of the game tables have their contents loaded into Lua for easier comparison. The following are all valid:

if ch.race == RACE_TROLL ...
if ch.class == CLASS_MAGE ...
if ch.subclass == SUBCLASS_ARCHER ...
if ch.clan == CLAN_SHADOKIL ...
if ch.sex == SEX_FEMALE ...
if ch.position == POS_SITTING ...

Lua Object Return Types

Some of the properties on objects will return other objects on the stack rather than string or integer values. Once you have a variable of this type, all of the usual properties are available on it. For example, when 'targ = self.target' returns the mob's target, then all the properties of 'targ' are available using targ.level, targ.int, etc.

Comparing Lua Object Return Types

One other important point for builders to remember is that similar objects in Lua do not compare as equal. For example, if Razor triggers a program (ch) and the mob gets it's target (targ) then wants to see if Razor is already it's target, it cannot simply do if ch == targ. This is because the two variables are two different objects in Lua that just happen to point to the same underlying character in the MUD. Every character in the game has a unique 'gid' value and this is what should be used for comparison.

In the sample Lua code below, the mob checks if it has a target already. If it doesn't, it remembers the character triggering the prog. If it does, it wants to either inform the player that they are its target, or inform the player who the target it. The 'gid' character property is used for the comparison:

targ = self.target
if targ == nil then
   say ("I don't have a target")
   remember(ch)
else
   if (targ.gid == ch.gid) then
      say ("Hi! You're my target!")
   else
      say ("My target's name is " .. targ.name)
   end
end

As we get into more advanced Lua programming and store character information for later re-use (in prog timers for example), it is always the 'gid' that will be stored, never a direct pointer to the character themselves which can be become invalid if the target character quits/is killed in the meantime.


Data1 .. Data5 Values

The Data1 to Data5 values are numeric values that can be set on a mob and are saved over a reboot. These have generic names because their purpose is not defined - it is whatever makes sense for the builder to track. Some examples may be number of times a mob has been killed, or the number of repops until a mob moves location or opens a door, etc. It can even be the chance of something happening with the chance increasing each repop via a repop trigger.

Note that all mobs of the same type share data1 .. data5 values. If you have 2 or more of the same mob loading and you set these values, you are setting it for all of them, so it cannot be used to track data about individual instances of mobs.


Damage Focus Types

These values are used with the ch.damtype property. For example:

say("Your damage type is " ..ch.damtype);
if ch.damtype == FOCUS_FIRE then
   say("You are using fire.");
else
   say("You are not using fire.");
end

if ch.damtype == FOCUS_SLASH or ch.damtype == FOCUS_BASH or ch.damtype == FOCUS_PIERCE then
   say("You are using physical damage!");
end
ValueDefinition
0FOCUS_BASH
1FOCUS_PIERCE
2FOCUS_SLASH
3FOCUS_ACID
4FOCUS_AIR
5FOCUS_COLD
6FOCUS_DISEASE
7FOCUS_EARTH
8FOCUS_ENERGY
9FOCUS_FIRE
10FOCUS_HOLY
11FOCUS_LIGHT
12FOCUS_ELECTRIC
13FOCUS_MAGIC
14FOCUS_MENTAL
15FOCUS_NEGATIVE
16FOCUS_POISON
17FOCUS_SHADOW
18FOCUS_SONIC
19FOCUS_WATER