ID:140201
 
Code:
        verb
Fight(mob/M)
if(!M.client)
return
if(istype(M,/obj))
return
if(istype(M,/turf))
return
else
flick("punch",src)
var/damage = (src.str - M.def)
if(damage <= 0)
damage = 1
if(M.power == "Hawkins")
for(var/mob/B in M.basils)
if(!B)
M.hp -= damage
s_damage(M,damage,"red")
M.Health_Bar()
M.NDeath()
return
else
B.hp -= damage
s_damage(B,damage,"red")
B.Health_Bar()
B.NDeath()
return


Problem description:
First let me tell you what im trying to do:
EDIT: The fight(mob/M) is for NPC's.

Basically when someone attacks this player, i want it to check if there is any mob(s) in the list called basils. if there is, i want the damage to be redirected to one of the mobs in the list. Now this seems to be working fine, however, once the mob that the damage got redirected to is dead, he is removed from the list. and when there are no mobs in the list, i want the player himself to get the damage. however, the way i have set it up here, makes the player unhittable :P.

Probably because if(!B) is rubbish, what i want is for it to check for mobs, and if there are none, do damage to the player, if there are, redirect the damage.

so how do i check if it is empty if !B isn't the right way?

one thing i noticed is that you need to use "else if" instead of multiple if statements but i doubt that would fix your problem.

I also noticed that if you just want to tell if an object within a radius is a mob, you don't need to test if that object is an object or a turf, since your only interested in testing for other mobs.

Idk if any of that helps you any but it may be a start.
Delete the for() and use if(!M.basils)

Right now, you're looping through Basils. It finds nothing. Yet in the loop, you check if(!B), which will never trigger because the loop never begins in the first place.
In response to Emasym
this doesn't work either
In response to Narutostory
Because you probably didn't entirely get what I mean.
Basils, in my idea, should be a mob variable referencing a mob.

mob/var/tmp/mob/Basils
// Temp so it doesn't get saved.


When using the redirecting skill or whatever, you set Basils to the player/mob/whatever you're redirecting to.

mob/verb/Redirect_To(mob/M)
if(M) Basils=M


Then, in your code

if(B.Basils)
B.Basils.hp-=damage
else
B.hp-=damage