Jump to content
CaptainMarkerCrunch

[Help] AI Units Getting Stuck in Unconcious State

Recommended Posts

Hello Glorious & Mighty Forums, I come bearing a simple call for help. (I'm still relatively new to Arma Scripting so go easy on me.)

I've written a script that essentially allows a player to "Revive" a downed AI unit when their damage reaches max (The AI Unit gets put into an unconscious state).

 

Spoiler

//Creator: Swedish_Gandalf Ie. Captain_Marker_Crunch
//Date Created: 2022-06-26
//Date Updated: 2022-06-26
//Desc: Incapacitates AI rather than kills on killing blow.
/*  Resources:
    https://forums.bohemia.net/forums/topic/220558-release-bossai-script-units-with-custom-hit-point-pools-amount-of-livesrevives-etc/
    https://forums.bohemia.net/forums/topic/205515-handledamage-event-handler-explained/
*/

//To Call Script:
//[this] spawn SWE_fnc_ReviveUnit;

_Debug = false; //Debug Option

// ----- Script

params ["_thisUnit"]; //Parametres

_thisUnit setVariable ["SWE_needRevive", false, true]; //Is Unit Already Down/In a Revivable State? -> False

_thisUnit addEventHandler ["HandleDamage",{

    params ["_unit", "_hitSelection", "_damage", "", "", "", "", ""]; //Parametres
    
    if (_unit getVariable "SWE_needRevive" == true) exitWith {0};
    
    if (_damage >= 1 || _unit getHit "" >= 1) exitWith {
        
        _unit setVariable ["SWE_needRevive", true, true]; //Is Unit Already Down/In a Revivable State? -> True
        
        _unit allowDamage false;
        _unit setDamage 0.5;
        _unit setUnconscious true;
        _unit setCaptive true;
        
        //Parametres for Function
        [
            _unit, // object the action is attached to
            "Revive", // Title of the action
            "\a3\ui_f\data\IGUI\Cfg\holdactions\holdAction_reviveMedic_ca.paa",	// Idle icon shown on screen
            "\a3\ui_f\data\IGUI\Cfg\holdactions\holdAction_reviveMedic_ca.paa",	// Progress icon shown on screen
            "(_this distance _target < 4) && (lifeState _target == ""INCAPACITATED"") && ([_this, ""FirstAidKit"", true] call BIS_fnc_hasItem)", // Condition for the action to be shown
            "_this distance _target < 4", // Condition for the action to progress
            {}, // Code executed when action starts
            { hintsilent format ["Healing Progress :%1 / 24", _this select 4] }, // Code executed on every progress tick
            {
                params ["_target", "_caller", "_actionId", "_arguments"];
                _caller removeItem "FirstAidKit"; //Removes a First Aid Kit From Revivers Inv.

                _target setDamage 0; //Set Units Damage to 'Healthy'
                _target setUnconscious false;
                _target allowDamage true;
                _target setCaptive false;
                _target setVariable ["SWE_needRevive", false, true]; //Is Unit Already Down/In a Revivable State? -> False
                    
            }, // Code executed on completion
            {}, // Code executed on interrupted
            [], // Arguments passed to the scripts as _this select 3
            2, // action duration in seconds
            nil, // priority
            true, // Remove on completion
            false // Show in unconscious state
            
        ] remoteExec ["BIS_fnc_holdActionAdd", 0, _unit]; // Calls Hardcoded Function - MP compatible implementation
        
        0;
        
    };
    
    _damage;

}];

 


The Script functions just as it should however I have noticed that every so often the unit will just get stuck in it's "downed" (unconscious) state. This seems to have a much higher chance of happening if the unit is run over in a vehicle. You can still revive and harm the unit while it's stuck, it just wont "Get up" ever again. I'm assuming it has to do with some element regarding the animation being interrupted.

I'm mostly asking if anyone encountered an issue similar to this before, or is seeing anything blatantly obvious that I've missed in my code.

Thanks!

Share this post


Link to post
Share on other sites

Is this for a solely SP mission? Or is it also MP?

BIS_fnc_holdActionAdd codes run local on player machine. setUnconscious requires a local argument.

Maybe you'd have to remoteExec it for it to work 100% of the time?

 

If locality is not the issue, then I'm probably not good to help you now. Never used setUnconscious before.

Share this post


Link to post
Share on other sites

It seems to me that your unit probably sometimes dies before the creation of the action via the event handler. As a condition for the making him in unconsciousness state, you do not use the unit's real damage, but a new one that will be added to the real one. Therefore, most likely in a situation where the unit already has 0.4 damage, and your shot will add 0.7 damage to it, the handler will not allow the unit to fall into an unconscious state, but simply skip this moment. Try using

((damage _unit + _damage) >= 1 || _unit getHit "" >= 1)

instead of

(_damage >= 1 || _unit getHit "" >= 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

×