Re: Fight.c: switching targets in hit()

From: Patrick Dughi (dughi@imaxx.net)
Date: 11/23/98


>   Sorry if you received this already. I sent it from another server on my
> ISP accidently so I am pretty sure it never got out.
>   I have a question about switching victims during a fight. I want to make
> a skill that basically works like an autorescue but it happens BEFORE the
> first attack gets off. So, for instance, you go into a room with your mage
> following. The mob in that room is aggro towards Mages, and attacks. The
> warrior skill kicks in so instead he takes the hit instead of the mage.
> How do I switch targets like that? I tried simple victim = victim->master
> (the person taking the hit is the leader of the group), and this works
> until I type peace (stops battle) which then causes the MUD to crash. I
> also went through and used basically the rescue code for stopping a fight
> and starting one, but that didn't work either. I am putting all
> this code in the hit() function right above where it calculates AC because
> this is where it needs to be. Can anyone help?

        If you're on a *nix system (i'll assume this since you're talking
of sending from different servers), the solution is pretty simple - use
the gdb program to examine your core file.  It will tell you why the
crash was caused, which file caused it, which line, etc.

        Specifically though, i'd say that the do_hit might be the wrong
function to put this check in..see, do_hit ...
void hit(struct char_data * ch, struct char_data * victim, int type)

        Now, i'm not the best programmer in the world, but I really
_really_ recommend that you not change the argument that you've been
passed (ie, redefine victim to be a different one.)

        You're almost sure to screw something up like that.  On the other
hand though, there is an easy way to do it..

        Make a function like 'check_for_resucer'....

struct_char data *check_for_rescuer(struct char_data *mob,
                                        struct char_data *vict) {
   struct char_data *k = 0;

        /* if they're not grouped, they will not be saved..*/
   if(!(vict->master || vict->followers)) {
     return vict;
   }
                /* they're grouped, check for master first */
   if(vict->master && (mob->in_room == vict->master->in_room) &&
     GET_SKILL(vict->master,SKILL_GOOD_RESCUE) &&
        CAN_SEE(vict->master,mob) &&
                other stuff like is standing etc ...) {
     /* might want to do a skill check here, instead of auto-allowing
        this hit transfer */
     return (vict->master);
    }

/* else the master either doesn't exist, or doesn't do the skill */

     for (k = vict->followers; k; k = k->next) {
       if(k && (mob->in_room == k->in_room) && GET_SKILL(k,SKILL_GOOD_RESCUE) &&
          CAN_SEE(k,mob) && other stuff like is standing etc ...) {
     /* might want to do a skill check here, instead of auto-allowing
        this hit transfer */
        return (k);
        }
     }
        /* no one with the skill found */
    return vict;
}

        A simple enough function - run it like this:
          hit(ch, check_for_rescuer(ch,vict), TYPE_UNDEFINED);

        In each case of the hit function in the aggro section of your
mobact.c.  This is pretty simple actually, it will return either the
player if no one can save them, or the player they should hit if not.  It
doesn't involve any extensive changes either, as the do_hit function
should take care of it...

                                                PjD


     +------------------------------------------------------------+
     | 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