Re: [Code][Re: Sac code]

From: JTRhone (ujtr@lady.cs.sunyit.edu)
Date: 12/08/96


On Sun, 8 Dec 1996, Dan Johnson wrote:
> <snipped>
> {
>   struct obj_data *obj;
> 
>   one_argument(argument, buf);
> 
>   if (*buf) {
>     if ((obj = get_obj_in_list_vis(ch, buf, world[ch->in_room].contents)) &&
>        (CAN_WEAR(obj, ITEM_WEAR_TAKE))) 
      {
>       act("$n sacrifices $p.", FALSE, ch, obj, 0, TO_ROOM);
>       act("You sacrifice $p to your god.\r\nYou have been rewarded by
>       your deit$ extract_obj(obj);
>     } 
      else // <<<<<<< Crash bug next line, if obj == NULL >>>>>>
      if (!(CAN_WEAR(obj, ITEM_WEAR_TAKE))) {
>         send_to_char("You can't sacrifice that!\r\n", ch);
>     }
>   } else
>     send_to_char("Sacrifice what?\r\n", ch);
>   return;
>  }                                                           
> 
See the bug?  If the obj isn't found in the room, you still check obj's
flags on the else clause.

I'll make a couple mods to this.  Note: this is not my code, this is code
that someone posted, and I feel like fixing up a bit.  Also please note,
that I use an extremely iterative version with something like this.  If
you are having trouble with some code, it's better not to try to mimic
some of the gurus on here with squishing up 45 tasks in a small block of
code.  It's better, if you are not entirely comfortable with C, to split
up the tasks into a readable format so you actually understand what's goin
on :)  This is not a flame, merely a suggestion.  BTW, I'm not familiar
with Circle3.0, since mine is based on 2.2, but I don't recognize the
object wear flag ITEM_TAKE_WEAR... perhaps its a bit or from two older
flags, like (ITEM_TAKE | ITEM_WEAR) ?  Just curious :)

ACMD(do_sac)
{
   struct obj_data *obj;

   one_argument(argument, arg);

   // note, I like to take care of no arg and wrong args up front, not
   // at the end of a function, lets get the wrongness out of the way :) 
   if (!*arg)
   {
     send_to_char("  << Sac what? message >> \n\r",ch);
     return;
   }

   // if it's not in the room, we ain't gonna sac it
   if (!(obj = get_obj_in_list_vis(ch, arg, world[ch->in_room].contents)))
   {
     send_to_char(" << That obj aint here messg >> \n\r",ch);
     return;
   }

   // nifty, got the object in the room, now check its flags
   if (!CAN_WEAR(obj, ITEM_TAKE_WEAR))
   {
     send_to_char(" << You can't sacrifice that! message >>\n\r",ch);
     return;
   }

   // seems as if everything checks out eh? ok now do it
   act("$n sacrifices $p.", FALSE, ch, obj, 0, TO_ROOM);
   act("You sacrifice $p to your god.\r\nYou have been rewarded by your deity.",
	FALSE, ch, obj, 0, TO_CHAR); 
   extract_obj(obj);
}

Hope this helps somebody.

jtrhone aka vall RoA


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



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