Difference between revisions of "Manual:DIL Manual/isaff()"

From DikuMUD Wiki
Jump to navigation Jump to search
(checked against the compiler and the interpreter; example compiles)
 
(2 intermediate revisions by 2 users not shown)
Line 1: Line 1:
−
= integer isaff ( u : unitptr , i : integer ) =
+
= isaff() =
 +
'''Function''' (integer). Tells whether a unit carries an affect with a given id.
  
−
  u : A unit to be examined.
+
isaff(u : unitptr, id : integer)
−
  i : An id of an affect, see ID_* in values.h and/or vme.h
 
−
  result: TRUE, if unit 'u' is affected by affect id 'i'
 
  
−
'''Examples:'''
+
Looks through the affects on <code>u</code> (spells, poisons, curses and other timed effects added with <code>addaff()</code>) and is TRUE if one of them has the id <code>id</code>. It works on any unit: characters, objects and rooms.
  
−
  if (isaff(self, ID_BLIND_CHAR))
+
== Parameters ==
−
    sendtext("You're blinded", self);
+
{| class="wikitable"
 +
! Name !! Type !! Meaning
 +
|-
 +
| u || unitptr || The unit to look at.
 +
|-
 +
| id || integer || The affect id, an <code>ID_*</code> constant.
 +
|}
  
−
This command scans the unit 'u' for any affect matching the id 'i'
+
== Returns ==
−
and returns TRUE if one is found.
+
Integer: 1 if <code>u</code> has at least one affect with that id, otherwise 0. If <code>u</code> is null, the result fails: false in an <code>if</code>, so <code>not isaff(null, ...)</code> is true.
  
−
See also:
+
== Notes ==
−
  > [[Manual:DIL_Manual/subaff()|subaff()]]
+
* The <code>ID_*</code> constants are in <code>vme/include/vme.h</code> (<code>ID_CORPSE</code>, <code>ID_BLIND_CHAR</code>, <code>ID_INVISIBILITY</code>, <code>ID_CURSE</code>, ...) and <code>vme/include/values.h</code>. There is no <code>ID_BLIND</code>.
−
  > [[Manual:DIL_Manual/addaff()|addaff()]]
+
* It only tests for the affect, not its strength or time left. <code>getaffects()</code> lists a unit's affects.
−
  > [[Manual:DIL_Manual/getaffects()|getaffects()]]
+
* An affect isn't the same as a flag: blindness, for instance, can come from an affect (<code>ID_BLIND_CHAR</code>) or from the flag <code>CHAR_BLIND</code> in <code>charflags</code>, so baselook.zon tests both.
 +
 
 +
== Example ==
 +
<pre>
 +
dilbegin integer is_blind(u : unitptr);
 +
code
 +
{
 +
  if (u == null)
 +
      return (FALSE);
 +
  return (isaff(u, ID_BLIND_CHAR) or isset(u.charflags, CHAR_BLIND));
 +
}
 +
dilend
 +
</pre>
 +
Tells whether a character is blind, from an affect or from the flag, as baselook.zon does.
 +
 
 +
== See also ==
 +
* [[Manual:DIL Manual/addaff()|addaff()]]
 +
* [[Manual:DIL Manual/subaff()|subaff()]]
 +
* [[Manual:DIL Manual/getaffects()|getaffects()]]
 +
* [[Manual:DIL Manual/isset()|isset()]]

Latest revision as of 23:14, 14 November 2026

isaff()

Function (integer). Tells whether a unit carries an affect with a given id.

isaff(u : unitptr, id : integer)

Looks through the affects on u (spells, poisons, curses and other timed effects added with addaff()) and is TRUE if one of them has the id id. It works on any unit: characters, objects and rooms.

Parameters

Name Type Meaning
u unitptr The unit to look at.
id integer The affect id, an ID_* constant.

Returns

Integer: 1 if u has at least one affect with that id, otherwise 0. If u is null, the result fails: false in an if, so not isaff(null, ...) is true.

Notes

  • The ID_* constants are in vme/include/vme.h (ID_CORPSE, ID_BLIND_CHAR, ID_INVISIBILITY, ID_CURSE, ...) and vme/include/values.h. There is no ID_BLIND.
  • It only tests for the affect, not its strength or time left. getaffects() lists a unit's affects.
  • An affect isn't the same as a flag: blindness, for instance, can come from an affect (ID_BLIND_CHAR) or from the flag CHAR_BLIND in charflags, so baselook.zon tests both.

Example

dilbegin integer is_blind(u : unitptr);
code
{
   if (u == null)
      return (FALSE);
   return (isaff(u, ID_BLIND_CHAR) or isset(u.charflags, CHAR_BLIND));
}
dilend

Tells whether a character is blind, from an affect or from the flag, as baselook.zon does.

See also