The combat AI is already typed to only attack /Player mobs. You also shouldn't be checking if things ==null, instead, use something like if(!M.key).
Oh! My bad. I forgot I took that part out. Either way, if you want that bit taken out AND NPCs not to attack eachother because you don't want your mob to have a special path, that works too.
why does it say for me that level=1 is an undefined var
Capital Level?
When my enemy attacks once close to me, it disappears. What should i go?
In response to Michael.smith94
Posting the relevant code would be helpful.
i need help i put the combat ai proc in but it says this;179:error: M: undefined type: M for every line with 'M'
In response to Michael.smith94
Michael.smith94 wrote:
When my enemy attacks once close to me, it disappears. What should i go?


I think it's probably the flick, his enemy probably doesnt have the attack state.
I had the same issue with the disappearing enemies, except they were only visible when attacking. Turns out I forgot to specify a name for the enemy's walk state.

Another bit of weirdness I had was attacking myself if another enemy was out of range. Adding the following under the Attack verb right above the damage calculation cleared it up:

if (M == src) return 0

Thanks again for the Tutorials. They're a good kickstart even if they aren't perfect.
Hello Falacy
mob/monsters
Basic_Enemy
Troll
hp=10
maxhp=10
New()
src.oldx = src.x
src.oldy = src.y
src.oldz = src.z
src.oldexp = src.exp
src.odlhp= src.maxhp
src.blastable=1
src.oldzenni = src.zenni
..()
Move(var/turf/NewTurf,var/StepDir)
switch(StepDir)
if(NORTHWEST) pick(step(src,NORTH),step(src,WEST))
if(NORTHEAST) pick(step(src,NORTH),step(src,EAST))
if(SOUTHWEST) pick(step(src,SOUTH),step(src,WEST))
if(SOUTHEAST) pick(step(src,SOUTH),step(src,EAST))
else return ..(NewTurf,StepDir)
New()
..()
spawn(-1) src.CombatAI()
return ..()

mob/monsters/proc/CombatAI()
spawn while(src)
sleep(rand(15,18))
var/mob/target
target=locate(/mob/Player) in oview(11,src)
if(target)
while(src.blastable && target && get_dist(src,target)<8)
step_towards(src,target)
var/mob/a = ""
if(src.dir==NORTH && target.y == src.y +4 &&target.x == src.x) a = target
else if(src.dir==SOUTH && target.y==src.y -4 &&target.x == src.x) a = target
else if(src.dir==WEST && target.x == src.x -4 &&target.y == src.y) a = target
else if(src.dir==EAST && target.x == src.x +4 &&target.y == src.y) a = target
if(a != "")
src.Monster_Blast()
sleep(12)
else
src.exp = src.oldexp
src.aggresive = src.oldaggresive
src.zenni = src.oldzenni
src.hp=src.odlhp
src.loc = locate(src.oldx,src.oldy,src.oldz)


This is my AI system. But whenever I use this my CPU increase for 2%. What I want to do here is that when players are in AI oview(7-3) he will do projectile.
My goal is also to prevent AI from facing them diagonally!
I also want that if AI is in oview 2 he will walk to player and attack him once he is 1 step away from him. And while non player is in AI oview he will be teleported back to spawn and get his stats refreshed. Ty
mob/monsters/proc/CombatAI()
spawn while(src)
sleep(rand(15,18))
var/mob/target
target=locate(/mob/Player) in oview(11,src)
if(target)
while(src.blastable && target && get_dist(src,target)<8)
step_towards(src, target)
var/mob/a
if(get_dist(src, target) >= 3 && get_dist(src, target) <= 7)
a = target
if(a)
src.Monster_Blast()
sleep(12)
else
src.exp = src.oldexp
src.aggresive = src.oldaggresive
src.zenni = src.oldzenni
src.hp=src.odlhp
src.loc = locate(src.oldx,src.oldy,src.oldz)


There you go. Your code is a ton more complicated than it needs to be.

/mob/monster
name = "monster"
icon = 'monster.dmi'
desc = "a horrible green monster"
var/mob/target
var/speed = 5 //The lower the speed, the faster the monster is!

New()
..()
life()

proc/life()
if(!target) for(var/mob/M in view(7, src))
if(M.client)
target = M
break
if(target)
if(target in view(1, src)) attack(target)
else step_to(src, target)
else step_rand(src)
spawn(speed) .()

attack(var/mob/M as mob)
view(7, src) << "[src] claws [M]!"
ok i dont get this my enemy is not attacking watsoever it just sits there.. could it be because i set the enemy with map editor or wat??? btw yes ive been following since tut. 1
In response to Natasdrol
check to see if you capitalized the p for player when you defined it I did and the same thing happened to me eventually I decided to fiddle with it both player in the code and where you defined it should be lower case or upper case but those must be the same I think.
In response to Dark sage biko
a bit late mate
Page: 1 2