Jump to content
target_practice

'Dammaged' EH stops firing.

Recommended Posts

I've been using the 'dammaged' event handler to run code to update a healthbar for a vehicle. Initially it works fine but after a second or two it seems to stop triggering.

I've tested it by having various AI-controlled vehicles attack the vehicle in question.

I know it's the EH and not my code that's causing the problem (as I substituted dammaged with eachFrame and it worked fine) and while the biki mentions that the EH wouldn't fire for minor damage, in my tests the source remained consistent.

Share this post


Link to post
Share on other sites

Ah yes, sorry.

Event handler executing the code:

 _target addEventHandler ["Dammaged",{[_this select 0,116,117,20042] call BTP_fnc_sovproUIUpdateCVHealthBar;

And the function itself:

if (!hasInterface) exitWith{}; 

params [["_indicatedCV",objNull,[objNull]],["_progressBarIDC",nil,[0]],["_statusTextIDC",nil,[0]],["_displayIDD",nil,[0]]];

//Check that the passed object is a Command Vehicle
if !(_indicatedCV getVariable ["sovpro_attr_isCV",false]) exitWith {["Indicated object is not a command vehicle"] call BIS_fnc_error};

//Get the actual display
private _display = findDisplay _displayIDD;

//Get the controls from the display
private _progressBar = _display displayCtrl _progressBarIDC;
private _statusText = _display displayCtrl _statusTextIDC;

//Check that the indicated controls are the correct type
if ((ctrlType _progressBar != 8) or {ctrlType _statusText != 0}) exitWith {["Invalid control type"] call BIS_fnc_error};

//Retrieve the current damage level of the vehicle
_currentDamage = damage _indicatedCV;

//Convert damage into a percentage string, and set the text display with it
_healthPercent = 100 - 100*_currentDamage;
_healthPercentString = [str _healthPercent,"%"] joinString "";

_statusText ctrlSetText _healthPercentString;

//Use damage value to transition CT_PROGRESS colour from 100% green at 0 to 100% red at 1, and set its position to reflect the damage level
_progressBar ctrlSetTextColor [_currentDamage,(1 - _currentDamage),0,0.7];
_progressBar progressSetPosition (1 - _currentDamage);

 

Share this post


Link to post
Share on other sites

Did you try your function alone? say with a radio trigger instead of EH? That means to rework few things like another variable instead of _this select 0 in command line and a set damage. You could work easier than inside an EH and grab more detailed errors.

It seems to me you miss disableSerialization before working with _local variable for the display. I'm not sure, I can't test your display. Not vanilla Arma.

 

Share this post


Link to post
Share on other sites
8 hours ago, Grumpy Old Man said:

Bracket error in the very first line.

Check out some editors that support .sqf syntax highlighting.

 

Cheers

I'm not sure what you mean by 'bracket error', since to my understanding there are no syntax problems in this code.

EDIT: Sorry, I didn't realise you were referring to the first code box. That bracket error is only shown because I didn't copy-paste it properly and in the actual code it is not present.

As for syntax highlighting, I use NP++ with SQF highlighting.

 

8 hours ago, pierremgi said:

Did you try your function alone? say with a radio trigger instead of EH? That means to rework few things like another variable instead of _this select 0 in command line and a set damage. You could work easier than inside an EH and grab more detailed errors.

It seems to me you miss disableSerialization before working with _local variable for the display. I'm not sure, I can't test your display. Not vanilla Arma.

 

As mentioned in the OP, while I haven't tried it outside of an EH, when used in conjunction with an EachFrame handler, the desired outcome is produced.

Do keep in mind that the Dammaged EH works with the function for a few seconds before stopping.

 

I also haven't used the damaged passed by the EH itself as I am unsure as to whether it refers to overall damage or the damage to the specific part.

Share this post


Link to post
Share on other sites

So, the question is: are you sure the "dammaged" EH fires on your kind of vehicle? Also, some modded ones may have changed.

Try with other ones. Throw a hint. Some vehicles don't take damage, depending on caliber and some can pass from 0 to 1, independently of the hit parts. See this oooold video (min 2:50 and 4:00, sorry for the length). Test different calibers and vehicles.

Share this post


Link to post
Share on other sites
10 hours ago, pierremgi said:

So, the question is: are you sure the "dammaged" EH fires on your kind of vehicle? Also, some modded ones may have changed.

Try with other ones. Throw a hint. Some vehicles don't take damage, depending on caliber and some can pass from 0 to 1, independently of the hit parts. See this oooold video (min 2:50 and 4:00, sorry for the length). Test different calibers and vehicles.

The vehicle I have been testing with is a vanilla IFV-6c Panther (B_APC_Tracked_01_rcws_F).

 

I've tested the EH with a hint being used to return the damage of the vehicle, and now I believe I have determined the cause of my issue.

The documentation doesn't make this very clear, but the 'Dammaged' event handler only fires for damage sustained by vehicle parts, rather than for the entire hull.

I have confirmed this by using system chat to coincidentally report the damage returned by the EH (which I have found to be damage to the given vehicle part) and found that the EH ceased firing once this value reached 1.

 

It looks like I may need to use the 'Hit' EH instead, which is annoying as it will be difficult to ensure proper locality.

 

Also, for some reason not disabling serialization never caused any problems for me, despite me manipulating UI elements.

  • Like 1

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

×