Jump to content
Sign in to follow this  
RootinTootinShootin

HandleDamage Script Seems To Heal Player Occasionally

Recommended Posts

Hi everyone!

 

I know ARMA 3 wasn't built for it at all but I've been trying to make a couple "action movie" style Scenarios, using the following commonly suggested script to reduce player damage:

 

this setVariable ["selections", []];
this setVariable ["gethit", []];
this addEventHandler
[
"HandleDamage",
{
 _unit = _this select 0;
 _selections = _unit getVariable ["selections", []];
 _gethit = _unit getVariable ["gethit", []];
 _selection = _this select 1;
 if !(_selection in _selections) then
 {
  _selections set [count _selections, _selection];
  _gethit set [count _gethit, 0];
 };
 _i = _selections find _selection;
 _olddamage = _gethit select _i;
 _damage = _olddamage + ((_this select 2) - _olddamage) * 0.25;
 _gethit set [_i, _damage];
 _damage;
}
];

 

Now, I found this actually does its job most of the time (in vanilla at least), allowing the player to soak up a fair few shots before dying, but in certain situations it seemed like the enemies were taking longer than they should have to kill me - they'd unload what seemed like a couple clips into me, then I'd die kind of abruptly, making it seem almost random if the bullet dealt me damage or not.

 

I installed a Status Bar mod which gave my health as a percentage, and it seemed as though certain shots, especially when I was under fire from multiple enemies, seemed to be healing me.

 

There's every chance that the status bar mod was giving me an incorrect readout but what it was showing seemed to explain some previous issues I've had with this script - e.g. suddenly appearing to take no damage at all on one playthrough when I'd previously been able to tank around 10 or so shots from regular enemies before being killed.

 

Perhaps I was taking so much damage that the formula was trying to multiply a negative number, resulting in me being healed?

 

 

Thank you so much for taking a look at this post, any input is appreciated - I understand that ARMA wasn't built for things like this but with a Mission Editor THIS good it's always nice to have the option if you ask me!

Share this post


Link to post
Share on other sites

Actually, your script can't work because you're using 

 _selections = _unit getVariable ["selections", []];
 _gethit = _unit getVariable ["gethit", []];

to get some data, but you never use setVariable to update it 

Share this post


Link to post
Share on other sites
54 minutes ago, xjoker_ said:

Actually, your script can't work because you're using 


 _selections = _unit getVariable ["selections", []];
 _gethit = _unit getVariable ["gethit", []];

to get some data, but you never use setVariable to update it 

 

Intriguing!

 

It's not my script, it's just one that's been suggested in a number of threads around the web that seemed to do its job, some going back to ARMA II even.

 

I did wonder if maybe the _olddamage variable wasn't being reset after the hit or something like that, eventually leading to a negative number being multiplied, but I'm a complete coding newbie so I had no idea how I might try and implement something like that!

 

Any suggestions on what updating the variable would look like in the code?

 

Thank you for your response! :D

Share this post


Link to post
Share on other sites
15 hours ago, HazJ said:

These were how you did it in A2. Use the new commands available in A3.

https://community.bistudio.com/wiki/getHit

 

Ah, I thought there might have been something going on there - I'll have to explore how getHit works!

 

If anyone has any tips on how to start "translating" that script into ARMA 3 any thoughts would be very much appreciated!

 

 

Thanks so much for your responses so far. :D

Share this post


Link to post
Share on other sites

Hang on! This script from Conroy from four years ago seems to work perfectly!

player addeventhandler ["HandleDamage",{
_unit = _this select 0;
_selection = _this select 1;
_passedDamage = _this select 2;
_source = _this select 3;
_projectile = _this select 4;

_oldDamage = 0;

switch(_selection)do{
	case("head"):{_oldDamage = _unit getHitPointDamage "HitHead";};
	case("body"):{_oldDamage = _unit getHitPointDamage "HitBody";};
	case("hands"):{_oldDamage = _unit getHitPointDamage "HitHands";};
	case("legs"):{_oldDamage = _unit getHitPointDamage "HitLegs";};
	case(""):{_oldDamage = damage _unit;};
	default{};
};

_return = _oldDamage + ((_passedDamage - _oldDamage) / 20);

_return
}];

Maybe I just hadn't searched QUITE enough and kept turning up to the ARMA II projects!

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  

×