ID:265037
 
Code:
mob/proc

Attack()
for(var/mob/M in get_step(src,dir))

if(attacked==1)
return
flick("attack[usr.icon_state]",src)
attacked=1


if(J_getatt(M))


var/_dmg = J_getdmg(M)

if(_dmg>0)
oview(5) << output("\red <small>[src.name] has hit [M.name].","info")
M.Hp-=_dmg
s_damage(M,_dmg, "red")
M.Bars(src)


if(M.Hp <= 0)
M.DeathCheck(src)

else
M << output("[src.name] tried to attack you but missed.","info")
src << output("You tried to attack [M.name] but you missed.","info")

else
M << output("[src.name] tried to attack you but missed.","info")
src << output("You tried to attack [M.name] but you missed.","info")

spawn(attack_delay)
attacked=0


Problem description:My character would attack himself some time when im in battle and sometimes my character attack the monster and sometimes my character attack himself. is there a code to prevent this from happing

Are you using pixel movement? If that's the case, it's because the way get_step works is it detects a mob in the direction the attacker is facing. Anything in the square next to the attacker in that direction is going to be hit by it. The way pixel movement is working is you can be in more than one square simultaneously, thus setting off the attack on yourself.

For a fix in that case, I suggest you look at http://www.byond.com/developer/forum/?id=795933

It's an engine made by Gravity Sandwich that shows you how to create a melee attack engine that goes by the new pixel movement BYOND has.
Attacking on a sidescroller game is different than on normal games, you normally have to include certain vars to make sure you won't attack yourself, please tell us more about your game, so we can figure out how can we help you (:
In response to Oondivinezin
the movement is kinda weird i guess byond updated before i starting making the game and i dont understand it at all
world
fps = 25
icon_size = 32
view = 9

mob
step_size = 4


obj
step_size = 8


other than that im not using any kind of weird movement but my mobs do all move weird tho i kinda thought at first it was the movement
In response to Oondivinezin
Thank it works thank you
maybe try adding somewhere

   if(src==usr)
return