Manual:DIL Manual/addaff()

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

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_ or APF_ value outside TIF_NONE..TIF_MAX or APF_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_ABILITY or APF_MOD_CHAR_FLAGS on a room or an object, or APF_MOD_OBJ_FLAGS 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 beat of 0 or less the affect never ticks and never runs out: only subaff() 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 wearer ID_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.

See also