Manual:DIL Manual/UNIT ST PC and UNIT ST NPC
Jump to navigation
Jump to search
UNIT_ST_PC and UNIT_ST_NPC
Constants (integer, vme.h: 0x02 and 0x01).
Characters: players (UNIT_ST_PC) and monsters (UNIT_ST_NPC). Test for both with u.type & (UNIT_ST_PC | UNIT_ST_NPC); the same mask works in foreach and findunit(). The type of a unit is in its type field; the four unit types are bits, so they can be combined with |.
Fields
Every character has: abilities, attack_type, charflags, defensive, endurance, exp, exptol, fighting, follower, followercount, level, mana, master, max_endurance, max_mana, natural_armour, offensive, opponentcount, position, race, sex, speed, switched, weapons. Players have more fields (see UNIT_ST_PC), and monsters two of their own (see UNIT_ST_NPC).
Notes
- Every unit, whatever its type, has the general fields: name, names, title, descr, outside_descr, inside_descr, extra, type, symname, nameidx, zoneidx, zone, key, outside, inside, next, gnext, gprevious, flags, manipulate, openflags, opendiff, weight, baseweight, capacity, height, light, bright, illum, minv, alignment, hp, max_hp, loadcount, hasfunc, spells.
dex_redcompiles but has no value: reading it stops the program with "unknown field type" in the log.spells[]exists on every unit, but holds spell skills only on characters.- Reading a field the unit doesn't have fails, and a failed value is false in every comparison: test the type first.
Example
dilbegin countchars();
var
u : unitptr;
n : integer;
code
{
n := 0;
foreach (UNIT_ST_PC | UNIT_ST_NPC, u)
n := n + 1;
log(itoa(n) + " characters around " + self.name);
quit;
}
dilend
Counts the players and monsters around the unit.