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

From DikuMUD Wiki
Jump to navigation Jump to search
(Created page with "= stringlist getaffects(u : unitptr) = u : The unit to scan for affects result : Returns stringlist of affects as described below. '''Example''': sl := getaffects(sel...")
 
(checked against the compiler and the interpreter; example compiles)
 
Line 1: Line 1:
−
= stringlist getaffects(u : unitptr) =
+
= getaffects() =
 +
'''Function''' (stringlist). Lists the affects on a unit, one string of numbers each.
  
−
  u : The unit to scan for affects
+
getaffects(u : unitptr)
−
  result : Returns stringlist of affects as described below.
 
  
−
'''Example''':
+
For each affect on <code>u</code> (spells, poison, transfers of abilities and skills from
 +
equipment...), the list gets one string of six numbers separated by commas:
  
−
  sl := getaffects(self);
+
id,apf,data0,data1,data2,duration
  
−
For each affect on a unit, two strings are added to the stringlist.
+
* <code>id</code>: the affect's <code>ID_</code> value (<code>vme/include/vme.h</code>).
−
The first string is the description of what gets modified, e.g. an
+
  Transfer affects, the ones equipment gives while worn, have it negative.
−
ability. The second string contains the three data value data0,data1
+
* <code>apf</code>: the <code>APF_</code> function that applies it (<code>vme.h</code>), such as
−
and data2, as well as the duration left.
+
  <code>APF_ABILITY</code> (0).
 +
* <code>data0</code> to <code>data2</code>: the affect's data, as given to
 +
  [[Manual:DIL Manual/addaff()|addaff()]]; for an ability transfer, <code>data0</code> is the
 +
  ability and <code>data1</code> the amount.
 +
* <code>duration</code>: the beats left (see addaff()), or -1 for an affect without end.
  
−
Could look like this:
+
Take a string apart with [[Manual:DIL Manual/split()|split()]] and
 +
[[Manual:DIL Manual/atoi()|atoi()]].
  
−
  {"Ability Adjustment", "6,6,0,-1",
+
== Parameters ==
−
  "Weapon adjustment", "12,14,0,-1"}
+
{| class="wikitable"
 +
! Name !! Type !! Meaning
 +
|-
 +
| u || unitptr || Any unit: a character, an object or a room.
 +
|}
  
−
Use the [[Manual:DIL_Manual/split()|split()]] command to separate the numerical values.
+
== Returns ==
 +
Stringlist: one entry per affect, in the order the unit holds them; empty when there are none.
 +
It fails when <code>u</code> 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, [[Manual:DIL Manual/isaff()|isaff()]] is simpler.
  
−
See also:
+
== Example ==
 +
<pre>
 +
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
 +
</pre>
 +
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.
  
−
  > [[Manual:DIL_Manual/isaff()|isaff()]]
+
== See also ==
−
  > [[Manual:DIL_Manual/addaff()|addaff()]]
+
* [[Manual:DIL Manual/isaff()|isaff()]]
−
  > [[Manual:DIL_Manual/getaffects()|getaffects()]]
+
* [[Manual:DIL Manual/addaff()|addaff()]]
 +
* [[Manual:DIL Manual/subaff()|subaff()]]
 +
* [[Manual:DIL Manual/split()|split()]]

Latest revision as of 23:20, 14 November 2026

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