Difference between revisions of "Manual:DIL Manual/target"

From DikuMUD Wiki
Jump to navigation Jump to search
(XML import)
(checked against the compiler and the interpreter; example compiles)
 
Line 1: Line 1:
−
<span id="targ"></span>
+
= target =
−
'target'
+
'''Variable''' (unitptr, read-only).
−
    This variable is a unit pointer to the unit which is the target of the
 
−
    current operation. For 'done' messages this could for example be the
 
−
    destination in a give command.
 
−
    See description of messages for more information.
 
  
−
  ---~---~---~---~---~---~---~---~---
+
  target : unitptr
−
<span id="targ"></span>
 
−
'target'
 
−
    This variable is a unit pointer to the unit which is the target of the
 
−
    current operation. For 'done' messages this could for example be the
 
−
    destination in a give command.
 
−
    See description of messages for more information.
 
  
−
---~---~---~---~---~---~---~---~---
+
The unit an action in the event was aimed at, when the event has one; otherwise null:
 +
* SFB_DONE after <code>give</code>: the receiver. After <code>get</code> and <code>drop</code>: the item. After <code>put</code>: the container. After a move: the room entered.
 +
* SFB_PRE with <code>command(CMD_AUTO_DAMAGE)</code>: the victim of the hit. SFB_PRE for a spell: the spell's target.
 +
* SFB_CMD, SFB_MSG from sendto(), SFB_TICK: null.
 +
* A send_done() or send_pre() from DIL passes its own target.
 +
 
 +
== Notes ==
 +
* The usual give handler waits for <code>command("give") and (target == self)</code>; <code>medium</code> is then the item, already in <code>self</code>'s inventory.
 +
* It belongs to the current event: copy it into a variable right after the wait, and secure() the variable if it must outlast a wait or pause.
 +
* <code>target</code> is a reserved word, so no variable can be called <code>target</code>; use <code>tgt</code> or <code>vict</code>.
 +
 
 +
== Example ==
 +
<pre>
 +
dilbegin altar_watch();
 +
code
 +
{
 +
  :start:
 +
  wait(SFB_DONE, command("get") and (medium == self));
 +
  act("The altar glows as $1n takes $2n from it.",
 +
      A_SOMEONE, activator, target, null, TO_ROOM);
 +
  act("The altar glows as you take $2n from it.",
 +
      A_SOMEONE, activator, target, null, TO_CHAR);
 +
  goto start;
 +
}
 +
dilend
 +
</pre>
 +
An altar (an object with this program) that glows when someone takes something from it: in a <code>get</code>, <code>medium</code> is the container and <code>target</code> the item taken.
 +
 
 +
== See also ==
 +
* [[Manual:DIL Manual/activator|activator]]
 +
* [[Manual:DIL Manual/medium|medium]]
 +
* [[Manual:DIL Manual/send done()|send done()]]
 +
* [[Manual:DIL Manual/SFB DONE|SFB DONE]]
 +
* [[Manual:DIL Manual/SFB PRE|SFB PRE]]

Latest revision as of 23:18, 14 November 2026

target

Variable (unitptr, read-only).

target : unitptr

The unit an action in the event was aimed at, when the event has one; otherwise null:

  • SFB_DONE after give: the receiver. After get and drop: the item. After put: the container. After a move: the room entered.
  • SFB_PRE with command(CMD_AUTO_DAMAGE): the victim of the hit. SFB_PRE for a spell: the spell's target.
  • SFB_CMD, SFB_MSG from sendto(), SFB_TICK: null.
  • A send_done() or send_pre() from DIL passes its own target.

Notes

  • The usual give handler waits for command("give") and (target == self); medium is then the item, already in self's inventory.
  • It belongs to the current event: copy it into a variable right after the wait, and secure() the variable if it must outlast a wait or pause.
  • target is a reserved word, so no variable can be called target; use tgt or vict.

Example

dilbegin altar_watch();
code
{
   :start:
   wait(SFB_DONE, command("get") and (medium == self));
   act("The altar glows as $1n takes $2n from it.",
       A_SOMEONE, activator, target, null, TO_ROOM);
   act("The altar glows as you take $2n from it.",
       A_SOMEONE, activator, target, null, TO_CHAR);
   goto start;
}
dilend

An altar (an object with this program) that glows when someone takes something from it: in a get, medium is the container and target the item taken.

See also