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

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="bpact"></span>
+
= act() =
 +
'''Procedure.''' Shows a message to the characters around someone, worded for each of them.
  
−
  The purpose of act is to send a message to a number of players '''present''' in
+
  act(text : string, show : integer, char : unitptr, medium : unitptr or string,
−
a room.  The room is defined as the room containing the afore mentioned
+
    victim : unitptr or string, to : integer)
−
character (provided he himself is in the room, i.e. not in a closed
 
−
container.)
 
  
 +
Sends <code>text</code> to the characters that <code>to</code> picks, around <code>char</code>. Codes such as <code>$1n</code> in the text are filled in for each reader: a name, or "someone" when they can't see who it is, "he" or "she", and so on. The usual way to tell what happens is one act for the one who does it (<code>TO_CHAR</code>), one for the victim (<code>TO_VICT</code>) and one for the others (<code>TO_NOTVICT</code> or <code>TO_REST</code>).
  
−
---~---~---~---~---~---~---~---~---
+
== Parameters ==
 +
{| class="wikitable"
 +
! Name !! Type !! Meaning
 +
|-
 +
| text || string || The message, with $-codes (below). No <code>&lt;br/&gt;</code> at the end: act adds it.
 +
|-
 +
| show || integer || <code>A_SOMEONE</code>, <code>A_HIDEINV</code>, <code>A_ALWAYS</code> or <code>A_RAW</code> (below).
 +
|-
 +
| char || unitptr || The one who acts: <code>$1</code>, and the place the message goes out from.
 +
|-
 +
| medium || unitptr or string || <code>$2</code>: a unit, a string for <code>$2t</code>, or <code>null</code>.
 +
|-
 +
| victim || unitptr or string || <code>$3</code>: a unit, a string for <code>$3t</code>, or <code>null</code>.
 +
|-
 +
| to || integer || Who gets it: a <code>TO_</code> constant (below).
 +
|}
  
−
'''Syntax:'''
+
The constants are in <code>vme.h</code>.
  
−
act(message, visibility, char, medium, victim, to_whom);
+
{| class="wikitable"
 +
! to !! Who gets it
 +
|-
 +
| TO_CHAR || <code>char</code> only.
 +
|-
 +
| TO_VICT || <code>victim</code> only.
 +
|-
 +
| TO_ROOM || Everyone around <code>char</code>, but not <code>char</code>.
 +
|-
 +
| TO_NOTVICT || Everyone around <code>char</code>, but not <code>char</code> and not <code>victim</code>.
 +
|-
 +
| TO_ALL || Everyone around <code>char</code>, <code>char</code> too.
 +
|-
 +
| TO_REST || As <code>TO_ROOM</code>, and not those inside <code>char</code> either.
 +
|}
 +
"Around <code>char</code>" is the room <code>char</code> is in, including those inside transparent units there; when <code>char</code> is inside a transparent unit (a wagon, a boat), also the room around that unit.
  
 +
{| class="wikitable"
 +
! show !! Meaning
 +
|-
 +
| A_SOMEONE || Not shown to those asleep. A unit a reader can't see is "someone" or "something".
 +
|-
 +
| A_HIDEINV || Not shown to those who can't see <code>char</code>, nor to those asleep. For things that are only seen, like a smile.
 +
|-
 +
| A_ALWAYS || Shown also to those asleep. A unit a reader can't see is "someone" or "something".
 +
|-
 +
| A_RAW || Shown to everyone, and <code>$n</code> and <code>$N</code> give the real names even of units the reader can't see.
 +
|}
  
−
<!--TERM--> '''message'''
+
A code is <code>$</code>, a digit for the argument (1 <code>char</code>, 2 <code>medium</code>, 3 <code>victim</code>) and a letter:
−
<!--DEFINITION-->         - is a string that will be shown to other mobiles when the act is executed. To refer to the following arguments use the [[#formatters|formatters]] listed below.
+
{| class="wikitable"
−
<!--TERM--> '''visibility'''
+
! Code !! Becomes
−
<!--DEFINITION-->         - is an integer that defines what happens if the mobile that is about to receive the message can't see the activator.
+
|-
−
<!--TERM-->         <b><!--CODE-->A_SOMEONE</b><!--ENDCODE-->
+
| $1n || A player's name, or the title of an NPC or object ("the town guard"); "someone" or "something" to those who can't see it.
−
<!--DEFINITION-->                If the receiver cannot see char, replace any reference to char with <i>someone</i>.
+
|-
−
<!--TERM-->        <b><!--CODE-->A_HIDEINV</b><!--ENDCODE-->
+
| $1N || The unit's first name ("guard"); "someone" or "something" to those who can't see it.
−
<!--DEFINITION-->                If the receiver cannot see char, don't send the message at all. Use this when missing vision should eliminate the perception of the action the message represent. One instance where it is used is in smile. You would need a ridiculously sensitive ear to hear, let alone percept that someone's smiling if you can't see them. Do not use it if 'sound' is inherent in the message.
+
|-
−
<!--TERM-->        <b><!--CODE-->A_ALWAYS</b><!--ENDCODE-->
+
| $1e, $1m, $1s || he/she/it, him/her/it, his/her/its.
−
<!--DEFINITION-->                Works exactly like <i><!--CODE-->A_SOMEONE</i><!--ENDCODE-->, except that the receiver will see the message even when sleeping.
+
|-
−
<!--TERM--> '''char'''
+
| $1p || The character's position (standing, sleeping, ...); "lying" for anything else.
−
<!--DEFINITION-->          - is a unitptr, and the most important argument in the act. If this is not valid the act will never show, leaving mobiles without the message.
+
|-
−
<!--TERM--> '''medium'''
+
| $1a || "a" or "an" to go before the unit's name (or before a string argument).
−
<!--DEFINITION-->          - is a unit pointer, an integer or a string. Use this at your leisure.
+
|-
−
<!--TERM--> '''victim'''
+
| $2t || The string given as that argument.
−
<!--DEFINITION-->          - is a unit pointer, an integer or a string. Certain flags in the next argument rely on the validity of victim.
+
|-
−
<!--TERM--> '''to_whom'''
+
| $$ || A single <code>$</code>.
−
<!--DEFINITION-->          - is an integer that defines who gets the message.
+
|}
−
<!--TERM-->        <b><!--CODE-->TO_ROOM</b><!--ENDCODE-->
 
−
<!--DEFINITION-->                Sends the message to the entire room, excluding 'char'.
 
−
<!--TERM-->        <b><!--CODE-->TO_VICT</b><!--ENDCODE-->
 
−
<!--DEFINITION-->                Sends to 'victim' only. 'victim' must be valid, naturally.
 
−
<!--TERM-->        <b><!--CODE-->TO_NOTVICT</b><!--ENDCODE-->
 
−
<!--DEFINITION-->                Sends the message to the entire room, excluding 'char' and 'victim'.  Perfect for bystanders in a melee.
 
−
<!--TERM-->        <b><!--CODE-->TO_CHAR</b><!--ENDCODE-->
 
−
<!--DEFINITION-->                Sends the message to 'char' and no one else.
 
−
<!--TERM-->        <b><!--CODE-->TO_ALL</b><!--ENDCODE-->
 
−
<!--DEFINITION-->                Sends the message to everybody in the room.
 
−
<!--TERM-->        <b><!--CODE-->TO_REST</b><!--ENDCODE-->
 
−
<!--DEFINITION-->                This is a bit different from the rest.  In sends the message to all other units in the local environment, excluding those inside 'char'.
 
  
−
---~---~---~---~---~---~---~---~---
+
== Notes ==
 +
* Only characters with a connection see it. NPCs, and the programs on them, never see act() text: to tell a program something, use <code>send()</code> or <code>sendto()</code>.
 +
* With <code>char</code> null, or <code>victim</code> null for <code>TO_VICT</code> and <code>TO_NOTVICT</code>, nothing is sent. A string as <code>char</code> compiles but sends nothing.
 +
* A <code>to</code> outside <code>TO_ROOM</code> ... <code>TO_REST</code> (0 to 5) sends nothing. A <code>show</code> below 10 or above 14 is logged and taken as <code>A_ALWAYS</code>.
 +
* A code whose argument is null shows "NULL", and an unknown code cuts the message there; both are logged.
 +
* The first letter is made a capital (after any HTML tags at the start).
 +
* Numbers can't be passed: give <code>itoa(n)</code> as the medium or victim and write <code>$2t</code> or <code>$3t</code>.
 +
* Used in an expression, <code>s := act(...)</code> sends nothing and gives the text as the one it is about would see it, with the <code>&lt;br/&gt;</code>, or <code>""</code> when there is nobody or they wouldn't see it; see <code>sact()</code>.
  
−
<span id="formatters"></span>
+
== Example ==
−
'''Act Formatters'''
+
<pre>
 +
dilbegin block_flee();
 +
var
 +
  pc : unitptr;
 +
code
 +
{
 +
  :start:
 +
  wait(SFB_CMD, command("flee") and (activator.type == UNIT_ST_PC));
 +
  pc := activator;
 +
  block;
 +
  act("You panic and try to flee, but something prevents you from escaping!",
 +
      A_SOMEONE, pc, null, self, TO_CHAR);
 +
  act("$1n panics and tries to flee, but can not!",
 +
      A_SOMEONE, pc, null, self, TO_REST);
 +
  goto start;
 +
}
 +
dilend
  
−
Just as the description formatters, act has its own set of formatters that
+
dilbegin hand_over(item : unitptr, pc : unitptr);
−
enable you to create generic messages that will be interpreted at run-time,
+
code
−
lessening the load on you.
+
{
 +
  act("You hand $2n to $3n.", A_SOMEONE, self, item, pc, TO_CHAR);
 +
  act("$1n hands you $2n.", A_SOMEONE, self, item, pc, TO_VICT);
 +
  act("$1n hands $2n to $3n.", A_SOMEONE, self, item, pc, TO_NOTVICT);
 +
  return;
 +
}
 +
dilend
 +
</pre>
 +
Fleeing fails where this program is, with one message for the player and one for the others (adapted from clans.zon), and the three messages of handing something over.
  
−
The format string is a normal message, containing some special characters:
+
== See also ==
−
 
+
* [[Manual:DIL Manual/sact()|sact()]]
−
<!--TERM--> '$$'
+
* [[Manual:DIL Manual/sendtext()|sendtext()]]
−
<!--DEFINITION-->        will be sent to the receiver as a single `$'
+
* [[Manual:DIL Manual/send()|send()]]
−
 
+
* [[Manual:DIL Manual/sendto()|sendto()]]
−
'$', followed by a number and an extra character.
+
* [[Manual:DIL Manual/itoa()|itoa()]]
−
  '''The numbers:'''
 
−
 
 
−
<!--TERM--> '1'
 
−
<!--DEFINITION-->          means this formatter refers to the 'char' argument.
 
−
<!--TERM--> '2'
 
−
<!--DEFINITION-->        means this formatter refers to the 'medium' argument.
 
−
<!--TERM--> '3'
 
−
<!--DEFINITION-->          means this formatter refers to the 'victim' argument.
 
−
 
 
−
    '''The characters'''
 
−
 
 
−
<!--TERM--> 'N'
 
−
<!--DEFINITION-->          the formatter will be replaced with the name of the unit, or (depending on the visibility) 'something' or 'someone'.
 
−
<!--TERM--> 'a'
 
−
<!--DEFINITION-->        'a' or 'an' depending on the name of the unit referred by the number.
 
−
<!--TERM--> 'e'
 
−
<!--DEFINITION-->        'it', 'he' or 'she' depending on the gender of the unit referred by the number.
 
−
<!--TERM--> 'm'
 
−
<!--DEFINITION-->        'it', 'him' or 'her' depending on the gender of the unit referred by the number.
 
−
<!--TERM--> 'n'
 
−
<!--DEFINITION-->          the formatter will be replaced with the title of the unit, or (depending on the visibility) 'something' or 'someone'.
 
−
<!--TERM--> 'p'
 
−
<!--DEFINITION-->        'fighting', 'standing', 'sleeping', etc., depending on the positionof the unit referred by the number.
 
−
<!--TERM--> 's'
 
−
<!--DEFINITION-->        'its', 'his' or 'her' depending on the gender of the unit referred by the number.
 
−
<!--TERM--> 't'
 
−
<!--DEFINITION-->        the string in the argument referred by the number.
 
−
 
 
−
 
 
−
 
 
−
'''Example:'''
 
−
 
 
−
<nowiki>
 
−
 
 
−
  act("You step over $2n.", A_SOMEONE, self, litter, null, TO_CHAR);
 
−
  act("$1n steps over $2n.", A_SOMEONE, self, litter, null, TO_REST);</nowiki>
 
−
 
 
−
 
 
−
'''See Also:'''
 
−
  [[#act.html|DIL Act() for Dummies]]
 
−
 
 
−
---~---~---~---~---~---~---~---~---
 
−
<span id="bpact"></span>
 
−
 
 
−
The purpose of act is to send a message to a number of players '''present''' in
 
−
a room.  The room is defined as the room containing the afore mentioned
 
−
character (provided he himself is in the room, i.e. not in a closed
 
−
container.)
 
−
 
 
−
 
 
−
---~---~---~---~---~---~---~---~---
 
−
 
 
−
'''Syntax:'''
 
−
 
 
−
act(message, visibility, char, medium, victim, to_whom);
 
−
 
 
−
 
 
−
<!--TERM--> '''message'''
 
−
<!--DEFINITION-->          - is a string that will be shown to other mobiles when the act is executed. To refer to the following arguments use the [[#formatters|formatters]] listed below.
 
−
<!--TERM--> '''visibility'''
 
−
<!--DEFINITION-->          - is an integer that defines what happens if the mobile that is about to receive the message can't see the activator.
 
−
<!--TERM-->        <b><!--CODE-->A_SOMEONE</b><!--ENDCODE-->
 
−
<!--DEFINITION-->                If the receiver cannot see char, replace any reference to char with <i>someone</i>.
 
−
<!--TERM-->        <b><!--CODE-->A_HIDEINV</b><!--ENDCODE-->
 
−
<!--DEFINITION-->                If the receiver cannot see char, don't send the message at all. Use this when missing vision should eliminate the perception of the action the message represent. One instance where it is used is in smile. You would need a ridiculously sensitive ear to hear, let alone percept that someone's smiling if you can't see them. Do not use it if 'sound' is inherent in the message.
 
−
<!--TERM-->        <b><!--CODE-->A_ALWAYS</b><!--ENDCODE-->
 
−
<!--DEFINITION-->                Works exactly like <i><!--CODE-->A_SOMEONE</i><!--ENDCODE-->, except that the receiver will see the message even when sleeping.
 
−
<!--TERM--> '''char'''
 
−
<!--DEFINITION-->          - is a unitptr, and the most important argument in the act. If this is not valid the act will never show, leaving mobiles without the message.
 
−
<!--TERM--> '''medium'''
 
−
<!--DEFINITION-->          - is a unit pointer, an integer or a string. Use this at your leisure.
 
−
<!--TERM--> '''victim'''
 
−
<!--DEFINITION-->          - is a unit pointer, an integer or a string. Certain flags in the next argument rely on the validity of victim.
 
−
<!--TERM--> '''to_whom'''
 
−
<!--DEFINITION-->          - is an integer that defines who gets the message.
 
−
<!--TERM-->        <b><!--CODE-->TO_ROOM</b><!--ENDCODE-->
 
−
<!--DEFINITION-->                Sends the message to the entire room, excluding 'char'.
 
−
<!--TERM-->        <b><!--CODE-->TO_VICT</b><!--ENDCODE-->
 
−
<!--DEFINITION-->                Sends to 'victim' only. 'victim' must be valid, naturally.
 
−
<!--TERM-->        <b><!--CODE-->TO_NOTVICT</b><!--ENDCODE-->
 
−
<!--DEFINITION-->                Sends the message to the entire room, excluding 'char' and 'victim'.  Perfect for bystanders in a melee.
 
−
<!--TERM-->        <b><!--CODE-->TO_CHAR</b><!--ENDCODE-->
 
−
<!--DEFINITION-->                Sends the message to 'char' and no one else.
 
−
<!--TERM-->        <b><!--CODE-->TO_ALL</b><!--ENDCODE-->
 
−
<!--DEFINITION-->                Sends the message to everybody in the room.
 
−
<!--TERM-->        <b><!--CODE-->TO_REST</b><!--ENDCODE-->
 
−
<!--DEFINITION-->                This is a bit different from the rest.  In sends the message to all other units in the local environment, excluding those inside 'char'.
 
−
 
 
−
---~---~---~---~---~---~---~---~---
 
−
 
 
−
<span id="formatters"></span>
 
−
'''Act Formatters'''
 
−
 
 
−
Just as the description formatters, act has its own set of formatters that
 
−
enable you to create generic messages that will be interpreted at run-time,
 
−
lessening the load on you.
 
−
 
 
−
The format string is a normal message, containing some special characters:
 
−
 
 
−
<!--TERM--> '$$'
 
−
<!--DEFINITION-->        will be sent to the receiver as a single `$'
 
−
 
 
−
'$', followed by a number and an extra character.
 
−
  '''The numbers:'''
 
−
 
 
−
<!--TERM--> '1'
 
−
<!--DEFINITION-->          means this formatter refers to the 'char' argument.
 
−
<!--TERM--> '2'
 
−
<!--DEFINITION-->        means this formatter refers to the 'medium' argument.
 
−
<!--TERM--> '3'
 
−
<!--DEFINITION-->          means this formatter refers to the 'victim' argument.
 
−
 
 
−
    '''The characters'''
 
−
 
 
−
<!--TERM--> 'N'
 
−
<!--DEFINITION-->          the formatter will be replaced with the name of the unit, or (depending on the visibility) 'something' or 'someone'.
 
−
<!--TERM--> 'a'
 
−
<!--DEFINITION-->        'a' or 'an' depending on the name of the unit referred by the number.
 
−
<!--TERM--> 'e'
 
−
<!--DEFINITION-->        'it', 'he' or 'she' depending on the gender of the unit referred by the number.
 
−
<!--TERM--> 'm'
 
−
<!--DEFINITION-->        'it', 'him' or 'her' depending on the gender of the unit referred by the number.
 
−
<!--TERM--> 'n'
 
−
<!--DEFINITION-->          the formatter will be replaced with the title of the unit, or (depending on the visibility) 'something' or 'someone'.
 
−
<!--TERM--> 'p'
 
−
<!--DEFINITION-->        'fighting', 'standing', 'sleeping', etc., depending on the positionof the unit referred by the number.
 
−
<!--TERM--> 's'
 
−
<!--DEFINITION-->        'its', 'his' or 'her' depending on the gender of the unit referred by the number.
 
−
<!--TERM--> 't'
 
−
<!--DEFINITION-->        the string in the argument referred by the number.
 
−
 
 
−
 
 
−
 
 
−
'''Example:'''
 
−
 
 
−
<nowiki>
 
−
 
 
−
  act("You step over $2n.", A_SOMEONE, self, litter, null, TO_CHAR);
 
−
  act("$1n steps over $2n.", A_SOMEONE, self, litter, null, TO_REST);</nowiki>
 
−
 
 
−
 
 
−
'''See Also:'''
 
−
  [[#act.html|DIL Act() for Dummies]]
 
−
 
 
−
---~---~---~---~---~---~---~---~---
 

Latest revision as of 23:22, 14 November 2026

act()

Procedure. Shows a message to the characters around someone, worded for each of them.

act(text : string, show : integer, char : unitptr, medium : unitptr or string,
    victim : unitptr or string, to : integer)

Sends text to the characters that to picks, around char. Codes such as $1n in the text are filled in for each reader: a name, or "someone" when they can't see who it is, "he" or "she", and so on. The usual way to tell what happens is one act for the one who does it (TO_CHAR), one for the victim (TO_VICT) and one for the others (TO_NOTVICT or TO_REST).

Parameters

Name Type Meaning
text string The message, with $-codes (below). No <br/> at the end: act adds it.
show integer A_SOMEONE, A_HIDEINV, A_ALWAYS or A_RAW (below).
char unitptr The one who acts: $1, and the place the message goes out from.
medium unitptr or string $2: a unit, a string for $2t, or null.
victim unitptr or string $3: a unit, a string for $3t, or null.
to integer Who gets it: a TO_ constant (below).

The constants are in vme.h.

to Who gets it
TO_CHAR char only.
TO_VICT victim only.
TO_ROOM Everyone around char, but not char.
TO_NOTVICT Everyone around char, but not char and not victim.
TO_ALL Everyone around char, char too.
TO_REST As TO_ROOM, and not those inside char either.

"Around char" is the room char is in, including those inside transparent units there; when char is inside a transparent unit (a wagon, a boat), also the room around that unit.

show Meaning
A_SOMEONE Not shown to those asleep. A unit a reader can't see is "someone" or "something".
A_HIDEINV Not shown to those who can't see char, nor to those asleep. For things that are only seen, like a smile.
A_ALWAYS Shown also to those asleep. A unit a reader can't see is "someone" or "something".
A_RAW Shown to everyone, and $n and $N give the real names even of units the reader can't see.

A code is $, a digit for the argument (1 char, 2 medium, 3 victim) and a letter:

Code Becomes
$1n A player's name, or the title of an NPC or object ("the town guard"); "someone" or "something" to those who can't see it.
$1N The unit's first name ("guard"); "someone" or "something" to those who can't see it.
$1e, $1m, $1s he/she/it, him/her/it, his/her/its.
$1p The character's position (standing, sleeping, ...); "lying" for anything else.
$1a "a" or "an" to go before the unit's name (or before a string argument).
$2t The string given as that argument.
$$ A single $.

Notes

  • Only characters with a connection see it. NPCs, and the programs on them, never see act() text: to tell a program something, use send() or sendto().
  • With char null, or victim null for TO_VICT and TO_NOTVICT, nothing is sent. A string as char compiles but sends nothing.
  • A to outside TO_ROOM ... TO_REST (0 to 5) sends nothing. A show below 10 or above 14 is logged and taken as A_ALWAYS.
  • A code whose argument is null shows "NULL", and an unknown code cuts the message there; both are logged.
  • The first letter is made a capital (after any HTML tags at the start).
  • Numbers can't be passed: give itoa(n) as the medium or victim and write $2t or $3t.
  • Used in an expression, s := act(...) sends nothing and gives the text as the one it is about would see it, with the <br/>, or "" when there is nobody or they wouldn't see it; see sact().

Example

dilbegin block_flee();
var
   pc : unitptr;
code
{
   :start:
   wait(SFB_CMD, command("flee") and (activator.type == UNIT_ST_PC));
   pc := activator;
   block;
   act("You panic and try to flee, but something prevents you from escaping!",
       A_SOMEONE, pc, null, self, TO_CHAR);
   act("$1n panics and tries to flee, but can not!",
       A_SOMEONE, pc, null, self, TO_REST);
   goto start;
}
dilend

dilbegin hand_over(item : unitptr, pc : unitptr);
code
{
   act("You hand $2n to $3n.", A_SOMEONE, self, item, pc, TO_CHAR);
   act("$1n hands you $2n.", A_SOMEONE, self, item, pc, TO_VICT);
   act("$1n hands $2n to $3n.", A_SOMEONE, self, item, pc, TO_NOTVICT);
   return;
}
dilend

Fleeing fails where this program is, with one message for the player and one for the others (adapted from clans.zon), and the three messages of handing something over.

See also