ID:141869
 
Code:
mob
verb
PK_AoETest_a()
var/mob/M
if(usr.psidelay == 1)
usr << "\red Please wait before using PSI again."
return
for(M in view(usr))
if(M.key != usr.key)
M.overlays+=image(icon='icon/pkflash.dmi',icon_state="explosion")//Overlay
////EFFECT//////////////////////////////////////////////////////////////
var/damage = src.PSI + 19 - M.defense
if(M.defense >= damage)
damage = 0
M.hp -= damage
M.updateHealth()
src.exp += M.giveexp
src.level_up()
view(M) << sound("sound/flash.wav",,,3,100)
////////////////////////////////////////////////////////////////////////


Problem description:I'm just messing around with different thing and i came up with this AoE verb.Well this peice of AoE coding only effects each mob one at a time when the user uses it. Any idea why?

It's because for() loops through them one at a time. To get them all to work (nearly) simultaneously, spawn() inside the for() loop. spawn() "splits" a proc, so to speak.
In response to Jeff8500
Normally using spawn() would have no benefit whatsoever, and would only make the process slower as a whole. DM is inherently single-threaded, but that doesn't even matter; a simple for() loop without sleep() or such procs already executes within a single tick so it's essentially all done 'at once' as far as everyone is concerned. He probably calls sleep() in one of the calls so that's why it's delayed; he needs to change that to spawn() or something else in those external procs, so their caller isn't delayed.

Jeff8500 wrote:
To get them all to work (nearly) simultaneously, spawn() inside the for() loop.

It's more 'nearly simultaneously' without spawning a new execution thread for each mob and just doing it normally, since they run one at a time. >_>