Jump to content
Sign in to follow this  
chronicsilence

Preventing death without preventing all damage

Recommended Posts

I'm trying to set up a system where a player can take damage as normal up until they are near death, but can't actually die. I have found this very difficult to do with the HandleDamage event handler, because it's not clear what level of damage to which hit points might cause death. For example, a player could get a damage level of 1 to "spine1", but that won't kill them. But if they get damage level of 1 to "head", that will kill them. Does anyone know how to catch death just before it happens and override it? It would be perfect if there was a way to override the "Killed" event handler so it doesn't actually kill the player, but that doesn't seem to work.

 

Obviously solutions such as "allowDamage false" or returning 0 from the HandleDamage handler won't work because that will prevent ALL damage, which I don't want.

 

Thanks!

Share this post


Link to post
Share on other sites

The only way you can achieve this is handledamage. Every other approach will lead to inconsistency and the unplanned  death

You can add damage via the handledamage EH script in a controlled way using sethit or setdamage.

So run the EH so that the unit doesnt receive damage.

You can get the actual damage that would have occured from the EH (This is passed to the EH script as (_this select 3) according to the wiki entry

and then if adding that damage returns a getdamage value of less than 1, then add it.

So something like the following would be the way to go.

_u = _this select 0;
_hitdamage = _this select 3;
systemchat format ["<<DEBUG >> Hitdamage is %1",_hitdamage];
if(_hitDamage + (getdamage _u) >= 1)
     then{_u setdamage 0.9}
          else{_u setdamage ((getdamage _u) + _hitDamage)};

HandleDamage EH wiki entry

Share this post


Link to post
Share on other sites

The only way you can achieve this is handledamage. Every other approach will lead to inconsistency and the unplanned  death

You can add damage via the handledamage EH script in a controlled way using sethit or setdamage.

So run the EH so that the unit doesnt receive damage.

You can get the actual damage that would have occured from the EH (This is passed to the EH script as (_this select 3) according to the wiki entry

and then if adding that damage returns a getdamage value of less than 1, then add it.

So something like the following would be the way to go.

_u = _this select 0;
_hitdamage = _this select 3;
systemchat format ["<<DEBUG >> Hitdamage is %1",_hitdamage];
if(_hitDamage + (getdamage _u) >= 1)
     then{_u setdamage 0.9}
          else{_u setdamage ((getdamage _u) + _hitDamage)};

HandleDamage EH wiki entry

 

Thanks, a couple notes on this:

 

1) the "hitdamage" (_this select 3) is not the new damage, it's the cumulative damage (pre-existing damage plus new damage to the given selection).

 

2) some "selections" (hitpoints), like the player's hand, could get 100% damage but still not kill the player. What I need is a way to trigger a script every time a player would otherwise die, but I can't do this just by looking whether damage >= 1 because damage to certain selections can be 1 without killing the player ("hand_l", "spine1", "spine2", "spine3" being some examples of selections that can reach 100% damage without killing the player)

 

So what I really need is just some sort of trigger that fires when a player should die, but fires before death instead of after death (unlike the "Killed" EVH).

Share this post


Link to post
Share on other sites

Then you will most likely need to set up your own logging system for the damage received on the unit, probably best to store that in a setvariable array on the unit, where each element represents the damage to that part of the model.

 

On each Handledamage event, you can then calculate from the various array elements whether the unit would have died or not and if not add some damage to inapacitate the unit some more.

Maybe you can tie this in with a MPHit EH.

 

Another not so obvious system would be to have a KilledEH and a minimal respawndelay timer of something like 0.0001 seconds

The killed EH would then return the following

  • Units equipment, weapons uniform etc
  • stance
  • Position the unit was in
  • Direction he was facing

With this info, if you so wish,you can setpos the unit back to where he died, with the equipment he died instantaneously and not noticeable to the player.

I used such a system back in OFP to stop spawn camping in missions i made for a clan league and it was very effective.

 

The beauty of a KilledEH with base respawn is, you can make just about any respawn system you want with a supporting dialogue system like a spectate script.

You can hold them off "getting back into the game" for as long or as little as you like.

Relocate them wherever you want

You can add a killed ticket system, based on the unit itself, the group it is in or an overall side ticket counter.

You can even have the unit switch sides.

 

 

That as far as i know are the only 2 options that will give you consistency

Share this post


Link to post
Share on other sites

@chronicsilence or teron would you have a working copy of this script above an example mission. I am working on single player/Lan mission ongoing campaign however there is no working SP respawn function that I know of but this code above will work perfectly with a revive code that I am working on that will allow the player to team switch and find the unit that is damaged and unconscious but not killed during the mission. Help would be greatly appreciated.

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
Sign in to follow this  

×