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

From DikuMUD Wiki
Jump to navigation Jump to search
(XML import)
 
(checked against the compiler and the interpreter; example compiles)
 
(One intermediate revision by one other user not shown)
Line 1: Line 1:
 +
= addcolor() =
 +
'''Function''' (integer). Gives a player their own colour for a colour name.
  
 +
addcolor(pc : unitptr, key : string, colour : string)
  
−
<span id="bpaddcolor"></span>
+
Adds <code>key</code> to the player's personal colours with the value <code>colour</code>. From
 +
then on, text inside <code>&lt;div class='key'&gt;</code> (see
 +
[[Manual:DIL Manual/getcolor()|getcolor()]]) is shown to that player in this colour instead of
 +
the game's default. The colours are saved with the player, and the <code>color</code> command
 +
lists them. A player with no colour of their own for a key gets the default from
 +
<code>vme/etc/color.def</code>.
  
−
'''Function: '''<i><!--CODE-->addcolor (ch : unitptr, ks : string, cstr : string ) ;</i><!--ENDCODE-->
+
== Parameters ==
 +
{| class="wikitable"
 +
! Name !! Type !! Meaning
 +
|-
 +
| pc || unitptr || The player. Must be a PC.
 +
|-
 +
| key || string || The colour's name: 1 to 20 letters, digits or <code>_</code>.
 +
|-
 +
| colour || string || The colour, written as in <code>color.def</code>: a foreground and a background, such as <code>"cpc bn"</code>.
 +
|}
  
−
<!--TERM--> '''ch'''
+
== Returns ==
−
<!--DEFINITION-->         character you are adding the color to
+
Integer: <code>TRUE</code> when the colour was added, <code>FALSE</code> when the player already
−
<!--TERM--> '''ks'''
+
has that key. It fails, and writes a line to the zone's log, when <code>pc</code> is null or not
−
<!--DEFINITION-->         key string for the color
+
a PC, when the key is empty, too long or has other characters, or when <code>colour</code> is
−
<!--TERM--> '''cstr'''
+
empty.
−
<!--DEFINITION-->         color string
 
  
−
This function allows your Dils to create and add their own personal colors to a players
+
== Notes ==
−
color list.  That way you can actually make an act in a color that the player chooses or
+
* A key is matched by abbreviation: if the player has <code>clan_who</code>,
−
you yourself choose.
+
  <code>addcolor(pc, "clan", ...)</code> finds it and returns <code>FALSE</code>. Use
−
'''Function: '''<i><!--CODE-->addcolor(pc, "clan_who","&amp;c+w&amp;bn");</i><!--ENDCODE-->
+
  [[Manual:DIL Manual/changecolor()|changecolor()]] to change an existing one.
 +
* The colour isn't checked. The <code>color</code> command accepts a foreground of
 +
  <code>c</code>, an optional <code>p</code> (bright) and one of <code>n r g y b m c w</code>,
 +
  then a background of <code>b</code> and one of <code>n r g y b m c</code>:
 +
  <code>"cw bn"</code> is white on black, <code>"cpy bn"</code> bright yellow. Stay with those.
 +
* Personal colours only change what telnet players see. The web client gets the class name
 +
  and colours it with its own style sheet.
 +
 
 +
== Example ==
 +
<pre>
 +
dilbegin set_clan_col(pc : unitptr, colour : string);
 +
var
 +
  i : integer;
 +
code
 +
{
 +
  if (pc.type != UNIT_ST_PC)
 +
      quit;
 +
 
 +
  if (not addcolor(pc, "clan_who", colour))
 +
      i := changecolor(pc, "clan_who", colour);
 +
 
 +
  sendtext(getcolor("clan_who") + "Your clan list looks like this now.</div><br/>", pc);
 +
  quit;
 +
}
 +
dilend
 +
</pre>
 +
Sets a player's colour for <code>clan_who</code>, adding it or changing it.
 +
 
 +
== See also ==
 +
* [[Manual:DIL Manual/changecolor()|changecolor()]]
 +
* [[Manual:DIL Manual/delcolor()|delcolor()]]
 +
* [[Manual:DIL Manual/getcolor()|getcolor()]]

Latest revision as of 23:03, 14 November 2026

addcolor()

Function (integer). Gives a player their own colour for a colour name.

addcolor(pc : unitptr, key : string, colour : string)

Adds key to the player's personal colours with the value colour. From then on, text inside <div class='key'> (see getcolor()) is shown to that player in this colour instead of the game's default. The colours are saved with the player, and the color command lists them. A player with no colour of their own for a key gets the default from vme/etc/color.def.

Parameters

Name Type Meaning
pc unitptr The player. Must be a PC.
key string The colour's name: 1 to 20 letters, digits or _.
colour string The colour, written as in color.def: a foreground and a background, such as "cpc bn".

Returns

Integer: TRUE when the colour was added, FALSE when the player already has that key. It fails, and writes a line to the zone's log, when pc is null or not a PC, when the key is empty, too long or has other characters, or when colour is empty.

Notes

  • A key is matched by abbreviation: if the player has clan_who,
 addcolor(pc, "clan", ...) finds it and returns FALSE. Use
 changecolor() to change an existing one.
  • The colour isn't checked. The color command accepts a foreground of
 c, an optional p (bright) and one of n r g y b m c w,
 then a background of b and one of n r g y b m c:
 "cw bn" is white on black, "cpy bn" bright yellow. Stay with those.
  • Personal colours only change what telnet players see. The web client gets the class name
 and colours it with its own style sheet.

Example

dilbegin set_clan_col(pc : unitptr, colour : string);
var
   i : integer;
code
{
   if (pc.type != UNIT_ST_PC)
      quit;

   if (not addcolor(pc, "clan_who", colour))
      i := changecolor(pc, "clan_who", colour);

   sendtext(getcolor("clan_who") + "Your clan list looks like this now.</div><br/>", pc);
   quit;
}
dilend

Sets a player's colour for clan_who, adding it or changing it.

See also