Jump to content
celery

HandleDamage EH explained (+poor man's getHit)

Recommended Posts

That's what I thought too, but when I shot one of the AI teammates in the leg when testing, I did see his hint appear. I thought maybe it might not occur with real players, but I wasn't sure. I don't plan to have AI enabled in the mission that I plan to use these scripts in later. But first I need to figure out a way to get these 3 scripts to work together without conflicting. I figure there has to be a way to make it possible.

Share this post


Link to post
Share on other sites

You were testing in Single Player or Hosted right? In that case AI is controlled by the server, which is you, so you see the AI/server hints. :)

Share this post


Link to post
Share on other sites

So after much testing, I'm left to assume that if I use an EH HandleDamage on a player - that I am then unable to use an EH hit or EH Dammaged on the same player. Is this true? If it is true, is there any other possible way of using my health hint script?

Share this post


Link to post
Share on other sites

Your other EHs don't fire because your unit doesn't get overall damage.

Share this post


Link to post
Share on other sites

Is it possible to calculate the overall damage and the body part damage into 1 total and then have the health hints show the new total?

Share this post


Link to post
Share on other sites

This is what I am going to use in my mission. I can do without the headshot "ding" sound since there is no way to get it to work now, and it kind of sucks that the player doesn't show blood at all, but I think I think I'd rather trade those things for increased armor and accurate health hints. If there is a way to force the player to show blood on his body, please let me know. If it's possible I would like to make the player look bloody at certain health levels.

player init:

null = this execVM "hp.sqf";

hp.sqf:

_this setVariable ["selections", []];
_this setVariable ["gethit", []];
_this addEventHandler 
[
"HandleDamage",
{
	if (_this select 1 == "") then
	{
		_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.5;
		_gethit set [_i, _damage];
		_damage;
	};
}
];

_this addEventHandler 
[
"Hit",
{
	_dam = getDammage player;
	_dif = 1 - _dam;
	_total = _dif * 100;
	_hp = round _total;

	if ((_hp <=100) && (_hp >80)) then 
	{
		hintSilent composeText [parsetext format["<t size='1.2' align='center' color='#00FF00'>Health:</t><t size='1.2' align='center' color='#FFFFFF'> %1</t>", _hp]];
	};
	if ((_hp <80) && (_hp >60)) then 
	{
		hintSilent composeText [parsetext format["<t size='1.2' align='center' color='#CCFF00'>Health:</t><t size='1.2' align='center' color='#FFFFFF'> %1</t>", _hp]];
	}; 
	if ((_hp <60) && (_hp >40)) then 
	{
		hintSilent composeText [parsetext format["<t size='1.2' align='center' color='#FFFF00'>Health:</t><t size='1.2' align='center' color='#FFFFFF'> %1</t>", _hp]];
	};
	if ((_hp <40) && (_hp >20)) then 
	{
		hintSilent composeText [parsetext format["<t size='1.2' align='center' color='#FF9900'>Health:</t><t size='1.2' align='center' color='#FFFFFF'> %1</t>", _hp]];
	};
	if ((_hp <20) && (_hp >0)) then 
	{
		hintSilent composeText [parsetext format["<t size='1.2' align='center' color='#FF0000'>Health:</t><t size='1.2' align='center' color='#FFFFFF'> %1</t>", _hp]];
	};
	if (!alive player) then 
	{
		hintSilent composeText [parsetext format["<t size='1.2' align='center' color='#FF0000'>Health:</t><t size='1.2' align='center' color='#FFFFFF'> 0</t>"]];
	};
}
];

Celery, if some of the HandleDamage lines above are not needed, let me know which ones to remove.

I have never created a dialog before, but I would like to make one for the health hint messages if I can and have it appear in the bottom right corner, or someplace other than where the normal hint messages appear - and have it show the entire time. It wouldn't even need a background or anything. I just need it to show the text. I've done a lot of searching and found lots of stuff, but most all of it pertains to buttons and I found nothing that showed changing messages, so I was wondering if somebody might be able to point me in the right direction.

Share this post


Link to post
Share on other sites

You could track head damage and not apply any further damage that would go over the threshold of 0.9.

Share this post


Link to post
Share on other sites

I stuck some setHit stuff in where the hint messages appear. It tested ok and seemed convincing enough. Does it look ok to you?

player init:

this setVariable ["selections", []];
this setVariable ["gethit", []];
this addEventHandler 
[
"HandleDamage",
   	{
   		if (_this select 1 == "") then
   		{
   			_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.5;
   			_gethit set [_i, _damage];
   			_damage;
   		};
   	}
];
this addEventHandler 
[
   	"Hit",
   	{
	_unit = _this select 0;
   		_dam = getDammage _unit;
   		_dif = 1 - _dam;
   		_total = _dif * 100;
   		_hp = round _total;

   		if ((_hp <=100) && (_hp >80)) then 
   		{
   			_unit setHit ["hands", 0.9]; 
   			hintSilent composeText [parsetext format["<t size='1.4' align='center' color='#00FF00'>Health:</t><t size='1.4' align='center' color='#FFFFFF'> %1</t>", _hp]];
   		};
   		if ((_hp <80) && (_hp >60)) then 
   		{
		_unit setHit ["body", 0.9];
   			hintSilent composeText [parsetext format["<t size='1.4' align='center' color='#CCFF00'>Health:</t><t size='1.4' align='center' color='#FFFFFF'> %1</t>", _hp]];
   		}; 
   		if ((_hp <60) && (_hp >40)) then 
   		{
   			_unit setHit ["legs", 0.9];
   			hintSilent composeText [parsetext format["<t size='1.4' align='center' color='#FFFF00'>Health:</t><t size='1.4' align='center' color='#FFFFFF'> %1</t>", _hp]];
   		};
   		if ((_hp <40) && (_hp >20)) then 
   		{
			_unit setHit ["head", 0.9];
   			hintSilent composeText [parsetext format["<t size='1.4' align='center' color='#FF9900'>Health:</t><t size='1.4' align='center' color='#FFFFFF'> %1</t>", _hp]];
   		};
   		if ((_hp <20) && (_hp >0)) then 
   		{
		_unit setHit ["legs", 1];
   			hintSilent composeText [parsetext format["<t size='1.4' align='center' color='#FF0000'>Health:</t><t size='1.4' align='center' color='#FFFFFF'> %1</t>", _hp]];
   		};
   		if (!alive _unit) then 
   		{
   			_unit setHit ["hands", 1]; _unit setHit ["body", 1]; _unit setHit ["head", 1];
   			hintSilent composeText [parsetext format["<t size='1.4' align='center' color='#FF0000'>Health:</t><t size='1.4' align='center' color='#FFFFFF'> 0</t>"]];
   		};
   	}
];

Edited by A-SUICIDAL

Share this post


Link to post
Share on other sites

Ok, 2 hours later and this dialog stuff is already killing me. It's very hard to find samples. I went to armaholic browsed through the editing download section and downloaded anything that had a dialog box in the thumbnail preview, then I installed a few and tried to dissect them and learn how to make my own. I wish I could just pay somebody to make it for me since it's probably the easiest dialog for somebody to make that has any experience making dialogs, but I'll keep trying to figure it out on my own in the meantime. I feel like I'm in a science class - asking myself why am I learning this if I am never going to have any use for it later in life, lol. I just need the dialog for this one thing, then I'll probably never need to use a dialog ever again. And I need this dialog to be like it's part of the game, like a hud, so when it is on the screen, I can still run around and kill stuff. Most all of the dialogs I found can only be opened from an action and once they are open you cannot move, shoot or do anything until you close the dialog. I just need it to show small text in the bottom right corner of the screen that says "Health: 100" in bright green and the number value in white, and then incorporate my script into it somehow so it will give the current health value as the health value changes and change the word "Health:" from green to, yellowgreen, yellow, orange and finally red just before you die, just like the script above, if that's possible. Probabyl not. Or better yet, a picture of a red cross and a big green number next to it. The more arcade looking the better, lol. OFPEC site is under maintenance, so I can't read their dialog tutorial :(

Edited by A-SUICIDAL

Share this post


Link to post
Share on other sites

I tried applying the script to a vehicle. First I tried a littlebird chopper.

I placed a US rifleman (me) and set myself to allowDamage false;, then I placed 3 enemy M113's with their backs turned about 200 meters away, then I placed an empty littlebird AH-6J next to me and I then began to experiment with the script.

littlebird init.

this setVariable ["selections", []];
this setVariable ["gethit", []];
this addEventHandler 
[
"HandleDamage",
   	{
   		_veh = _this select 0;
   		_selections = _veh getVariable ["selections", []];
   		_gethit = _veh 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;
   	}
];

The littlebird took damage, but it definitely withstood many hits before the engine and rotor gave out and I was forced to land. I landed facing all 3 M113's about 20 meters away and I stayed in the chopper and watched as all my damage indicators turned red, except for the HULL which remained green. The enemy continued to fire for a long time, but the littlebird never blew up. I finally hopped out and touched off a satchel next to the chopper and that did blow it up.

This thread mostly discussed how to decrease the damage a player takes, but it didn't discuss vehicles much, so I wasn't sure if this script would even work well for a vehicle. Obviously somethings not working right if the littlebirds hull stayed green the entire time. So my question is... Is there a way to get this to work correctly for vehicles?

Share this post


Link to post
Share on other sites

It's a bug in Arma 2 that aircraft don't have a working hull damage indicator. The EH works as intended.

Share this post


Link to post
Share on other sites

What about the "crash exploding in flames" bug? I mean if you try and use a handledamage to prevent a chopper to take any damage, a collision with the ground will still blow it up.

And as i said in this thread once (dude this one got a lot of answers)

if you apply to it a damage eventhandler, it will not fire every time the chopper's hit, but mainly when a component is destroyed or almost destroyed [...]

if i shoot the tail rotor with a rifle, it will not display anything until said rotor is damaged enough for the chopper to start spinning.

Just thought you could enlighten me as to what's the satus on this? bug? myself being stupid? intended behaviour?

Share this post


Link to post
Share on other sites

Even if I set it to...

_damage = _olddamage + ((_this select 2) - _olddamage) * 1;

...the three M113's are unable to fully destroy (blow up) the littlebird with their 50 cals.

Is there a way to maybe setHit on the hull if the rest of the chopper parts are damaged?

For instance, this will make the tail rotor appear in red on the littlebirds damage indicator.

this setHit ["mala vrtule", 0.9];

I can't find the right command to make the hull appear red. Anybody know?

Share this post


Link to post
Share on other sites

Remove the EH to compare please.

Also:

It's a bug in Arma 2 that aircraft don't have a working hull damage indicator.

Share this post


Link to post
Share on other sites

With no EH I managed to fully destroy a littlebird with with just 100 rounds from a 50 cal. But with the EH using _damage = _olddamage + ((_this select 2) - _olddamage) * 1; 3 BTR 60's, 3 BMP2's, 3 BDRM's, 3 Shilkas, and 3 MM13's could not destroy the littlebird. lol, 15 tanks.

It's no big deal, I don't need to use the script for vehicles that bad. I just thought it would have been nice to some how give the littlebird a little extra armor, but I don't want to make it so it cannot be destroyed by the enemy vehicles I tested with, otherwise all of the enemy vehicles will run dry of ammo trying to fully destroy the chopper.

Share this post


Link to post
Share on other sites

Using the EH from the first post of the thread, I get the exact same result with and without it. Instead of relying on the AI to destroy your EH'd helicopter and comparing it to you destroying a non-EH'd helicopter, do both yourself.

Share this post


Link to post
Share on other sites

Yeah, I can destroy the chopper, but with the EH at * 1, it took me nearly 400 rounds to destroy the chopper. That much I already knew, but my concern is the AI since I won't be shooting at my own choppers, heh. I did copy the script from the first post and simply change the first 3 "_unit" to "this" and then stuck it into the chopper init. The AI could not destroy it at all when I tested with the enemy vehicles that I mentioned above.

I understand that there is a hull bug for aircraft, which kinda stinks, but the script still works well for land vehicles, which is cool, and I am extremely thankful for all your help and making that possible. I didn't test with other choppers, mainly because I'm not really concerned about the the other choppers too much. It's just the littlebird that seems to get shot down really easily, so I thought it would help to give it a little extra armor, but I can't allow the enemy AI tanks in my mission to go dry over the chopper. I once placed a static 50 cal in my mission and set it to "allowDamage false", that was a huge mistake since all the enemy went dry drying to destroy the gun.

My friends like to use the littlebird in my mission, but as soon as they get anywhere close to the enemy, they immediately get shot down. I thought with a little extra player armor and some extra littlebird armor - that it would give my friends a little bit more of a chance to actually kill something with the littlebird before getting shot down. I think the best bet is to just use the transport littlebird and remove the AH-6J from the mission, since it just causes too much frustration. Or I could leave it in the mission and set a very short abandoned time on it, but that would kinda stink too.

The script works great for with an HMMWV GPK. I have a few friends that will definitely like knowing that their favorite jeep just got a bit tougher.

Edited by A-SUICIDAL

Share this post


Link to post
Share on other sites

I finally learned how to create a dialog to use instead of hints that display the players current health in the bottom right corner, but I'm having problems with it where I use ctrlSetText and ctrlSetTextColor within the players init EH "hit". It's probably very simple to fix, I'm just not sure how. I didn't want to hijack this thread with it, so I posted about it here:

http://forums.bistudio.com/showthread.php?140559-ctrlSetText-problem&p=2230338&viewfull=1#post2230338

Any help getting this to work would be great. Thanks.

==============

Edited

Resolved :)

Edited by A-SUICIDAL

Share this post


Link to post
Share on other sites

Seems like we no longer need to accumulate total damage by plusing the old damage effects on the entity, engine can do it automatically since the latest update.

Share this post


Link to post
Share on other sites

Hello.

 

I think the "head_hit" part no longer exists. I guess it's "head" now. 

21:06:35 "PART:  || DAMAGE: 3.55783 || SOURCE: civ_2 || PROJECTILE: B_408_Ball || FRAME: 128530"
21:06:35 "PART: ? || DAMAGE: 0 || SOURCE: civ_2 || PROJECTILE: B_408_Ball || FRAME: 128530"
21:06:35 "PART: neck || DAMAGE: 0 || SOURCE: civ_2 || PROJECTILE: B_408_Ball || FRAME: 128530"
21:06:35 "PART: head || DAMAGE: 0 || SOURCE: civ_2 || PROJECTILE: B_408_Ball || FRAME: 128530"
21:06:35 "PART: pelvis || DAMAGE: 0 || SOURCE: civ_2 || PROJECTILE: B_408_Ball || FRAME: 128530"
21:06:35 "PART: spine1 || DAMAGE: 0 || SOURCE: civ_2 || PROJECTILE: B_408_Ball || FRAME: 128530"
21:06:35 "PART: spine2 || DAMAGE: 0 || SOURCE: civ_2 || PROJECTILE: B_408_Ball || FRAME: 128530"
21:06:35 "PART: spine3 || DAMAGE: 0 || SOURCE: civ_2 || PROJECTILE: B_408_Ball || FRAME: 128530"
21:06:35 "PART: body || DAMAGE: 0 || SOURCE: civ_2 || PROJECTILE: B_408_Ball || FRAME: 128530"
21:06:35 "PART: ? || DAMAGE: 0 || SOURCE: civ_2 || PROJECTILE: B_408_Ball || FRAME: 128530"
21:06:35 "PART: hands || DAMAGE: 0 || SOURCE: civ_2 || PROJECTILE: B_408_Ball || FRAME: 128530"
21:06:35 "PART: legs || DAMAGE: 0 || SOURCE: civ_2 || PROJECTILE: B_408_Ball || FRAME: 128530"
21:06:35 "PART:  || DAMAGE: 3.55783 || SOURCE: civ_2 || PROJECTILE:  || FRAME: 128530"

Share this post


Link to post
Share on other sites
Guest

Seems like we no longer need to accumulate total damage by plusing the old damage effects on the entity, engine can do it automatically since the latest update.

ffur2007slx2_5, what you mean? Arma 2 now have a getHit function?

 

 

HandleDamage event handler explained

There has been little documentation about how the "HandleDamage" (...)

Celery,

If you heal your self on an ambulance vehicle, you will stay in full health, but since poor man event handler will not run, for the records you will stay damaged, what is not true. Any fix?

Share this post


Link to post
Share on other sites

I added this code in unit init field

this addEventHandler ["HandleDamage", {}];

From biki and documentation, this should make unit invincible (unit should take NO DAMAGE). But instead unit will take damage as normal. Trying this on current stable version 1.64. 

 

Is HandleDamage broken at moment?

Share this post


Link to post
Share on other sites


this addEventHandler ["HandleDamage", {FALSE}]; // NO damage

this allowdamage false; // NO damage

--------------------------------------

this addEventHandler ["HandleDamage", {TRUE}]; // damage

this allowdamage true; // damage

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

×