Manual:DIL Manual/getaffects()

From DikuMUD Wiki
< Manual:DIL Manual
Revision as of 23:20, 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

getaffects()

Function (stringlist). Lists the affects on a unit, one string of numbers each.

getaffects(u : unitptr)

For each affect on u (spells, poison, transfers of abilities and skills from equipment...), the list gets one string of six numbers separated by commas:

id,apf,data0,data1,data2,duration
  • id: the affect's ID_ value (vme/include/vme.h).
 Transfer affects, the ones equipment gives while worn, have it negative.
  • apf: the APF_ function that applies it (vme.h), such as
 APF_ABILITY (0).
  • data0 to data2: the affect's data, as given to
 addaff(); for an ability transfer, data0 is the
 ability and data1 the amount.
  • duration: the beats left (see addaff()), or -1 for an affect without end.

Take a string apart with split() and atoi().

Parameters

Name Type Meaning
u unitptr Any unit: a character, an object or a room.

Returns

Stringlist: one entry per affect, in the order the unit holds them; empty when there are none. It fails when u is null.

Notes

  • The old manual described two strings per affect with a text description first. That is no
 longer so: one string each, numbers only.
  • To test for one affect, isaff() is simpler.

Example

dilbegin show_affects(pc : unitptr, u : unitptr);
var
   sl : stringlist;
   parts : stringlist;
   i : integer;
   n : integer;
code
{
   sl := getaffects(u);
   n := length(sl);
   i := 0;
   while (i < n)
   {
      parts := split(sl.[i], ",");
      sendtext("Affect " + parts.[0] + ", " + parts.[5] + " beats left.<br/>", pc);
      i := i + 1;
   }
   quit;
}
dilend

Shows a player the id and time left of each affect on a unit; spells.zon's identify reads the same list to describe an item's transfers.

See also