Difference between revisions of "Manual:DIL Manual/addcolor()"
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) | ||
| − | < | + | Adds <code>key</code> to the player's personal colours with the value <code>colour</code>. From |
| + | then on, text inside <code><div class='key'></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>. | ||
| − | + | == 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>. | ||
| + | |} | ||
| − | + | == Returns == | |
| − | + | Integer: <code>TRUE</code> when the colour was added, <code>FALSE</code> when the player already | |
| − | + | has that key. It fails, and writes a line to the zone's log, when <code>pc</code> is null or not | |
| − | + | a PC, when the key is empty, too long or has other characters, or when <code>colour</code> is | |
| − | + | empty. | |
| − | |||
| − | + | == Notes == | |
| − | + | * A key is matched by abbreviation: if the player has <code>clan_who</code>, | |
| − | + | <code>addcolor(pc, "clan", ...)</code> finds it and returns <code>FALSE</code>. Use | |
| − | + | [[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 returnsFALSE. Use changecolor() to change an existing one.
- The colour isn't checked. The
colorcommand accepts a foreground of
c, an optionalp(bright) and one ofn r g y b m c w, then a background ofband one ofn 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.