ID:264796
 
Code:Hello everybody, I have a problem in a code here.
This code is to make an NPC walk and if you think any player on the map, it goes behind the player to attack him. See the code

mob
var
rLocX
rLocY
rLocZ //The x, y and z co-ordinates to respawn at.
respawnSpeed = 10

mob/Mobs
Obasama
name="Oba Sama"
icon = 'Oba sama.dmi'
hp=50
Mhp=50
Str=3
Vit=1
Int=2
Dex=0
level=6
enemy=1
New()
. =..()
spawn(1)
src.rLocX = src.x
src.rLocY = src.y
src.rLocZ = src.z
WalkAround()
src.oldspot = src.loc
lol
for(var/mob/M in oview(6))
if(M.enemy||M.npc)
M.hp += 0
else
step_towards(src,M)
var/damage= src.Str+10
M.hp-=damage
view()<<"[M] Tomou [damage] de dano com um golpe de [src]!"
M.Death()
spawn(10)
goto lol
Death()
if(src.dead)
return
src.dead= 1
src.loc = null

Respawn()
var/newMonsterType = src.type
var/X = src.rLocX
var/Y = src.rLocY
var/Z = src.rLocZ
var/rSpeed = src.respawnSpeed
src = null
spawn(rSpeed)
new newMonsterType (locate(X, Y, Z))

mob/proc/Respawn()
usr.loc=locate(1,1,1)

mob/proc/Death()
if(npc==1||enemy==1)
return
if(usr.hp<=0)
for(var/mob/Clone/M in oview(9))
del(M)
for(var/mob/Puppet/M in oview(9))
del(M)
for(var/mob/SandaimePuppet/M in oview(9))
del(M)
usr.morto=1
usr.icon_state="dead"
sleep(50)
usr.dead=0
usr.wounds+=rand(1,5)
usr.deaths++
world<<"[src.nome] killed [usr]!"
src.kills++
usr.hp=usr.Mhp
usr.icon_state=""
if(usr.chakra<=0)
usr.Nadar()
if(usr.inwater==1&&usr.hp<=0)
usr.bed()


Problem description: The NPC goes and attacks normally, only when you will use the proc Death ()
The player does not die and when the player attacks the mob, he dies in an attack


The most obvious problem here is you're using usr in all the wrong places. Instead of using usr where you're currently using it, use src. That could possibly be the problem considering usr is meant to reference the player. src on the other hand is meant to reference the atom the proc is applied to.