Example DGevent

From: Fafhrd (fafhrd@LINKMASTER.NET)
Date: 05/12/98


This is a well working one.... Enjoy.



struct camp_event {
  struct char_data *ch;
  int was_in;
};

ACMD(do_camp)
{
  struct camp_event *ce;

  if (GET_ACTION(ch)) {
    send_to_char("You are too busy to do this!\r\n", ch);
    return;
  }
  if (GET_POS(ch) == POS_FIGHTING) {
    send_to_char("Suicide may be accomplished in many ways. This isn't one
of them.\r\n", ch);
    return;
  }
  /* create and initialize the camp event */
  CREATE(ce, struct camp_event, 1);
  ce->ch = ch;
  ce->was_in = ch->in_room;
  GET_ACTION(ch) = event_create(camp_event, ce, 50);

  act("You prepare a campsite, in anticipation of leaving the realm.",
FALSE, ch, NULL, NULL, TO_CHAR);
}

EVENTFUNC(camp_event)
{
  struct camp_event *ce = (struct camp_event *) event_obj;
  struct char_data *ch = NULL;
  int was_in, now_in, x, y, z;
  void Crash_rentsave(struct char_data *ch, int cost);

  /* extract all the info from ce */
  ch = ce->ch;
  was_in = ce->was_in;
  now_in = ch->in_room;
  free(event_obj);

  /* make sure we're supposed to be here, then clear it */
  if (!GET_ACTION(ch))
    return 0;
  GET_ACTION(ch) = NULL;

  if (IS_NPC(ch) || !ch->desc)
    return 0;

  if (GET_POS(ch) == POS_FIGHTING) {
    act("You decide now is not the best time for camping.", FALSE, ch, NULL,
NULL, TO_CHAR);
    return 0;
  }
  if (now_in != was_in) {
    act("You are no longer near where you began the campsite.", FALSE, ch,
NULL, NULL, TO_CHAR);
    return 0;
  }
  act("You complete your campsite, and leave this world for awhile.", FALSE,
ch, NULL, NULL, TO_CHAR);
  if (!GET_INVIS_LEV(ch))
    act("$n camps out, leaving this realm.", TRUE, ch, 0, 0, TO_PROXIMITY);
  sprintf(buf, "%s camped out", GET_NAME(ch));
  mudlog(buf, CMP, LVL_GOD, TRUE);
  Crash_rentsave(ch, 0);
  extract_char(ch);
  save_char(ch, now_in);

  return 1;
}

Erik Madison
System Engineer
LinkMaster ISP Services
fafhrd@linkmaster.net


     +------------------------------------------------------------+
     | Ensure that you have read the CircleMUD Mailing List FAQ:  |
     | http://democracy.queensu.ca/~fletcher/Circle/list-faq.html |
     +------------------------------------------------------------+



This archive was generated by hypermail 2b30 : 12/15/00 PST