ID:171051
 
I need some help on my death check..

        DeathCheck(mob/M)
if(src.health < 1)
if(src.sheilds < 20)
src.dead=1
world<<"<small><font color = red><B>[src] has been killed by [M]!</small></font>"
if(src.shiptype=="Defasf")
//shortened
src.DeathEnd()
if(src.shiptype=="Asdsf")
//shortened

src.DeathEnd()
DeathEnd()
src.loc=locate(src.lx+1,src.ly-2,src.lz)
src.enemy = null
src.dead=null
del src.enemy_marker


The problem is that when the players health/sheild status start to go below 1 they dont die,What's wrong? I'd like it if someone could explain it to me.

~>Jiskuha
if(src.health <= 1||src.shields<=20)

It was that, or it was...
if(src.health <= 1&&src.shields<=20)

I think that was it.

[edit]Change all the "srcs" to M... me thinks.
In response to Hell Ramen

[edit]Change all the "srcs" to M... me thinks.

No no,src is the one dying M is the one attacking/killing.

~>Jiskuha
Well, procs aren't just running in the background the whole time. You have to call them, so, when a player has the potential to die (probably when he gets hurt), you need to call your DeathCheck proc. So, in your Attack verb, after the damage is calculated, probably (depends on the Attack verb, of course), you would call your DeathCheck() proc. Assuming that M represents the defender in the Attack verb and src represents the Attacker, or the 'source' of the Attack verb, you would call:
M.DeathCheck(src)


This means that BYOND will run DeatchCheck() with Attack()'s M as the src of the new proc and Attacks()'s src as the argument(In DeathCheck(mob/M), the "mob/M" part would be the argument) of DeathCheck.

EDIT: Basically, your problem is not in the DeathCheck proc itself, but in the way you are calling it.
Your code should be calling DeathEnd considering health is less than 1 and shields are less than 20 and if your shiptype is Defasf or Asdsf.

If you want it to work so if either health is down or shields are down then go for this:

        DeathCheck(mob/M)
if(src.health < 1||src.shields < 20)
src.dead=1
world<<"<small><font color = red><B>[src] has been killed by [M]!</small></font>"
if(src.shiptype=="Defasf")
//shortened
src.DeathEnd()
if(src.shiptype=="Asdsf")
//shortened

src.DeathEnd()
DeathEnd()
src.loc=locate(src.lx+1,src.ly-2,src.lz)
src.enemy = null
src.dead=null
del src.enemy_marker
In response to Wizkidd0123
No you can clearly see that M is the one killing and src is the one dying(read what the text message sent to the world said).
In response to Wizkidd0123
Wizkidd0123 wrote:
EDIT: Basically, your problem is not in the DeathCheck proc itself, but in the way you are calling it.

        Attack(mob/M)
step_to(src,enemy)
if(src.attack>25)
src.attack=0
src.enemy = null
del src.enemy_marker
if(!M.dead&&src.attack<25)
spawn() src.Attack(M)
//cut for length
M.health-=50
M.shields-=50
world<<"[M.health],[M.shields]"
M.DeathCheck(src)


I'm almost positive I'm calling it correctly.

~>Jiskuha
In response to DeathAwaitsU
That coding would make it so that if is health was less than 1 OR shields were less than 20. I could be wrong, but I assume that shields are like armor, or something.
In response to DeathAwaitsU
Ah,i see i was checking it wrong. Thanks DeathAwaits you.

~>Jiskuha
In response to Jiskuha
In that case, either health or shields must be great enough to bypass DeathCheck, so, to narrow down the problem, we'll put in debug messages:
        DeathCheck(mob/M)
src << "Test 1 passed"
if(src.health < 1)
src << "Test 2 passed; health=[health]"
if(src.sheilds < 20)
src << "Test 3 passed; shields=[shields]"


Tell me what this outputs. If Test 1 fails, then we know the proc is being called wrong, if Test 2 fails, then helath must be greater than 1, if Test 3 fails, than shields must be greater than 0. Once we know what's wrong, we can easily work with it.
In response to Wizkidd0123
DeathAwaitsU wrote:
Your code should be calling DeathEnd considering health is less than 1 and shields are less than 20 and if your shiptype is Defasf or Asdsf.

If you want it to work so if either health is down or shields are down then go for this:

I know.
In response to DeathAwaitsU
Ohhhhh. Thank you; I misunderstood.
Sorry, I misunderstood, what you wanted. For the proc to work when health is below 1 OR shields are below 20, you need the || operator. The "||" operator is used to mean "OR". So, let's look at the following example:
if(A||B)
src << "You've won!!"

This means, that if expression A is true, then it will output "You've won!!". If expression B is true, it will output "You've won!!". If both expression A and expression B are true, it will output "You've won!!". However, if neither expression is true, then the if() statement will return null and obciously, it won't output anything.

Anyway, looking back at the problem with this new piece of knowledge, we can now approach it like this:
        DeathCheck(mob/M)
if(health<1||shields<20)
src.dead=1
//Rest of the stuff down here
In response to Wizkidd0123
It's great to see more people explaining stuff on the forum, but I'd like to add something. The logical OR operator continues as soon as it hits a true statement.
if( 1 || 2 )
world << "I didn't even notice a 2 there because the first statement was true!"


It's useful knowledge if you're Thoedis or anyone else who likes to have things move as fast as possible, as you can put the statement that's more likely to be true first. =)