ID:1786944
 
Keywords: dead, help, invincible
(See the best response by Lummox JR.)
Code:
mob
proc
/* death_check(mob/attacked,mob/attacker)
if(attacked.hp<=0&&attacked.in_battle==1)
death(attacked,attacker)*/

death_check(mob/attacked,mob/attacker)
if(attacked.hp<=0&&attacked.in_battle)
active_mobs-=attacked
attacked.Save()
attacker.Save()
if(attacked.lives>0&&attacked.in_battle)
attacked.lives--
attacked.icon_state="dead"
attacked.density=0
attacked.in_battle=0
if(attacked.character)world << "<font color=red><u>System:</font color=red><font color=yellow>[attacked.character] has become incapacitated by [attacker.character]!"
attacked << "<font color=red>System:</font color=red><font color=yellow>You will recover in 10 seconds."
spawn(100)
if(attacked.character==null||attacked.in_battle==1||attacked.dead==1)return
attacked.icon_state=""
attacked.density=1
attacked.in_battle=1
attacked.dead=0
active_mobs+=attacked
attacked.hp=80
attacked.cp=80
if(attacked.client)
attacked.client.eye=attacked
attacked.client.perspective=MOB_PERSPECTIVE
attacked.regen()
src.Update_Scores()
else
attacked.in_battle=0
attacked.density=0
attacked.dead=1
attacked.icon_state="dead"
attacked.dec_team(attacked)
attacker.gain_kill()
src.Update_Scores()
if(attacked.character)world << "<font color=red><u>System:</font color=red><font color=yellow>[attacked.character] has been defeated by [attacker.character]"
if(mode == MODE_FREE_FOR_ALL)
round_check()
mob
proc
damage(mob/attacked,mob/attacker,var/damage)
attacked.hp-=damage
if(attacked.can_attack==1)flick("damage",attacked)
if(attacked.client)attacked.update_HUD()
spawn()//0 is no point causes a loop
new/obj/effects/hit(attacked.loc)
if(attacked.hp<=0&&attacked.in_battle==1&&attacked.dead==0)attacked.death_check(attacked,attacker)


Problem description:For some reason, if a player comes back after being incapacitated their dead var sometimes becomes 1 making the person unkillable.

Best response
The death check proc should have only one argument: the attacker. The attacked mob should always be src. Damage is the same way: it should belong to the mob being damaged.
I get this runtime error now.
runtime error: type mismatch: 100 -= Edit Nero (/mob)
proc name: damage (/mob/proc/damage)
source file: 0.2 Combat.dm,13
usr: Edit Nero (/mob)
src: the tester (/mob/tester)
call stack:
the tester (/mob/tester): damage(the tester (/mob/tester), Edit Nero (/mob), 1.35)
Edit Nero (/mob): attack()


Here is the new damage proc:
mob
proc
damage(mob/attacker,var/damage)
src.hp-=damage
if(src.can_attack==1)flick("damage",src)
if(src.client)src.update_HUD()
spawn()//0 is no point causes a loop
new/obj/effects/hit(src.loc)
if(src.hp<=0&&src.in_battle==1&&src.dead==0)src.death_check(src,attacker)


and here is the new death proc:
mob
proc
/* death_check(mob/src,mob/attacker)
if(src.hp<=0&&src.in_battle==1)
death(src,attacker)*/

death_check(mob/attacker)
if(src.hp<=0&&src.in_battle)
active_mobs-=src
src.Save()
attacker.Save()
if(src.lives>0&&src.in_battle)
src.lives--
src.icon_state="dead"
src.density=0
src.in_battle=0
if(src.character)world << "<font color=red><u>System:</font color=red><font color=yellow>[src.character] has become incapacitated by [attacker.character]!"
src << "<font color=red>System:</font color=red><font color=yellow>You will recover in 10 seconds."
spawn(100)
if(src.character==null||src.in_battle==1||src.dead==1)return
src.icon_state=""
src.density=1
src.in_battle=1
src.dead=0
active_mobs+=src
src.hp=80
src.cp=80
if(src.client)
src.client.eye=src
src.client.perspective=MOB_PERSPECTIVE
src.regen()
src.Update_Scores()
else
src.in_battle=0
src.density=0
src.dead=1
src.icon_state="dead"
src.dec_team(src)
attacker.gain_kill()
src.Update_Scores()
if(src.character)world << "<font color=red><u>System:</font color=red><font color=yellow>[src.character] has been defeated by [attacker.character]"
if(mode == MODE_FREE_FOR_ALL)
round_check()
In response to Edit Nero
You're calling damage() incorrectly. The first argument should be the attacker. The one getting attacked is the owner of the proc, so it doesn't go in the arguments.
In response to Kaiochao
Eh, I'm confused.
Now that you've changed the args to death_check() and damage(), you need to change the way you call them.

In the last line of damage(), you're calling the death_check() proc with the old arguments. Instead you should call it as attacked.death_check(attacker).
Like so?
mob
proc
damage(mob/attacker,mob/attacked,var/damage)
src.hp-=damage
if(src.can_attack==1)flick("damage",src)
if(src.client)src.update_HUD()
spawn()//0 is no point causes a loop
new/obj/effects/hit(src.loc)
if(src.hp<=0&&src.in_battle==1&&src.dead==0)attacker.death_check(attacked)
No. You switched the attacked and attacker.
If I do it the other way, you won't be killed. That way you become incapacitated/killed.
attacker is the one attacking, attacked is the one taking the damage.
In the damage() proc, the correct way to call death_check is death_check(attacker). You don't need to call src.death_check(attacker) since src is already implied.
In response to Lummox JR
death_check(attacker) would check the person attacking not the person being attacked.
mob
proc
// attacker damages src
damage(attacker, damage)
hp -= damage
// etc.
death_check(attacker)

// check if attacker killed src
death_check(attacker)
if(hp <= 0)
// etc.

// src attacks his target (just an example)
attack(target)
// damage() is called on the target,
// so "src" in the "damage()" proc is "target" in this "attack()" proc.
// similarly, "attacker" in "damage()" is "src" in "attack()".
target.damage(src, 1000)
In response to Edit Nero
Edit Nero wrote:
Like so?
mob
> proc
> damage(mob/attacker,mob/attacked,var/damage)
> src.hp-=damage
> if(src.can_attack==1)flick("damage",src)
> if(src.client)src.update_HUD()
> spawn()//0 is no point causes a loop
> new/obj/effects/hit(src.loc)
> if(src.hp<=0&&src.in_battle==1&&src.dead==0)attacker.death_check(attacked)


So this way is incorrect? @Kaio
In response to Edit Nero
It's incorrect because you're essentially passing src to itself. The "attacked" in damage() will/should always be src.

I first responded to your runtime error, which said that you're calling damage in the form damage(attacker, attacked, damage) after you changed it to the form damage(attacker, damage). Basically, you fixed the arguments in damage(), but you didn't fix where you were calling damage().
Okay so I have this..
mob
proc
damage(mob/attacker,var/damage)
src.hp-=damage
if(src.can_attack==1)flick("damage",src)
if(src.client)src.update_HUD()
spawn()//0 is no point causes a loop
new/obj/effects/hit(src.loc)
if(src.hp<=0&&src.in_battle==1&&src.dead==0)death_check(attacker)

mob
proc
/* death_check(mob/src,mob/attacker)
if(src.hp<=0&&src.in_battle==1)
death(src,attacker)*/

death_check(mob/attacker)
if(src.hp<=0&&src.in_battle)
active_mobs-=src
src.Save()
attacker.Save()
if(src.lives>0&&src.in_battle)
src.lives--
src.icon_state="dead"
src.density=0
src.in_battle=0
if(src.character)world << "<font color=red><u>System:</font color=red><font color=yellow>[src.character] has become incapacitated by [attacker.character]!"
src << "<font color=red>System:</font color=red><font color=yellow>You will recover in 10 seconds."
spawn(100)
if(src.character==null||src.in_battle==1||src.dead==1)return
src.icon_state=""
src.density=1
src.in_battle=1
src.dead=0
active_mobs+=src
src.hp=80
src.cp=80
if(src.client)
src.client.eye=src
src.client.perspective=MOB_PERSPECTIVE
src.regen()
src.Update_Scores()
else
src.in_battle=0
src.density=0
src.dead=1
src.icon_state="dead"
src.dec_team(src)
attacker.gain_kill()
src.Update_Scores()
if(src.character)world << "<font color=red><u>System:</font color=red><font color=yellow>[src.character] has been defeated by [attacker.character]"
if(mode == MODE_FREE_FOR_ALL)
round_check()


mob/verb
attack()
set category=null
if(!can_attack||!in_battle)
return
else
can_attack=0
var/X=-32
var/vel=0
if(dir==EAST)
X=32
if(on_ground)
flick(pick("attackA","attackB","attackC","attackD"),usr)
if(vel_x>11||vel_x<-11)
flick("velocity attack",usr)
X=X*1.5
vel=1
sleep(2)
else
flick(pick("air attackA","air attackB"),usr)
sleep(1)
for(var/mob/M in obounds(usr,X,0,0))
if(M.team!=usr.team)
if(M.block==0)
M.damage(M,usr,usr.strength)
if(M.can_attack==1)flick("damage",M)
M.dir=get_dir(M,usr)
view(7) << pick('Sounds/HitA.wma','Sounds/HitB.wma','Sounds/HitC.wma','Sounds/HitD.wma')
if(vel==1||M.on_ground==0)
M.knockback2(M)
sleep(10)
else if(prob(20))M.knockback(M)
else if (prob(10))
M.stun(M)
else if(prob(10))
M.knockback2(M)
flick("velocity attack",usr)
else
flick("guard",M)
new/obj/effects/block(M)
M.dir=get_dir(M,usr)
view(7) << pick('BlockA.wav','BlockB.wav')
M.damage(M,src,src.strength/2)
sleep(2)
can_attack=1
return
view(7) << pick('SwingA.wav','SwingB.wav')
sleep(2)
can_attack=1


But I'm still getting the runtime error.
In response to Edit Nero
Your runtime error says that you're calling damage in the form damage(attacker, attacked, damage) after you changed the definition into the form damage(attacker, damage). Basically, you fixed the arguments in damage(), but you didn't fix where you were calling damage().

In attack(), you have M.damage(M, src, src.strength/2) or M.damage(M, usr, usr.strength). It should just be M.damage(src, strength/2) and M.damage(src, strength).

Whenever you're calling a proc like A.DoStuff(A, B, C), you probably have an unnecessary first argument of DoStuff(); it should just be A.DoStuff(B, C), where src becomes A automatically in DoStuff().
In response to Kaiochao
Okay, I've fixed attack() but when using Skills I get the runtime error as stated before, did you say how to fix?
You'll have to show us the skill procs to be sure. Undoubtedly though, you're doing the same thing: calling damage() incorrectly. As long as you call it in the form of victim.damage(attacker,amount) it should always behave correctly. If you change all your calls to damage() to use the right format, then any such issues should go away.
Here's one of the jutsus:
obj   
jutsu
bug_swarm
density=1
New()
..()
owner=usr
dir=usr.dir
walk(src,dir)
spawn(4)
del src
Move()
spawn(0)new/obj/jutsu/bug_hit(loc)
..()
Bump()
for(var/turf/T in view(3,src))
if(prob(35))new/obj/jutsu/bug_hit(T)
del src
Del()
for(var/mob/M in view(3,src))
if(M.team!=owner.team)
M.damage(M,owner,1)
M.swarm(M,16,0.5)
if(prob(35))M.chakradrain(M,16,0.5)
..()


mob
proc
bug_swarm()
if(bug_swarm)return
if(!jutsu_cooldown(10))return
if(!chakra_check(cp,7))return
spawn(3)
flick("specialA",usr)
spawn(4)
new/obj/jutsu/bug_swarm(loc)
bug_swarm=1
spawn(110)
bug_swarm=0
Page: 1 2