ID:139758
 
Code:
mob
AI
New()
..()
spawn() Wander()
NPC = 0
Enemy = 1
Resting = 0
target = null
stamina = 10
icon = 'icons.dmi'
var/Race_Alignment
Goblin
Race_Alignment = .Goblin
Archer
attack = 10
defense = 5
icon_state = "mob-2"

proc
Wander()
if(target)
if(get_dist(src, target) > 1)
step_to(src, target)
sleep(5)
else
Attack(target)
sleep(10)
else
get_target()
if(target)
sleep(5)
else
step_rand(src)
sleep(20)
spawn() Wander()

get_target()
for(var/mob/m in oview(2,src))
if(m==src.Race_Alignment) return
target = m
return


Problem description:
Basically the problem is this.
I have two npcs and they're from the same race (in this example goblin), they shouldn't attack each other. But in my code they attack each other and ignore me. What am i doing wrong?
I have two npcs and they're from the same race (in this example goblin), they shouldn't attack each other. But in my code they attack each other and ignore me. What am i doing wrong?

One problem is here:

                for(var/mob/m in oview(2,src))
if(m==src.Race_Alignment) return
target = m
return

You're using "return" in a for loop. That's not good unless you want to kill the loop entirely, because it kills the whole proc. Perhaps what you meant to use was "continue".

Another problem is that I don't think var/mob/m is compatible with var/Race_Alignment for a direct comparison like that. You might want to set var/Race_Alignment on all mobs and do a comparison of m.Race_Alignment instead.
In response to Geldonyetich
Ok. But that still doesn't stop the npcs from attacking another member of their race.
In response to Gamemakingdude
Gamemakingdude wrote:
Ok. But that still doesn't stop the npcs from attacking another member of their race.

Yeah, I was wondering about that. Maybe before you run that for loop you should set target to null again. It's also possible the race isn't being set. For example, maybe you painted the goblin to the map before you added that to the type, in which case it likely wasn't assigned to that instance of the goblin.
You are attempting to compare an actual mob (m) with a type path (Race_Alignment). You should instead be using istype().
In response to Garthor
Ah that's the problem. Forgot to do m.Race_Alignment

Thanks.