Re: Guard

From: Chuck Reed (
Date: 04/20/99

>I need a little help here, I am tring to make a guard skill. What it does is
>you type guard <name> and that makes you guard <name> Then if anyone attacks
><name> The person who is guarding automaticly rescues  them. How would I go
>about this. Please no flames, just help. :)

Add the following in structs.h:
   struct char_data *next_in_room;     /* For room->people - list         */
   struct char_data *next;             /* For either monster or ppl-list  */
   struct char_data *next_fighting;    /* For fighting list               */

   struct follow_type *followers;        /* List of chars followers       */
   struct char_data *master;             /* Who is char following?        */
+  struct char_data *guarding;           /* Who is the character guarding? */

Also add a SKILL_GUARD define where it's needed and a new PRF flag for
people who don't want to be guarded called PRF_NOGUARD.

Then write up the body of a command to set the guarded character like:
   one_argument(argument, arg);

      send_to_char ("You have no idea how!\r\n", ch);
   else if (!*arg)
      send_to_char ("Syntax: guard <target name>\r\n");
   else if (!(vict = get_char_room_vis(ch, arg)))
      send_to_char ("They don't seem to be here.\r\n", ch);
   else if (PRF_FLAGGED(vict, PRF_NOGUARD))
      send_to_char ("They don't want to be guarded right now!\r\n", ch);
   else {
      sprintf (buf, "You are now guarding %s.\r\n", GET_NAME(vict));
      send_to_char (buf, ch);
      sprintf (buf, "%s starts to guard you.\r\n", GET_NAME(ch));
      send_to_char (buf, vict);
      ch->guarding = vict;

Then in damage(), add two char_data vars called *guard and *next_guard and
make a check like this:
   for (guard = world[ch->in_room].people;guard;guard = next_guard) {
      next_guard = guard->next_in_room;
      if (guard->guarding == ch && GET_POS(guard) == POS_STANDING) {
         sprintf(buf, "You jump to the aid of %s!\r\n", GET_NAME(ch));
         send_to_char(buf, guard);
         sprintf(buf, "%s jumps to your aid!\r\n", GET_NAME(guard));
         send_to_char(buf, ch);
         sprintf(buf, "%s jumps to the aid of %s!\r\n", GET_NAME(guard),
         send_to_char(buf, victim);
         set_fighting(guard, victim);
         set_fighting(victim, guard);

That's the bulk of everything.  I won't post all the places you have to do
things, have to leave a little for the imagination.  Plus, this has a lot
of room for improvement, it's just an outline for you to use.

Lots of luck,
"Though his mind is not for rent to any god or government, don't write him
off as arrogant."

     | Ensure that you have read the CircleMUD Mailing List FAQ:  |
     |  |

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