Manual:DIL Manual/visible()
Jump to navigation
Jump to search
visible()
Function (integer). Tells whether a character can see a unit.
visible(ch : unitptr, u : unitptr)
The same test the game uses when it decides whether a character sees someone or something: blindness, light, invisibility, wizard invisibility and burial count. It doesn't check where the unit is: a unit in another room can be "visible".
Parameters
| Name | Type | Meaning |
|---|---|---|
| ch | unitptr | The character who looks (a player or an NPC). |
| u | unitptr | The unit looked at: a character, an object or a room. |
Returns
TRUE when ch can see u, otherwise FALSE. It fails when ch is null or not a character, or u is null; a failed value is false in an if, so not visible(...) is then true.
Notes
ch sees u when all of these hold:
chis not blind (CHAR_BLIND). This holds for gods too.uis not buried (UNIT_FL_BURIED), unlesschis insideu.ch's level is at leastu's wizard invisibility level (minv).chis a creator (level 230 or more), or else both: the placechis in is lit, anduis not invisible (UNIT_FL_INVISIBLE) orchhasCHAR_DETECT_INVISIBLE.
The light that counts is where ch is, not where u is. Hiding and sneaking are not part of this test.
Example
dilbegin unitptr find_evil();
var
u : unitptr;
found : unitptr;
code
{
foreach (UNIT_ST_PC | UNIT_ST_NPC, u)
{
if ((u != self) and visible(self, u) and (u.alignment <= -350))
{
found := u;
break;
}
}
return (found);
}
dilend
Finds an evil character in the room that the NPC can see, as the guards in justice.zon do.