ID:175609
 
ok in a for would it be possible to see if theres somthing like for(var/mob/k in view()) and if theres k it does somthing and if there isnt it does somthing else

Because for some reason in this attack code It wont quite work, and im puzzeled how to fix, no dout it will be a simple fix...
    MonsterAttack()
for (var/mob/Allied/M in view())
if(!M)
for (var/mob/person/Player in view())
if (Player.client && Player.Health > 0)
Player.Victory()
if (Player.Bnum == Bnum && Player.client)
var/hitpercent=50+src.Dexterity
var/hitpercent2=hitpercent - Player.Agility
if(hitpercent2>100) hitpercent2 = 100
if(hitpercent2<0) hitpercent = 0
var/hitpercent3=rand(-5,80)
var/damagefirst=rand(src.Strength)
var/damagecount=damagefirst-Player.Defense
sleep(2)
if(hitpercent3 <= hitpercent2)
if(damagecount > 0){Player.Health -= damagecount;view()<<"<font size = 1><font color = red>[src] Attacks [Player] for [damagecount]";Player.DeathCheck()}
else
damagecount=1
Player.Health -= damagecount
view() << "<font size = 1><font color = red>[src] Attacks [Player] for [damagecount]";Player.DeathCheck()
else{view() << "<font size = 1><font color = green>[src] attacks [Player], but misses."}
if(M)
var/ok=rand(1,2)
if(ok==1)
for (var/mob/person/Player in view())
if (Player.client && Player.Health > 0)
Player.Victory()
if (M.Bnum == Bnum)
var/hitpercent=50+src.Dexterity
var/hitpercent2=hitpercent - M.Agility
if(hitpercent2>100) hitpercent2 = 100
if(hitpercent2<0) hitpercent = 0
var/hitpercent3=rand(-5,80)
var/damagefirst=rand(src.Strength)
var/damagecount=damagefirst-M.Defense
sleep(2)
if(hitpercent3 <= hitpercent2)
if(damagecount > 0){M.Health -= damagecount;view()<<"<font size = 1><font color = red>[src] Attacks [M] for [damagecount]";M.DeathCheck()}
if(M.Health<1)
if (istype(M,/mob/Allied)){del(M)}
else
damagecount=1
M.Health -= damagecount
if(M.Health<1)
if (istype(M,/mob/Allied)){del(M)}
view() << "<font size = 1><font color = red>[src] Attacks [M] for [damagecount]";M.DeathCheck()
else{view() << "<font size = 1><font color = green>[src] attacks [M], but misses."}
if(ok==2)
for (var/mob/person/Player in view())
if (Player.client && Player.Health > 0)
Player.Victory()
if (Player.Health > 0)
if (Player.Bnum == Bnum)
var/hitpercent=50+src.Dexterity
var/hitpercent2=hitpercent - Player.Agility
if(hitpercent2>100) hitpercent2 = 100
if(hitpercent2<0) hitpercent = 0
var/hitpercent3=rand(-5,80)
var/damagefirst=rand(src.Strength)
var/damagecount=damagefirst-Player.Defense
sleep(2)
if(hitpercent3 <= hitpercent2)
if(damagecount > 0){Player.Health -= damagecount;view()<<"<font size = 1><font color = red>[src] Attacks [Player] for [damagecount]";Player.DeathCheck()}
else
damagecount=1
Player.Health -= damagecount
view() << "<font size = 1><font color = red>[src] Attacks [Player] for [damagecount]";Player.DeathCheck()
else{view() << "<font size = 1><font color = green>[src] attacks [Player], but misses."}
else
if (Player.client && Player.Health > 0)
Player.Victory()
for (var/mob/person/P in view())
if (P.client && P.Health > 0)
var/hitpercent=50+src.Dexterity
var/hitpercent2=hitpercent - P.Agility
if(hitpercent2>100) hitpercent2 = 100
if(hitpercent2<0) hitpercent = 0
var/hitpercent3=rand(1,100)
var/damagefirst=rand(src.Strength)
var/damagecount=damagefirst-P.Defense
sleep(2)
if(hitpercent3 <= hitpercent2)
if(damagecount > 0){P.Health -= damagecount;view()<<"<font size = 1><font color = red>[src] Attacks [P] for [damagecount]";P.DeathCheck()}
else
damagecount=1
Player.Health -= damagecount
view() << "<font size = 1><font color = red>[src] Attacks [P] for [damagecount]";P.DeathCheck()
else{view() << "<font size = 1><font color = green>[src] attacks [M], but misses."}
else
if (Player.client && Player.Health > 0)
Player.Victory()
if (M.Bnum == Bnum)
var/hitpercent=50+src.Dexterity
var/hitpercent2=hitpercent - M.Agility
if(hitpercent2>100) hitpercent2 = 100
if(hitpercent2<0) hitpercent = 0
var/hitpercent3=rand(-5,80)
var/damagefirst=rand(src.Strength)
var/damagecount=damagefirst-M.Defense
sleep(2)
if(hitpercent3 <= hitpercent2)
if(damagecount > 0){M.Health -= damagecount;view()<<"<font size = 1><font color = red>[src] Attacks [M] for [damagecount]";M.DeathCheck()}
if(M.Health<1)
if (istype(M,/mob/Allied)){del(M)}
else
damagecount=1
M.Health -= damagecount
if(M.Health<1)
if (istype(M,/mob/Allied)){del(M)}
view() << "<font size = 1><font color = red>[src] Attacks [M] for [damagecount]";M.DeathCheck()
else{view() << "<font size = 1><font color = green>[src] attacks [M], but misses."}
var/mob/M
for(M in view())
doSomething
if(!M)
doSomethingElse
In response to Garthor (#1)
Thank you Garthor.