Mob using player data

This question has come up a couple times lately so I decided to post it here to direct people as needed.


Players and mobs (NPC's) share many of the same data fields, but not all. So when a mob tries to access player data it gives a SYSERR like this:

SYSERR: Mob using >'((ch)-)player_specials-)saved.pref)' at act.wizard.c:127


The fix is actually a very easy one. All you have to do is make sure it only checks player data if it is a player. The way this is done in the code is with a non-player-character check. Now non-player-character (NPC) means it is a mob. So you need a double negative to make sure it is not a non-player-character. I know this is confusing, but just copy the example below.


- if (PRF_FLAGGED(ch, PRF_NOREPEAT)) // This line should be removed, hence the "-"

+ if (!IS_NPC(ch) && PRF_FLAGGED(ch, PRF_NOREPEAT)) // This line should be added without the "+"


The changed line now will not just check for a flag, instead it will check if it is a player (not an NPC) and it is flagged then continue.


I hope this helps and please report these (and any other bugs/SYSERR's) you find. I've corrected dozens of these and they keep cropping up, especially when you switch into a mob and try player commands.