com/ctell.c and help/ctell - examples for course 08

[previous example] [course08] [Table of contents] [next example]
/* Filename      : ctell.c
 * Description   : colour-tell command 
 *
 * written       : 04-10-1996 - Gunner
 * last modified : 27-05-1998 - Gunner
 * HTML-Version  : 04-02-2000 - Ghorwin
 */

#include <mudlib.h>
#include "/doc/crashcourse/defs.h"
inherit I_COMMAND;

#define HELPDIR "/doc/crashcourse/course08/help/"
#define ERRORMSG "'ctell <player> <message>'\n"
#define C_END "%^END%^"

    /* All available colours...                     */

string* colours = ({"BOLD", "INVERSE", "UNDERLINE", "BLINK", "BLACK", "RED",
                    "GREEN", "YELLOW", "BLUE", "MAGENTA", "CYAN", "GREY",
                    "L_RED", "L_GREEN", "L_YELLOW", "L_BLUE", "L_MAGENTA",
                    "L_CYAN", "B_BLACK", "B_RED", "B_GREEN", "B_YELLOW",
                    "B_BLUE", "B_MAGENTA", "B_CYAN", "B_GREY"});

string
query_action()
{
    return "ctell";   // short for colourtell.
}

string
short_help()
{
    return "This command will send a message to a player in a random colour.\n";
}

string
help()
{
    return HELPDIR+"ctell";
}

/* 
 * query_code : A function that returns a random colourcode
 */
string
query_ccode()
{
    string colourcode;

    colourcode = "%^" + colours[random(sizeof(colours))] + "%^";

    return colourcode;
}

/* 
 * MAIN 
 */
static int
main(string arg)
{
    string name, message;
    object who;

    if (!arg || sscanf(arg,"%s %s",name,message) != 2)
        NOT_FAIL(ERRORMSG);

    who = find_player(name);

    if (!who)
        NOT_FAIL("Who did you say? Can't find that player anywhere...\n");

    message = query_ccode() + message + C_END;

    tell_object(TP,"You send the following message:\n" + message + "\n"
        "to: " + CAP(Q_RNAME(who)) + ".\n");;

    tell_object(who,CAP(Q_RNAME(TP)) + " tells you: " + message + "\n");

    return 1;
}

help/ctell


NAME
        ctell - send a random coloured message to a player

SYNTAX
        ctell <player> <message>

DESCRIPTION
        This command will send randomly coloured message to a player.
        It will choose the colour from all available colours.

EXAMPLE
        ctell gunner Colours are fun, ain't they?

SEE ALSO
        atell, mtell