The COMPLETE Abermud List
« December 2003 »
S M T W T F S
1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30 31
You are not logged in. Log in
Entries by Topic
All topics  «
Blog Tools
Edit your Blog
Build a Blog
View Profile
Monday, 1 December 2003
Event Code for iDirt
Abermud Central is pretty much an abandoned site, but someone posted this code months ago that I just noticed: Damian Miller's Event Handler Code for iDiRT 1.82 All I ask is if you use this that you give me a little credit,
Makefile
add events.o to MUDDOBJS

events.h

#ifndef _EVENTS_H_
#define _EVENTS_H_

typedef struct _event_sys {
  struct _event_sys *next;
  Boolean use;
  char name[50];
  time_t timer;
  time_t reset_timer;
  void (*output_func)();
}_EVENT_SYS;

void load_events();
void do_events();
void eventscom ();

#endif

events.c

#include "kernel.h"
#include "mud.h"
#include "log.h"
#include "bootstrap.h"
#include "sendsys.h"
#include "mobile.h"
#include "timing.h"
#include "locations.h"
#include "objsys.h"
#include "bprintf.h"
#include "events.h"
#include "parse.h"
#include "utils.h"

_EVENT_SYS *ehead, *etail;
typedef _EVENT_SYS *eventsys;

void event_healall();

void add_event(char *name, Boolean use, time_t t, void (*d)())
{
	_EVENT_SYS *ecur;
	if(ehead==NULL)
	{
	 ehead = NEW(_EVENT_SYS, 1);
	 etail = ehead;
	 ecur  = ehead;
	}
	else
	{
	etail->next = NEW(_EVENT_SYS, 1);
	etail = etail->next;
	}
	strcpy(etail->name, name);
	etail->use = use;
	etail->reset_timer = t;
	etail->output_func = d;
	etail->next = NULL;
}

void do_events ()
{
  _EVENT_SYS *event;

  for (event = ehead; event != NULL; event = event->next)
  { 
    if (event->use == True) {
    ++event->timer;
     if (event->timer >= event->reset_timer) 
     {
       (void) event->output_func();
       event->timer = 0;
     }
    }
  }
}

//Load the events into the system.
void load_events ()
{
  //         Name       Use?    Reset   Function
  add_event("healall",	True,	300,	event_healall);
}


//A command to show events in the mud.
void eventscom ()
{
  _EVENT_SYS *event;
  char tleft[64];
  int count;
  if (plev (mynum) < LVL_ARCHWIZARD)
  {
   erreval ();
   return;
  }
  bprintf ("&+RTimed &+Cevents &+cin the &+Gland &+cof &+m%s&+c.\n", COL_NAME);
  bprintf ("&+r-------------------------------------------------------------------------------\n");
  bprintf ("&+W%-12s %-6s %-9s\n", "Name", "Active", "Time Left");
  bprintf ("&+r-------------------------------------------------------------------------------\n");
  for (event = ehead, count = 0; event != NULL; event = event->next, ++count)
  {
    strcpy (tleft, sec_to_hhmmss (event->reset_timer - event->timer));
    bprintf ("&+g%-12s %-6s %-9s\n", capitalize(event->name), 
    event->use == True ? "Yes" : "No", tleft);
  }
  bprintf ("&+r-------------------------------------------------------------------------------\n");
  bprintf ("&+cTotal &+YEvents&+C: &+g%d\n", count);
}

/************************************************************
 * Start of events, lets hope all these are nice            *
 ************************************************************/
void event_healall ()
{
  int i;
  int j = 0;
  for (i = 0; i < max_players; ++i) {
    if (is_in_game (i) && pfighting (i) < 0 && plev (i) < LVL_WIZARD &&
        ((pstr (i) < maxstrength (i) || pmagic (i) < maxmagic (i)) ||
         (pstr (i) < maxstrength (i) && pmagic (i) < maxmagic (i)))) {
      setpstr (i, maxstrength (i));
      setpmagic (i, maxmagic (i));
      ++j;
      sendf (i, "&+m%s &+cunleashes a healing spell over the world.\n",
             MUD_NAME);
    }
  }
    if(!j==0)
    send_msg (DEST_ALL, MODE_QUIET, LVL_WIZARD, LVL_MAX, mynum, NOBODY,
              "&+r[&+gEvent: &+CAuto &+YHeal All&+r]\n");
}

open up main.c and add this at the bottom of the includes:

#include "events.h"

then look for the on_timer(); and below it add:

do_events();

save and exit.

open up bootstrap.c and include events.h then in boot_world() add:

load_events();

add the verb "events" to verbs.src

then add #include "events.h" to parse.c and somewhere where you put your commands add:

  case VERB_EVENTS:
    eventscom();
    break;

save and exit. and you got my event code.

do a make clean or rm -rf *.o first

Posted by abermud at 11:43 AM CST
Post Comment | Permalink

View Latest Entries