Difference between revisions of "Manual:DIL Manual/getaffects()"
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: | ||
| − | = | + | = getaffects() = |
| + | '''Function''' (stringlist). Lists the affects on a unit, one string of numbers each. | ||
| − | + | getaffects(u : unitptr) | |
| − | |||
| − | + | 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: | ||
| − | + | id,apf,data0,data1,data2,duration | |
| − | + | * <code>id</code>: the affect's <code>ID_</code> value (<code>vme/include/vme.h</code>). | |
| − | + | Transfer affects, the ones equipment gives while worn, have it negative. | |
| − | + | * <code>apf</code>: the <code>APF_</code> function that applies it (<code>vme.h</code>), such as | |
| − | and | + | <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. | ||
| − | + | Take a string apart with [[Manual:DIL Manual/split()|split()]] and | |
| + | [[Manual:DIL Manual/atoi()|atoi()]]. | ||
| − | + | == Parameters == | |
| − | + | {| class="wikitable" | |
| + | ! 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 <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. | ||
| − | + | == 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. | ||
| − | + | == See also == | |
| − | + | * [[Manual:DIL Manual/isaff()|isaff()]] | |
| − | + | * [[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'sID_value (vme/include/vme.h).
Transfer affects, the ones equipment gives while worn, have it negative.
apf: theAPF_function that applies it (vme.h), such as
APF_ABILITY (0).
data0todata2: the affect's data, as given to
addaff(); for an ability transfer,data0is the ability anddata1the 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.