ID:814360
 
(See the best response by Stephen001.)
Code:
mob/Enemies
Wolf
icon='wolf.dmi'
icon_state=""
Level=10
Exp=30
MaxHP=50
Str=20
Def=15
Gold=5
Side = "Evil"

mob/Enemies/New()
src.HP=src.MaxHP
spawn(-1) src.CombatAI()
return ..()

mob/Enemies/proc/CombatAI()
if(isDead == TRUE)
return
while(src)
for(var/mob/player/M in oview())
if(get_dist(src,M)<=1)
src.dir=get_dir(src,M)
src.attack()
else
step_to(src,M)
break
sleep(rand(4,8))


Problem description: How do i stop the enemy from attacking when dead?

Let me ask you a question, if the enemy is Dead/Killed - is it deleted?
No
In response to Dr.Penguin (#2)
Dr.Penguin wrote:
No

Why not? removing the target would be the best idea.
when the enemy dies are u setting its var to isDead=1 ?
Best response
You need to move that isDead check into your while loop as well, so that while the CombatAI() is running, it'll check to see if the src is dead.

mob/Enemies/proc/CombatAI()
while(src)
if(isDead == TRUE)
return
for(var/mob/player/M in oview())
if(get_dist(src,M)<=1)
src.dir=get_dir(src,M)
src.attack()
else
step_to(src,M)
break
sleep(rand(4,8))