ID:1253859
 
(See the best response by LordAndrew.)
So after updating my whole combat system from a tutorial, everything worked fine but I noticed that when you are facing a certain direction (both NPC and player), they start attacking themselves. My NPC monsters tend to kill themselves A LOT and its really annoying. Its always a different direction every time, so like when im facing north and I attack I start doing damage on myself. Same thing with the monsters. I can't find the problem.. hopefully someone here can see it. Here is all of my code containing something to do with the combat:

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

mob/Enemies/proc/CombatAI()
while(src)
for(var/mob/Player/M in oview())
if(get_dist(src,M)<=1)
src.dir=get_dir(src,M)
src.Attack()
flick("attack",src)
sleep(rand(20,40))
else
if(get_dist(src,M)<=2)
step_to(src,M)
flick("walking",src)
break
sleep(rand(4,8))

-------------------

mob

verb
Attack()
flick("attack",src)
for(var/mob/M in get_step(src,src.dir))
var/Damage=rand(0,str)
view(M)<<"[src] hit [M] for [Damage] Damage!"
M.TakeDamage(Damage,src)

--------------------

DeathCheck(var/mob/Killer)
if(src.HP<=0)
if(src.client)
world<<"[Killer] Killed [src]!"
src.HP=src.MaxHP
src.loc=locate(5,5,1)
else
Killer<<"You Killed [src] for [src.exp] Exp"
Killer.exp+=src.exp
Killer.LevelCheck()
del src
TakeDamage(var/Damage,var/mob/Attacker)
src.HP-=Damage
src.DeathCheck(Attacker)


(The dashes separate different code files)
Wrap the code in <dm>code here </dm>
If you're utilizing pixel movement, then it's possible to hit yourself because you can occupy multiple locations at a time when you're offset between them. You'll want to add a check to make sure you're not hitting yourself, or just disinclude whatever's attacking from the list of possible targets.
How would I disinclude the attacker from attacking himself? Sorry, I'm pretty new to all of this and still learning a bit about all of this
In response to Kolvin
Best response
In your for statement, you could do:

for (var/mob/m in get_step(src, dir))
// If the mob is the thing attacking, skip over hitting it.
if (m == src) continue

// damage stuff goes here.
Ohh, I see. Thank you very much

Everything works perfectly now :)
tyvm for this is post help me with same problem