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

[previous example] [course08] [Table of contents] [next example]
/* Filename      : dmessage.c
 * Description   : command for delayed messages
 *
 * 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 "'dmessage <player> <message>'\n"
#define TIME 60

string
query_action()
{
    return "dmessage";
}

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

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

/* send_message : The delayed function - The whole argument is sent through 
 * due to the fact that the player may have logged out and in again within 
 * those seconds, and the player object would then have been changed.
 */
void
send_message(string arg)
{
    string name, message;
    object who;

    // No need for further error checking since we did all that
    // in the main() function, and arg is identical to main()s arg

    sscanf(arg,"%s %s",name,message);

    who = find_player(name);

    if (!who) 
        return;  // The player left... *sob* *sob*

    tell_object(who,message+"\n");
}

/* 
 * 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(name + " can't be found anywhere!\n");

    tell_object(TP,"Delayed message:\n" + message + "\nTo be sent to: " +
        name + " in 60 seconds.\n");

    call_out("send_message",TIME,arg);

    return 1;
}

help/dmessage


NAME
        dmessage - send a delayed message to a player

SYNTAX
        dmessage <player> <message>

DESCRIPTION
        This command will send a delayed message to a player.
        It will wait for 60 seconds, then send the specified
        message to the player. You can even format the message
        to look like a tell. ;-)

EXAMPLE
        dmessage gunner Someone tells you: Bah. I ain't here, doofy!

SEE ALSO