Jump to content
Sign in to follow this  
sowens

Damage Handler (set max damage to vehicle to no more than .9)

Recommended Posts

Thanks for taking a look at my post. I currently am working more on logistics in some of my maps. One of those I am trying to model is recoverable vehicles. Right now, I respawn a vehicle and set damage to it to .8 on the respawn. It works but it has some drawbacks, including not always looking the most elegant.

My question is, can you add a handler to set max damage to a vehicle never to exceed .9? My inability to figure out the answer led me to the solution above, and it works, but I think I would rather build the handler if possible.

Any suggestions? I have looked through some good places and came out blank on searches. I may be using the wrong terminology however. Thanks for your time.

Share this post


Link to post
Share on other sites
Thanks for taking a look at my post. I currently am working more on logistics in some of my maps. One of those I am trying to model is recoverable vehicles. Right now, I respawn a vehicle and set damage to it to .8 on the respawn. It works but it has some drawbacks, including not always looking the most elegant.

My question is, can you add a handler to set max damage to a vehicle never to exceed .9? My inability to figure out the answer led me to the solution above, and it works, but I think I would rather build the handler if possible.

Any suggestions? I have looked through some good places and came out blank on searches. I may be using the wrong terminology however. Thanks for your time.

Hi Sowens

It should be possible for you to add an eventhandler to prevent vehicles taking more than 0.9 damage. I wanted something similar for units so that they couldn't be killed, only knocked out, and AZCoder had an elegant solution. Look at this thread:

http://forums.bistudio.com/showthread.php?t=109904

Share this post


Link to post
Share on other sites

Thanks tpw...most appreciated on finding that!

Share this post


Link to post
Share on other sites
Thanks tpw...most appreciated on finding that!

No worries, give me a shout if you need any more help with it.

Share this post


Link to post
Share on other sites

It wasnt as simple as I though, but it is a good start for me. First attempt failed =)

---------- Post added at 07:02 PM ---------- Previous post was at 06:29 PM ----------

I have this...but I think its broke and I am not sure where best to put it to pick up new vehicles when adding to the mission...

addEventHandler ["handleVehicleDamage", { _this call handleVehicleDamage; }];

handleVehicleDamage = {
_unit			= _this select 0; 
_damage			= _this select 1;

private ["_dmg","_totalDmg"];
_dmg 	= _this select 2;

// calculate damage
_totalDmg = (damage _unit) + _dmg;

if (_totalDmg > 0.88) then
{ 
	// must set damage because this event handler prevents it
	_unit setDamage 0.88;
}
else
{
	// if total damage less than .88, set damage to total of existing damage plus handled damage
	_unit setDamage _totalDmg;
};
};

Any insight on how to get the vehicles to use this function would be super!

Edited by sowens

Share this post


Link to post
Share on other sites

anyone have suggestions on where I am messing up on the script and best place to put it? I tried putting in initServer.sqf as:

vehicleNameGoesHere addEventHandler ["handleVehicleDamage", { _this call handleVehicleDamage; }];

Share this post


Link to post
Share on other sites
anyone have suggestions on where I am messing up on the script and best place to put it? I tried putting in initServer.sqf as:

vehicleNameGoesHere addEventHandler ["handleVehicleDamage", { _this call handleVehicleDamage; }];

Sorry mate, I'm now on holidays away from my computer so can't really help too much.

Share this post


Link to post
Share on other sites

I changed it to

//addEventHandler ["HandleDamage", { _this call handleVehicleDamage; }]; 
//handleVehicleDamage = {
_unit			= _this select 0; 
_damage			= _this select 1;

private ["_dmg","_totalDmg"];
_dmg 	= _this select 2;
hint "I am in";
// calculate damage
_totalDmg = (damage _unit) + _dmg;

if (_totalDmg > 0.88) then
{ 
	// must set damage because this event handler prevents it
	_unit setDamage 0.88;
	hint "I am damaged";
}
else
{
	// if total damage less than .88, set damage to total of existing damage plus handled damage
	_unit setDamage _totalDmg;
};
//};

I then put in the init of the vehicle:

this addEventHandler ["HandleDamage", {_this execVM "client\vehicles\vehicleFunctions.sqf"}];

it works, sort of. The damage isn't being added correctly as three rifle shorts kills an armored truck. Getting closer.

Any suggestions from anyone?

Share this post


Link to post
Share on other sites

Does the handler void the armor of the vehicle? Might be why its not working as I thought.

Share this post


Link to post
Share on other sites

I haven't really used this, but when I first was reading about this event handler I remember in the description that one shot could result in multiple hit "events". Below is quoted from the below link in the BIS wiki.

It shows two shots at a soldier, once head, once torso. Overall it results in 5 hit events for each shot. Looking at the damage values some are actually greater than 1. Looking at your script it looks like you are adding each of these up.

Not sure of the difference when it is a vehicle you are shooting. But if each wheel can be damaged say upto 1 then a couple of shots into the wheel could result in a large accumulation of damage values.

I'm not at my arma machine to test sorry. You prob need to look at those damage values and apply them differently.

Example:

HANDLE = TargetSoldier addeventhandler ["HandleDamage",{diag_log text format ["T=%1 : %2", time, _this];_this select 2;} ];

When shooting the soldier once in the head, and once in the torso, ArmA2.RPT shows:

T=6.754 : [TargetSoldier,"",0.350463,B 1-1-A:1 (Matthijs),"B_556x45_Ball"]

T=6.754 : [TargetSoldier,"head_hit",3.23586,B 1-1-A:1 (Matthijs),"B_556x45_Ball"]

T=6.754 : [TargetSoldier,"body",0.0743558,B 1-1-A:1 (Matthijs),"B_556x45_Ball"]

T=6.754 : [TargetSoldier,"hands",0.667459,B 1-1-A:1 (Matthijs),"B_556x45_Ball"]

T=6.754 : [TargetSoldier,"legs",0.00307311,B 1-1-A:1 (Matthijs),"B_556x45_Ball"]

T=10.078 : [TargetSoldier,"",0.350179,B 1-1-A:1 (Matthijs),"B_556x45_Ball"]

T=10.078 : [TargetSoldier,"head_hit",0.230999,B 1-1-A:1 (Matthijs),"B_556x45_Ball"]

T=10.078 : [TargetSoldier,"body",1.52881,B 1-1-A:1 (Matthijs),"B_556x45_Ball"]

T=10.078 : [TargetSoldier,"hands",0.105206,B 1-1-A:1 (Matthijs),"B_556x45_Ball"]

T=10.078 : [TargetSoldier,"legs",0.0211435,B 1-1-A:1 (Matthijs),"B_556x45_Ball"]

http://community.bistudio.com/wiki/ArmA_2:_Event_Handlers#HandleDamage

Share this post


Link to post
Share on other sites

@sowens: Try lowering the percentage from .88 to .85 or less. Sometimes the damage applied can vary by .02, and if it hits .90 then it usually causes death or destruction.

For troubleshooting, try replacing the line 'hint "I am damaged"' with this:

player sideChat format["Damage: %1",_this];

That will give you a list of readings like blakeace shows for every round that hits.

Also the "_damage = select 1" is actually referencing the location that got hit, just fyi.

@blakeace: the "handleDamage" handler is supposed to prevent any damage at all, regardless of the number of hit events, as each event gets handled separately. So the damage caused by any hit is totally irrelevant.

What totalDmg calculation in the script does is grab the current damage to the unit, adds the damage caused by any single event hit, and checks if the new total is over 88%. Each shot will fire this event separately. Sometimes the _totalDmg value can be off by 2%, and 90% is generally death for a unit.

And one other thing: crashes don't count! Vehicles will still blow up if you crash them :D

Hope this helps.

Share this post


Link to post
Share on other sites

@blakeace: the "handleDamage" handler is supposed to prevent any damage at all, regardless of the number of hit events, as each event gets handled separately. So the damage caused by any hit is totally irrelevant.

What totalDmg calculation in the script does is grab the current damage to the unit, adds the damage caused by any single event hit, and checks if the new total is over 88%. Each shot will fire this event separately. Sometimes the _totalDmg value can be off by 2%, and 90% is generally death for a unit.

Yep exactly as I read it thanks, though as I read it I believe his main issue is that

The damage isn't being added correctly as three rifle shorts kills an armored truck. Getting closer.

Any suggestions from anyone?

Ok so I placed below in the init area of a vechile (hummer)

HANDLE = this addeventhandler ["HandleDamage",{diag_log text format ["T=%1 : %2", time, _this];_this select 2;} ];

Unlike the "infantry object" the results from the handler were

T=4.672 : [b 1-1-B:3,"",4.6913e-006,B 1-1-A:1 (Blake),"B_556x45_Ball"]

T=4.672 : [b 1-1-B:3,"",0.00151953,B 1-1-A:1 (Blake),"B_556x45_Ball"]

T=4.672 : [b 1-1-B:3,"glass1",0,B 1-1-A:1 (Blake),"B_556x45_Ball"]

T=4.672 : [b 1-1-B:3,"glass2",0,B 1-1-A:1 (Blake),"B_556x45_Ball"]

T=4.672 : [b 1-1-B:3,"glass3",0,B 1-1-A:1 (Blake),"B_556x45_Ball"]

T=4.672 : [b 1-1-B:3,"glass4",0,B 1-1-A:1 (Blake),"B_556x45_Ball"]

T=4.672 : [b 1-1-B:3,"wheel_1_1_steering",0.0374957,B 1-1-A:1 (Blake),"B_556x45_Ball"]

T=4.672 : [b 1-1-B:3,"",0.00182721,B 1-1-A:1 (Blake),"B_556x45_Ball"]

All values of the component damage recorded, and not applied to the object were very low. So if you added them all up and applied them via a setdamage they shouldn't kill a vehicle in three shots. Is it only one specific vehicle or all?

Try as AZCoder suggested with the sidechat to see all the damage values you are recording then applying as damage in the script.

Share this post


Link to post
Share on other sites

Yeah that's exactly it. Those little fractions add up, which explains the fluctuations. He's using a shortened version of a script I posted a ways back, and the basic trick is to lower the damage threshold. It would be nice to know which vehicle it is, because I haven't found it yet :D So far 88% has worked for me in all cases.

Share this post


Link to post
Share on other sites

It was the new armored and gunned PMC vehicle. I will give it a go on something else though. I appreciate the help from all of you.

---------- Post added at 08:32 AM ---------- Previous post was at 07:27 AM ----------

With the player sideChat format["Damage: %1",_this]; in the script, it looks like something is wrong. I killed an armored humvee with a m203.

Share this post


Link to post
Share on other sites

I am seeing this in the arma2oa.rpt

Error in expression <

private ["_unit"];

_unit = _this select 0;

_unit addEventHandler>

Error position: <_this select 0;

_unit addEventHandler>

Error Undefined variable in expression: _this

And this when shooting a vehicle with the handler:

[240005,30.2457,"3:05:13.373","0:01:19.670","x\ace\addons\sys_wounds\XEH_preInit.sqf",":",97,"PARAMS_1: _unit=O 1-2-I:1"]

[240005,30.2457,"3:05:13.373","0:01:19.670","x\ace\addons\sys_wounds\XEH_preInit.sqf",":",75,"PARAMS_1: _unit=O 1-2-I:1"]

[240005,30.2457,"3:05:13.373","0:01:19.670","x\ace\addons\sys_wounds\XEH_preInit.sqf",":",75,"PARAMS_1: _unit=O 1-2-I:1"]

[240006,30.5927,"3:05:13.402","0:01:19.706","x\ace\addons\sys_wounds\fnc_addEH.sqf",":",2,"PARAMS_1: _u=O 1-2-I:2"]

[240006,30.5927,"3:05:13.402","0:01:19.706","x\ace\addons\sys_wounds\fnc_addEH.sqf",":",3,"Adding HandleDamage Eventhandler: _u=O 1-2-I:2"]

[240006,30.5927,"3:05:13.403","0:01:19.706","x\ace\addons\sys_wounds\XEH_preInit.sqf",":",97,"PARAMS_1: _unit=O 1-2-I:2"]

[240006,30.5927,"3:05:13.403","0:01:19.706","x\ace\addons\sys_wounds\XEH_preInit.sqf",":",75,"PARAMS_1: _unit=O 1-2-I:2"]

[240006,30.5927,"3:05:13.403","0:01:19.706","x\ace\addons\sys_wounds\XEH_preInit.sqf",":",75,"PARAMS_1: _unit=O 1-2-I:2"]

Bad conversion: scalar

Bad conversion: scalar

Share this post


Link to post
Share on other sites

Oh, I was not using ACE. They have their own hooks for damage handling. For testing, you might try without ACE running, and please make sure ACE is up to date.

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  

×