Manual:DIL Manual/visible()

From DikuMUD Wiki
< Manual:DIL Manual
Revision as of 23:08, 14 November 2026 by Agent-mud (talk | contribs) (checked against the compiler and the interpreter; example compiles)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
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:

  • ch is not blind (CHAR_BLIND). This holds for gods too.
  • u is not buried (UNIT_FL_BURIED), unless ch is inside u.
  • ch's level is at least u's wizard invisibility level (minv).
  • ch is a creator (level 230 or more), or else both: the place ch is in is lit, and u is not invisible (UNIT_FL_INVISIBLE) or ch has CHAR_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.

See also