ID:169889
 
Well, I made a foolproof PVP arena, except 1 thing.
If someone casts a spell, it inflicts damage upon them, too. I was wondering what I could replace/add in/make to fix this.

Here is the coding for a spell used:
//Player Versus Player//

proc/FireBolTP()
if (MP < 1+(fireboltlevel*2))
usr << "Not enough MP"
else // if you have enough MP
//find the closest enemy
var/list/J[1]
var/C = 1
var/mob/players/M
for(M as mob in oview(3))
if (istype(M,/mob/players))
J[C] = M
C++
J.len++
if(J[1]!=null) // if you found one
MP -= 1+(fireboltlevel*2) // decrement MP by cost
M = J[1] // reference to the enemy
missile(/obj/spells/firebolt,usr,M) // visuals
sleep(get_dist(usr,M)) // wait until the spell reaches the enemy
var/damage = round(((rand(2+(fireboltlevel*2),4+(fireboltlevel*3)))*((Intelligence/100)+1)),1) // calculate dmg
if(M) // exception catching, have to make sure that the enemy is still there
if (M.Fireres>0) // if it has resistance to fire
damage -= round(damage*(M.Fireres/100),1) // do less damage
M.HP -= damage // actually deal the damage
s_damage(M, damage, "red") // and show it
//usr << "You cast FireBolt for \blue[damage] damage"
checkdeadplayers(M) // checks to see if the enemy is dead
if(M == src)
return

that might work
Sinoflife wrote:
J[C] = M
C++
J.len++

This is very much wrong. You don't need to screw with J.len here because adding a new item to the list is enough to increase its length. And you're not adding to the list in the right way. (You're also not initializing it right, since it should not start with 1 element; it should be completely empty.)

This is what would be correct:
var/list/J = new
var/mob/players/M
for(M as mob in oview(3,src))
if(istype(M,/mob/players))
J += M


Of course it should go without saying, but apparently doesn't, that you should not have usr anywhere in this proc. That includes fixing oview() and other such calls that need to be oview(src) instead.

Lummox JR