ID:631810
 
(See the best response by DarkCampainger.)


Problem description:
I have been sitting here for some time now, what im trying to achieve is making Ai not attack the same village members, i'v done various things, such as

if(M.Village.Name==src.Village.Name)return
if(!M.Village.Name==src.Village.Name)//continues proc
if(M.Village.Name!=src.Village.Name)//continues proc



I have a mist ninja, and a leaf ninja in the spawn area, both having villages set to their retrospective villages, and my village to leaf as-well for testing purposes.
Now I have had it where either both attack or both don't attack. I have even added the same to any proc that leads to the enemy attacking, but no matter what I do they either both attack or don't.
What I am thinking of next is overriding bump, but I am unsure whether that will solve my problem hence I am here.

Any help would be greatly appreciated.
Theoretically, the first and third methods should be working. As they are not, it suggests a problem somewhere else in the code. I would add debug output to print the village of the AI and of the target to see what the values actually are.
        checkvillage(Ninja/M())
if(M!=src)
if(!M.Village==src.Village)
world<<"[src] from [Village] can attack [M] [M.Village]"
if(M.Village==src.Village)
world<<"[src] from [Village] cant attack [M] [M.Village]"
return



I tried this method as the debug message, but either way it came up as can attack.

This is my attack code for npc
Including the first option from my original post pretty much.

            Attack_damage2(crit,baserate=10,Damage,colour="ff0000",ccolour="ff0000")
if(canattack==0)return
if(Village==M.Village)return
for(var/Ninja/M in view(1,src)
var/l=rand(1,2)
if(l==1)
flick("Punch",src)
if(l==2)
flick("Kick",src)
Stamina.current-=5
M.beingattacked=1
canattack=0
timer=1
FaceTowards(M)
crit=round(Agi.current/50-M.Agi.current/75)+baserate
if(prob(crit))
Damage=round(Str.current*1.8-M.Def.current+Jyuuken+Weapondamage)
if(Damage<=0)
Damage=1
M.Health.current-=Damage;F_damage(M,Damage,ccolour)
if(istype(M,/Ninja/player))
M.GainExp(M.Def,rand(10,15))
Death(M)
else
Damage=round(Str.current*1.2-M.Def.current+Jyuuken+Weapondamage)
if(Damage<=0)
Damage=1
M.Health.current-=Damage;F_damage(M,Damage,colour)

Death(M)
sleep(Agi.Attackspeed)
canattack=1
timer=0
M.beingattacked=0

Best response
But what did it output? That was the whole point: to see what values it's actually comparing.

Also, if(M.Village.Name==src.Village.Name) and if(M.Village==src.Village) have a subtle difference, in that the latter requires that both variables be pointing to the same instance of the village.

Also, as I mentioned before, if(!M.Village==src.Village) will not do what you want. It will NOT M.Village, making it null, and then compare it to src.Village.

Also, you seem to have multiple M variables (one in the for() loop, and maybe one on the type?). They may be obfuscating things somewhat, as it's not really clear which mob your testing the village against. You need to be doing that within the loop, or better yet, take all of that code out of the loop and just use it to find a target:
Attack_damage2(crit,baserate=10,Damage,colour="ff0000",ccolour="ff0000")
if(canattack==0)return

var/Ninja/M
for(M in view(1,src))
if(M.Village == src.Village)
continue // Skip Ninjas from the same village
else
break // Valid target found

if(M) // If a valid target was found
// Do your attack stuff
// ...


Alright thanks alot this helped.
Thanks for the great advice