ID:1958909
 
(See the best response by Ter13.)
in my project, the mobs have their density set to 0 (there are reasons for that) and you can only attack mobs in your loc. the attack verb kinda goes like this (i simplified it because the original one is like 30 lines long, but this follows the same concept):

mob/verb
attack()
var/mob/enemy/E
if (E in view(0)-usr) //as i said it has to be in your loc
E.hp -= usr.dmg
E.deathcheck()


so what happens is, i want the player to attack one enemy at a time, but if there is a plurality of enemies in its location, it attacks them all together in one click (this wouldn't happen in a project were the mob's density is 1, unfortunately that's not the case)

how do i make it so that only 1 enemy is attacked every time i click the attack verb, when there are 2 or more enemies in usr.loc?

Best response
mob/verb
attack()
var/mob/enemy/E = locate(/mob/enemy) in obounds(src)
if(E)
E.hp -= dmg
E.deathcheck()


The shortened version of your code does no looping and can in no way do what you are describing, so it doesn't follow the same theory of your original function as you said.

Without seeing your original function, I can't offer much better advice, but in theory the above code should work for you provided you adapt it to the particulars of your game.