ID:145434
 
Okay, I have a very simple attacking code here, but when I use it a box pops up asking which enemy I want to attack. I want it to attack all the enemies within 1 square. How do I do this?
Code:
attack(mob/enemy/M as mob in oview(1))
var/tmp
damage
if(!M) return
if(atk < M.def) damage = 0
else
damage = ((atk + rand(0,luck)) - M.def)
src << "You did [damage] damage to [M]!"
M.hp -= damage
M.DeathCheck()


attack()
for(var/mob/enemy/M in oview(1))
var/tmp
damage
if(!M) return
if(atk < M.def) damage = 0
else
damage = ((atk + rand(0,luck)) - M.def)
src << "You did [damage] damage to [M]!"
M.hp -= damage
M.DeathCheck()

The way you HAD it, it asked you which mob you want to attack. When you use for(), it loops through all of the specified types and performs the following functions accordingly.

I only fixed what you said because I am in a hurry so I am not sure if anything else is wrong.
mob
verb
Attack()
for(var/mob/Enemy/M in oview(1,src))
var/Damage = 0
if(M)
if(src.Atk < M.Def) Damage = 0
else
Damage = ((src.Atk+rand(0,luck)-M.Def)
src << "You did [Damage] damage to the [M]!"
M.HP -= Damage
M.DeathCheck()
In response to Sniper Joe
Alright! Everything's perfect. Thank you.
In response to Hovercraft
Or ofcourse, you can just use get_step(usr, usr.dir) in a for() loop. This'll attack all mobs you're facing.