Re: [CODE][NEWBIE??] Problem with IS_NPC(ch) (LONG)

From: Peter Ajamian (peter@pajamian.dhs.org)
Date: 04/16/01


Rich M Carpenter wrote:
>
> My problem is this:
> A select few of my mobs have found a way past an IS_NPC(ch) check,
>
> Here is the code:
> int invalid_race(struct char_data *ch, struct obj_data *obj) {
>         if (IS_NPC(ch))                <------- This is the check they
> are bypassing.

Hrmmm, very strange.  First check to make sure that the #defines are
correct.  Following is the actual #define for IS_NPC() (stock from latest
CVS, I don't think they changed, but you can dbl check them in bpl17
stock if you want)...
#define IS_NPC(ch)      (IS_SET(MOB_FLAGS(ch), MOB_ISNPC))
Then the #defines for IS_SET, MOB_FLAGS and MOB_ISNPC...
#define IS_SET(flag,bit)  ((flag) & (bit))
#define MOB_FLAGS(ch)   ((ch)->char_specials.saved.act)
#define MOB_ISNPC        (1 << 3)  /* (R) Automatically set on all
Mobs       */

If any of these changed there might be a reason (ie a patch or snippet
you put in, maybe 128 bits?).  Figure out why and what went wrong.

I would set a breakpoint for invalid_race and then check all the relevent
values for IS_NPC at that time.  Since you can't use macros directly in
gdb you have to resolve them yourself to check the actual value that
you're looking for, ie...

print (ch->char_specials.saved.act & (1<<3))

This should be non-zero for a mob (actually it will return 8 which is
1<<3).  If it shows as zero then your next task is to figure out why, if
it shows as non-zero then you're really up a creek as the compiler is
messing it up (continue to step through the test to verify this).

If it's zero you may find it helpfull just to get a full dump of the
entire char_data structure, you can do that with...

print *ch

Good luck.

> [OFF-TOPIC]
> diceroll = number(1, 20);
> does it assign a value to diceroll, or does any further use of diceroll
> cause a new number to be generated?

number() is a function just like any other, = is the assignment
operator.  The purpose of the number() function is to return a random
number between the two args inclusinve.  The purpose of the assignment
value is to copy the return value (or just the value period for
variables/constants/etc) to the variable on the left side.  It does not
create a permanent attachment between the two args, it simply does a
basic copy operation.  So the short answer is that no, further use of
diceroll will not cause a new number to be generated.  To generate a new
number you have to make the assignment again (ie a second
diceroll=number(1,20)).

Regards, Peter

--
   +---------------------------------------------------------------+
   | FAQ: http://qsilver.queensu.ca/~fletchra/Circle/list-faq.html |
   | Archives: http://post.queensu.ca/listserv/wwwarch/circle.html |
   +---------------------------------------------------------------+



This archive was generated by hypermail 2b30 : 12/05/01 PST