ID:376037
 
(See the best response by Stephen001.)
Code:
        proc/Wander(var/mob/Player/M)
while(src)
if(M in oview(5)) //if a Player comes in 5 steps pf him
step_towards(src,M) //Chase him!
for(M in oview(1)) //here you can define some stuff
break //if you want your NPC to shoot make it so
for(M in oview(2)) //these are saying if the Player is within 1,2,3,4 blocks do nothing
break
for(M in oview(3))
break
else
step_rand(src) //if no NPC is 5 blocks or less away walk around
sleep(10) //stop for 1 second
for(M in oview(4)) //.......
break
sleep(5)
spawn(5)
Wander()//Wonder again...
Bump(mob/Player/M)
if(M.player == 1) //If the NPC bumps you
if(!istype(src,M))
MFight(M)//Fight You!
else
return
Bump(mob/Player/Allies/M)
if(M.player == 1) //If the NPC bumps you
if(!istype(src,M))
MFight(M)//Fight You!
else
return
else
return


Having a problem trying to find a way to change the src to look for usr and other mob types without the proc trying to include turfs and objs

runtime error: undefined variable /turf/tree/var/player
proc name: Bump (/mob/Enemies/Bump)
source file: Monsters.dm,197
usr: Dark Warrior (/mob/Enemies/Dark_Warrior)
src: Dark Warrior (/mob/Enemies/Dark_Warrior)
call stack:
Dark Warrior (/mob/Enemies/Dark_Warrior): Bump(the tree (4,4,16) (/turf/tree))
guess you just need an if(istype(mob,M))
Best response
To be a little more verbose:

Bump(mob/Player/M)
if(M.player == 1) //If the NPC bumps you
if(!istype(src,M))
MFight(M)//Fight You!
else
return
Bump(mob/Player/Allies/M)
if(M.player == 1) //If the NPC bumps you
if(!istype(src,M))
MFight(M)//Fight You!
else
return
else
return


Your issue is that Bump() shall be called for anything you bump into. The argument classifier mob/Player/M does not guarantee that the only thing you'll have placed in there is a player, it's more a guide. What you'd want instead is to do something akin to the following:

Bump(atom/T)
if (istype(T,/mob))
var/mob/M = T
if(M.player == 1 && !istype(src,M)) //If the NPC bumps you
MFight(M) //Fight You!


Basically you only consider the rest of the code if the thing you happened to bump into, was a mob. You then do your player variable check (you can perhaps do this better than you have, but I assume you have your reasons), and check they are also not the same type as you (presumably to stop ... enemies attacking players of the same race?). If that's all met, you fight.