greeting_d.c - example for course 12

[previous example] [course 12] [Table of contents] [next example]
/* Filename      : greeting_d.c
 * Description   : an annoying daemon
 *
 * written       : 23-12-1996 - Gunner
 * last modified : 28-05-1998 - Gunner
 * HTML-Version  : 07-02-2000 - Ghorwin
 */

#include <mudlib.h>
inherit I_DAEMON;

#define SLEEP_TIME 30+random(30)

// Change this list to include your friends' names
string* friends = ({"gunner","barag","aztec","evergreen","sharp"});

// Change this list to some cool messages to send...
string* messages = ({"Hia! What's up with you?\n",
                     "Are you still here?\n",
                     "Why haven't you gone home yet?\n",
                     "Mudding is cool, ain't it?\n"});

/* 
 * create : This is a special functionname which will be called when the 
 *          object is created. Other such names are reset() and init()...
 */
void create()
{
    ::create();
    call_out("greet_players",SLEEP_TIME);
}

/* greet_players : This is the function called every SLEEP_TIME. It annoys 
 *                 the players quite a bit, so make damn sure the daemon is 
 *                 destroyed before you leave. And only use it "against" 
 *                 friends. Other ppl may call this harassment.
 */
void
greet_players()
{
    object pl;
    string name;

    foreach(name in friends)
    {
        pl = find_player(name);
        if (!pl) continue;
        tell_object(pl,messages[random(sizeof(messages))]);
    }
    call_out("greet_players",SLEEP_TIME);
}