Difference between revisions of "Manual:DIL Manual/medium"
Jump to navigation
Jump to search
(XML import) |
(checked against the compiler and the interpreter; example compiles) |
||
| Line 1: | Line 1: | ||
| − | + | = medium = | |
| − | + | '''Variable''' (unitptr, read-only). | |
| − | |||
| − | |||
| − | |||
| − | |||
| − | + | medium : unitptr | |
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | + | The unit used in the event that woke the program, when the event has one; otherwise null. What it is depends on the event: | |
| + | * SFB_DONE after <code>give</code>: the item or the coins given (<code>target</code> is the receiver). After <code>put</code>: the item put (<code>target</code> is the container). After <code>get</code>: the container it was taken from (<code>target</code> is the item). After a move: the room left (<code>target</code> is the room entered). | ||
| + | * SFB_PRE with <code>command(CMD_AUTO_DAMAGE)</code>: the weapon of the hit (randomt.zon's vorpal weapon waits for <code>medium == self</code>). | ||
| + | * SFB_CMD, SFB_MSG from sendto(), SFB_TICK: null. | ||
| + | * A send_done() or send_pre() from DIL passes its own medium. | ||
| + | |||
| + | == Notes == | ||
| + | * Like activator and target 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. | ||
| + | * It can't be assigned. | ||
| + | * Coins given arrive merged with the coins the receiver already holds; <code>power</code> is the amount given. | ||
| + | |||
| + | == Example == | ||
| + | <pre> | ||
| + | dilbegin collector(wanted : string); | ||
| + | var | ||
| + | item : unitptr; | ||
| + | pc : unitptr; | ||
| + | code | ||
| + | { | ||
| + | :start: | ||
| + | wait(SFB_DONE, command("give") and (target == self) and | ||
| + | (activator.type == UNIT_ST_PC)); | ||
| + | item := medium; | ||
| + | pc := activator; | ||
| + | if (item.symname != wanted) | ||
| + | { | ||
| + | act("$1n doesn't want $2n.", A_ALWAYS, self, item, pc, TO_VICT); | ||
| + | goto start; | ||
| + | } | ||
| + | act("$1n thanks you for $2n.", A_ALWAYS, self, item, pc, TO_VICT); | ||
| + | destroy(item); | ||
| + | goto start; | ||
| + | } | ||
| + | dilend | ||
| + | </pre> | ||
| + | An NPC (<code>dilcopy collector@zone("gem@zone");</code>) that takes one kind of item from players and destroys it, and says so when given anything else (the item then stays in its inventory). | ||
| + | |||
| + | == See also == | ||
| + | * [[Manual:DIL Manual/activator|activator]] | ||
| + | * [[Manual:DIL Manual/target|target]] | ||
| + | * [[Manual:DIL Manual/power|power]] | ||
| + | * [[Manual:DIL Manual/send done()|send done()]] | ||
| + | * [[Manual:DIL Manual/SFB DONE|SFB DONE]] | ||
Latest revision as of 23:18, 14 November 2026
Contents
medium
Variable (unitptr, read-only).
medium : unitptr
The unit used in the event that woke the program, when the event has one; otherwise null. What it is depends on the event:
- SFB_DONE after
give: the item or the coins given (targetis the receiver). Afterput: the item put (targetis the container). Afterget: the container it was taken from (targetis the item). After a move: the room left (targetis the room entered). - SFB_PRE with
command(CMD_AUTO_DAMAGE): the weapon of the hit (randomt.zon's vorpal weapon waits formedium == self). - SFB_CMD, SFB_MSG from sendto(), SFB_TICK: null.
- A send_done() or send_pre() from DIL passes its own medium.
Notes
- Like activator and target 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.
- It can't be assigned.
- Coins given arrive merged with the coins the receiver already holds;
poweris the amount given.
Example
dilbegin collector(wanted : string);
var
item : unitptr;
pc : unitptr;
code
{
:start:
wait(SFB_DONE, command("give") and (target == self) and
(activator.type == UNIT_ST_PC));
item := medium;
pc := activator;
if (item.symname != wanted)
{
act("$1n doesn't want $2n.", A_ALWAYS, self, item, pc, TO_VICT);
goto start;
}
act("$1n thanks you for $2n.", A_ALWAYS, self, item, pc, TO_VICT);
destroy(item);
goto start;
}
dilend
An NPC (dilcopy collector@zone("gem@zone");) that takes one kind of item from players and destroys it, and says so when given anything else (the item then stays in its inventory).