PROBLEM: when it kills two mobs (using a simple death proc which deletes npcs and respawns users)
it will afflict 2 more Wet people so 4 in total. but only if the first two were deleted. how do i stop this? i only want i to affect 2 people at a time, ive tried re-writting, and using break and continue but no luck.
MY DIAGNOSIS: i think that when the mobs are deleted in death() that M1 or M2 becomes null because the mob gets deleted? ive tried to fix it on this theory but my attempts, it leads me to beleive im wrong.
PS:basic timer is just a timer from my attempt to fix the problem, i really has no effect besides a delay between uses.
Code:
obj
Jutsu
var/Jdamage
Hurt_wets
icon = 'SHOP.dmi'
icon_state = "Sand_B"
jutsu = 1
Jlevel = 1
Click()
Hurt_wets()
verb
Hurt_wets()
var/mob/M2
var/mob/M1
var/damage = usr.chakrapower + 50
for(var/mob/M in ohearers())
if(src.basictimer==0)
if(M.Wet > 0)
if(M1 == null)
if(M1 == null)
if(M != M2)
M1 = M
if(M1.Wet == 1)
var/fdmg = damage
fdmg -= M1.clothing_defence
fdmg -= M1.defence
if(fdmg <0)
fdmg = 0
else
M1.health -= fdmg
M1.Wet = 0
flick("blood_splat",M1)
usr<<"happned[damage]"
M1.DeathCheck()
spawn(1)
if(M1 == null)
M1 = 1
spawn(9)
M1 = null
if(M2 == null)
if(M2 == null)
if(M != M1)
M2 = M
if(M2.Wet == 1)
var/FDMG = damage
FDMG -= M2.clothing_defence
FDMG -= M2.defence
if(FDMG <0)
FDMG = 0
else
M2.health -= FDMG
M2.Wet = 0
flick("blood_splat",M2)
usr<<"happned[damage]"
M2.DeathCheck()
spawn(1)
if(M2 == null)
M2 = 1
spawn(9)
M2 = null
else
break
PLEASE HELP ME, THANK-YOU for reading.
Secondly, why are you checking the exact same expression twice with if(M1 == null) and the same with M2? It's completely unnecessary and wastes resources by testing the exact same case twice.
Thirdly, to get to the root of your problem, you're using a for() loop in the completely wrong way. If you want to target two mobs in a for() loop doing one at a time, a quick and dirty way might look like this:
You'll have to do a little more work if you want it to calculate the distance and hit only the closest targets, but that's the basic jist of it. In its current state, it'll only hit the mobs with the lowest x and y position values, because those are the first mobs in the list.
Calculating mob distances is easy, you just take the whole list of myhearers and cycle through each one, getting the total distance from the centre. I suggest the Pythagorean Theorem since trig is always helpful. Make a list of the closest 2 mobs and use that. If two or more mobs share the same total distance, just pick one at random.
As for your code, I have no idea what it's even supposed to be doing, much less what it's actually doing. I think it would do you some good to hit the books back at square one and take it slowly.