Difference between revisions of "Manual:DIL Manual/addaff()"
(XML import) |
(checked against the compiler and the interpreter; example compiles) |
||
| Line 1: | Line 1: | ||
| − | + | = addaff() = | |
| − | addaff ( u : unitptr, id : integer, tif_first : integer, tif_tick : integer, | + | '''Procedure.''' Adds an affect to a unit. |
| − | + | ||
| − | + | addaff(u : unitptr, id : integer, duration : integer, beat : integer, | |
| − | + | data0 : integer, data1 : integer, data2 : integer, | |
| − | + | tif_first : integer, tif_tick : integer, tif_last : integer, | |
| − | + | apf : integer) | |
| − | + | ||
| − | + | An affect is a timed change to a unit: blindness, a raised strength, a slowed character. It has an id that [[Manual:DIL Manual/isaff()|isaff()]] and [[Manual:DIL Manual/subaff()|subaff()]] look for, an apply function (<code>APF_</code>) that makes the change and undoes it at the end, and up to three tick functions (<code>TIF_</code>, in vme.h) that run when it starts, at every beat, and when it ends; most of them send the messages. | |
| − | + | ||
| − | + | When added, the apply function is run, then <code>tif_first</code>. Every <code>beat</code> pulses <code>tif_tick</code> runs and <code>duration</code> goes down by one. At the beat after it has reached 0, the change is undone and <code>tif_last</code> runs. | |
| − | + | ||
| + | Only a program started in a zone with access level 0 (the fourth column of <code>vme/etc/zonelist</code>) can add affects. What counts is the zone of the program's first template, the one that was <code>dilcopy</code>'d or run as a command, not the zone of the template that calls <code>addaff()</code>. Elsewhere the zone log gets "attempt to violate system access security (ada)" and the program stops. | ||
| + | |||
| + | == Parameters == | ||
| + | {| class="wikitable" | ||
| + | ! Name !! Type !! Meaning | ||
| + | |- | ||
| + | | u || unitptr || A character or room for an id from 1 to 4096; an object for an id from 1 to 4096 or from -4096 to -1. | ||
| + | |- | ||
| + | | id || integer || The affect id: an <code>ID_</code> constant from vme.h or values.h. | ||
| + | |- | ||
| + | | duration || integer || How many beats it lasts. -1 never runs out. | ||
| + | |- | ||
| + | | beat || integer || Pulses between ticks: <code>WAIT_SEC * 30</code> is 30 seconds. | ||
| + | |- | ||
| + | | data0, data1, data2 || integer || Data for the apply and tick functions (see below). | ||
| + | |- | ||
| + | | tif_first, tif_tick, tif_last || integer || <code>TIF_</code> functions to run at the start, at each beat and at the end, or <code>TIF_NONE</code>. | ||
| + | |- | ||
| + | | apf || integer || The <code>APF_</code> apply function, or <code>APF_NONE</code>. | ||
| + | |} | ||
| + | |||
| + | The apply functions, from vme.h, and the data they use: | ||
| + | {| class="wikitable" | ||
| + | ! apf !! data0 !! data1 !! Works on | ||
| + | |- | ||
| + | | APF_ABILITY || <code>ABIL_</code> ability || amount added || characters only | ||
| + | |- | ||
| + | | APF_SPELL_ADJ || spell number || amount added || characters | ||
| + | |- | ||
| + | | APF_SKILL_ADJ || skill number || amount added || players | ||
| + | |- | ||
| + | | APF_WEAPON_ADJ || weapon number || amount added || characters | ||
| + | |- | ||
| + | | APF_MOD_CHAR_FLAGS || <code>CHAR_</code> flags set || || characters only | ||
| + | |- | ||
| + | | APF_MOD_UNIT_FLAGS || <code>UNIT_FL_</code> flags set || || all units | ||
| + | |- | ||
| + | | APF_MOD_OBJ_FLAGS || <code>OBJ_</code> flags set || || objects only | ||
| + | |- | ||
| + | | APF_LIGHT_DARK || light sources added (negative for dark) || || all units | ||
| + | |- | ||
| + | | APF_NATURAL_ARMOUR || <code>ARM_</code> armour type || (kept by the game) || characters | ||
| + | |- | ||
| + | | APF_SPEED || speed change, -8 to 8 || || characters | ||
| + | |} | ||
| + | |||
| + | == Notes == | ||
| + | * An id outside the ranges above, or a <code>TIF_</code> or <code>APF_</code> value outside <code>TIF_NONE</code>..<code>TIF_MAX</code> or <code>APF_NONE</code>..<code>APF_MAX</code>, adds nothing; the zone log gets "addaffect parameters OOB". | ||
| + | * It doesn't replace an affect with the same id: the unit gets a second one. Spells test with [[Manual:DIL Manual/isaff()|isaff()]] or remove the old one with [[Manual:DIL Manual/subaff()|subaff()]] first. | ||
| + | * "characters only" and "objects only" in the table are not checked: <code>APF_ABILITY</code> or <code>APF_MOD_CHAR_FLAGS</code> on a room or an object, or <code>APF_MOD_OBJ_FLAGS</code> on anything else, can crash the server. | ||
| + | * The ability, skill, spell and weapon functions refuse when the character's current value is below 1; the affect is then dropped at once. | ||
| + | * With a <code>beat</code> of 0 or less the affect never ticks and never runs out: only <code>subaff()</code> or the unit's end removes it. | ||
| + | * A negative id on an object is a transfer affect: it does nothing on the object, but while the object is worn the wearer has the same affect with the positive id (<code>ID_TRANSFER_STR</code>, which is <code>-ID_RAISE_STR</code>, gives the wearer <code>ID_RAISE_STR</code>), removed again when it is taken off. | ||
| + | * A player's affects don't tick while the player is link-dead. | ||
| + | * Nothing happens when the unit variable is null. | ||
| + | |||
| + | == Example == | ||
| + | <pre> | ||
| + | dilbegin mire(tgt : unitptr, hm : integer); | ||
| + | code | ||
| + | { | ||
| + | if (isaff(tgt, ID_MIRE)) | ||
| + | subaff(tgt, ID_MIRE); | ||
| + | |||
| + | addaff(tgt, ID_MIRE, 1 + hm / 25, WAIT_SEC * 15, | ||
| + | -4, 0, 0, TIF_SPEED_WORSE, TIF_NONE, TIF_SPEED_BETTER, | ||
| + | APF_SPEED); | ||
| + | } | ||
| + | dilend | ||
| + | </pre> | ||
| + | Slows a character down by 4 for <code>1 + hm / 25</code> beats of 15 seconds, as the mire spell in spells.zon does. It only works in a program started in a zone with access level 0, as spells.zon is. | ||
| + | |||
| + | == See also == | ||
| + | * [[Manual:DIL Manual/subaff()|subaff()]] | ||
| + | * [[Manual:DIL Manual/isaff()|isaff()]] | ||
| + | * [[Manual:DIL Manual/getaffects()|getaffects()]] | ||
| + | * [[Manual:DIL Manual/access|access]] | ||
Latest revision as of 23:16, 14 November 2026
addaff()
Procedure. Adds an affect to a unit.
addaff(u : unitptr, id : integer, duration : integer, beat : integer,
data0 : integer, data1 : integer, data2 : integer,
tif_first : integer, tif_tick : integer, tif_last : integer,
apf : integer)
An affect is a timed change to a unit: blindness, a raised strength, a slowed character. It has an id that isaff() and subaff() look for, an apply function (APF_) that makes the change and undoes it at the end, and up to three tick functions (TIF_, in vme.h) that run when it starts, at every beat, and when it ends; most of them send the messages.
When added, the apply function is run, then tif_first. Every beat pulses tif_tick runs and duration goes down by one. At the beat after it has reached 0, the change is undone and tif_last runs.
Only a program started in a zone with access level 0 (the fourth column of vme/etc/zonelist) can add affects. What counts is the zone of the program's first template, the one that was dilcopy'd or run as a command, not the zone of the template that calls addaff(). Elsewhere the zone log gets "attempt to violate system access security (ada)" and the program stops.
Parameters
| Name | Type | Meaning |
|---|---|---|
| u | unitptr | A character or room for an id from 1 to 4096; an object for an id from 1 to 4096 or from -4096 to -1. |
| id | integer | The affect id: an ID_ constant from vme.h or values.h.
|
| duration | integer | How many beats it lasts. -1 never runs out. |
| beat | integer | Pulses between ticks: WAIT_SEC * 30 is 30 seconds.
|
| data0, data1, data2 | integer | Data for the apply and tick functions (see below). |
| tif_first, tif_tick, tif_last | integer | TIF_ functions to run at the start, at each beat and at the end, or TIF_NONE.
|
| apf | integer | The APF_ apply function, or APF_NONE.
|
The apply functions, from vme.h, and the data they use:
| apf | data0 | data1 | Works on |
|---|---|---|---|
| APF_ABILITY | ABIL_ ability |
amount added | characters only |
| APF_SPELL_ADJ | spell number | amount added | characters |
| APF_SKILL_ADJ | skill number | amount added | players |
| APF_WEAPON_ADJ | weapon number | amount added | characters |
| APF_MOD_CHAR_FLAGS | CHAR_ flags set |
characters only | |
| APF_MOD_UNIT_FLAGS | UNIT_FL_ flags set |
all units | |
| APF_MOD_OBJ_FLAGS | OBJ_ flags set |
objects only | |
| APF_LIGHT_DARK | light sources added (negative for dark) | all units | |
| APF_NATURAL_ARMOUR | ARM_ armour type |
(kept by the game) | characters |
| APF_SPEED | speed change, -8 to 8 | characters |
Notes
- An id outside the ranges above, or a
TIF_orAPF_value outsideTIF_NONE..TIF_MAXorAPF_NONE..APF_MAX, adds nothing; the zone log gets "addaffect parameters OOB". - It doesn't replace an affect with the same id: the unit gets a second one. Spells test with isaff() or remove the old one with subaff() first.
- "characters only" and "objects only" in the table are not checked:
APF_ABILITYorAPF_MOD_CHAR_FLAGSon a room or an object, orAPF_MOD_OBJ_FLAGSon anything else, can crash the server. - The ability, skill, spell and weapon functions refuse when the character's current value is below 1; the affect is then dropped at once.
- With a
beatof 0 or less the affect never ticks and never runs out: onlysubaff()or the unit's end removes it. - A negative id on an object is a transfer affect: it does nothing on the object, but while the object is worn the wearer has the same affect with the positive id (
ID_TRANSFER_STR, which is-ID_RAISE_STR, gives the wearerID_RAISE_STR), removed again when it is taken off. - A player's affects don't tick while the player is link-dead.
- Nothing happens when the unit variable is null.
Example
dilbegin mire(tgt : unitptr, hm : integer);
code
{
if (isaff(tgt, ID_MIRE))
subaff(tgt, ID_MIRE);
addaff(tgt, ID_MIRE, 1 + hm / 25, WAIT_SEC * 15,
-4, 0, 0, TIF_SPEED_WORSE, TIF_NONE, TIF_SPEED_BETTER,
APF_SPEED);
}
dilend
Slows a character down by 4 for 1 + hm / 25 beats of 15 seconds, as the mire spell in spells.zon does. It only works in a program started in a zone with access level 0, as spells.zon is.