Difference between revisions of "Manual:DIL Manual/dilfind()"

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="bfdf"></span>
+
= dilfind() =
−
integer dilfind( s : string, u : unitptr )
+
'''Function''' (integer). Tells whether a unit runs a DIL program from a given template.
−
    s : name of dil template to find.
 
−
    u : unit to find program in.
 
−
    return: Whether a program using a template with same name as in 's'
 
−
            attached to unit 'u' was found.
 
  
−
  ---~---~---~---~---~---~---~---~---
+
  dilfind(tmpl : string, u : unitptr) : integer
−
<span id="bfdf"></span>
 
−
integer dilfind( s : string, u : unitptr )
 
−
    s : name of dil template to find.
 
−
    u : unit to find program in.
 
−
    return: Whether a program using a template with same name as in 's'
 
−
            attached to unit 'u' was found.
 
  
−
---~---~---~---~---~---~---~---~---
+
Looks through the programs on <code>u</code> for one that was started from the template <code>tmpl</code> and hasn't ended. Use it to avoid putting the same program on a unit twice, or to see whether a spell or a curse is still at work.
 +
 
 +
== Parameters ==
 +
{| class="wikitable"
 +
! Name !! Type !! Meaning
 +
|-
 +
| tmpl || string || The template's name with its zone, <code>"name@zone"</code>. Without the <code>@zone</code> nothing is found.
 +
|-
 +
| u || unitptr || The unit to look at.
 +
|}
 +
 
 +
== Returns ==
 +
TRUE when <code>u</code> has such a program, FALSE when not (or the template doesn't exist). The call fails when <code>u</code> is null; in an <code>if</code>, a failed call counts as false.
 +
 
 +
== Notes ==
 +
* It checks the template each program was started from, not one the program is busy in after calling it.
 +
* The name must match the template, not the unit: <code>dilfind("guard@midgaard", u)</code> asks about a program called guard, not about an NPC.
 +
 
 +
== Example ==
 +
<pre>
 +
dilbegin bleed_once(u : unitptr);
 +
code
 +
{
 +
  if (not dilfind("bleeding@ex", u))
 +
      dilcopy("bleeding@ex", u);
 +
  quit;
 +
}
 +
dilend
 +
 
 +
dilbegin bleeding();
 +
code
 +
{
 +
  heartbeat := PULSE_SEC * 10;
 +
  :loop:
 +
  wait(SFB_TICK, TRUE);
 +
  act("You bleed.", A_ALWAYS, self, null, null, TO_CHAR);
 +
  goto loop;
 +
}
 +
dilend
 +
</pre>
 +
Puts a bleeding program on a character unless it already bleeds, as barbarian.zon does with its blood poison. The example zone is called <code>ex</code>.
 +
 
 +
== See also ==
 +
* [[Manual:DIL Manual/dildestroy()|dildestroy()]]
 +
* [[Manual:DIL Manual/dilcopy()|dilcopy()]]
 +
* [[Manual:DIL Manual/hasfunc|hasfunc]]

Revision as of 23:18, 14 November 2026

dilfind()

Function (integer). Tells whether a unit runs a DIL program from a given template.

dilfind(tmpl : string, u : unitptr) : integer

Looks through the programs on u for one that was started from the template tmpl and hasn't ended. Use it to avoid putting the same program on a unit twice, or to see whether a spell or a curse is still at work.

Parameters

Name Type Meaning
tmpl string The template's name with its zone, "name@zone". Without the @zone nothing is found.
u unitptr The unit to look at.

Returns

TRUE when u has such a program, FALSE when not (or the template doesn't exist). The call fails when u is null; in an if, a failed call counts as false.

Notes

  • It checks the template each program was started from, not one the program is busy in after calling it.
  • The name must match the template, not the unit: dilfind("guard@midgaard", u) asks about a program called guard, not about an NPC.

Example

dilbegin bleed_once(u : unitptr);
code
{
   if (not dilfind("bleeding@ex", u))
      dilcopy("bleeding@ex", u);
   quit;
}
dilend

dilbegin bleeding();
code
{
   heartbeat := PULSE_SEC * 10;
   :loop:
   wait(SFB_TICK, TRUE);
   act("You bleed.", A_ALWAYS, self, null, null, TO_CHAR);
   goto loop;
}
dilend

Puts a bleeding program on a character unless it already bleeds, as barbarian.zon does with its blood poison. The example zone is called ex.

See also