  My first contribution is an event queue. For those who do not know, it's 
a list of things that are scheduled to happen in a certain moment in the 
future. 

  As far as i know, the code is free of bugs, and has worked perfectly in
my mud for a long time, with no trouble at all.

The event queue is composed by two files:
   events.c and events.h

Plus there are some changes to other files:

--------- structs.h ------------

Just add the following at the bottom:

/****  Event-driven engine structs  ******************************/

#define PULSE_EVENT     (1 RL_SEC)

#define EVENT(name) void (name)(void *causer, void *victim, long info)

struct event_info {
  int ticks_to_go;
  EVENT(*func);
  void *causer,*victim;
  void *info;
  struct event_info *next;
};

----------- handler.c

In function extract_char(), just before the REMOVE_FROM_LIST:

  /* remove any pending event for/from this character. */
  clean_events(ch);

------------ comm.c

In function heart_beat(), just after the call to perform_violence()

  if (!(pulse % PULSE_EVENT))
    run_events();

------------ Makefile

In the OBJFILES = ...

add the file events.o

then in the end of the file add:

events.o: events.c structs.h events.h utils.h comm.h handler.h db.h
<TAB>$(CC) -c $(CFLAGS) events.c

------------

That's all, I think. If it doesn't work mail me and i'll see what's missing. 
I also send my code for the teleport event, you can use it if you
want, but you'll have to change a lot more stuff (db.c and handler.c, structs.h
i think).

extern struct room_data *world;
EVENT(teleport_event)
{
  int destin=0;
  void death_cry(struct char_data *ch);

  /* Is the character still in the same room? */
  if (GET_LEVEL(VICTIM_CH)<LVL_GOD && VICTIM_CH->in_room==info) {

    /* Tell the other players in the room about the teleport. */
    act(world[VICTIM_CH->in_room].teleport->message_you,TRUE,VICTIM_CH,NULL,
        VICTIM_CH,TO_VICT);
    act(world[VICTIM_CH->in_room].teleport->message_oth,FALSE,VICTIM_CH,NULL,
        VICTIM_CH,TO_NOTVICT);

    /* Perform the teleport. */
    if ((destin=real_room(world[info].teleport->to_room))!=-1)
    {
      char_from_room(VICTIM_CH);
      char_to_room(VICTIM_CH,destin);
      look_at_room(VICTIM_CH,1);
      if (IS_SET(ROOM_FLAGS(VICTIM_CH->in_room),ROOM_DEATH) &&
                                              GET_LEVEL(VICTIM_CH)<LVL_IMMORT)
      {
        log_death_trap(VICTIM_CH);
        death_cry(VICTIM_CH);
        extract_char(VICTIM_CH);
      }
    } else
      log("SYSERR: Trying to teleport to unexisting room. Ignoring.");
  };
};

Finally, if you have mob progs, here's another example of use of events:

------------  mobcmd.c  ------

In the end of the file:

EVENT(delayed_command)
{
  command_interpreter(CAUSER_CH,(char *)info);
  free((char *)info);
}

ACMD(do_mpdelayed)
{
  char arg1[20];
  int delay;

  arg1[0]='\0';

  if (!IS_NPC(ch) || IS_AFFECTED(ch, AFF_CHARM))
    {
      send_to_char("Huh?\n\r", ch);
      return;
    }

  half_chop(argument,arg1,buf);
  delay=atoi(arg1);

  if (!delay)
    bug("Mpdelayed - the delay is invalid. - vnum #%d",0)
  else {
    sprintf(buf1,"Ok. Executing '%s' in %d seconds.\r\n",buf,delay);
    send_to_char(buf1,ch);
    add_event(delay,delayed_command,ch,NULL,(int)strdup(buf));
  };
}

                   I hope you find it useful,
                                Luis Carvalho
				<si12632@ci.uminho.pt>
