[BUG] A bug i found and fixed :P

Discussion in 'DZAI' started by Bushwookie420, Nov 18, 2013.

  1. Bushwookie420

    Bushwookie420 Well-Known Member

    Joined:
    Feb 7, 2013
    Messages:
    71
    Likes Received:
    25
    basically when the AI die after a few seconds they will play an animation were they wake up and die again if you shoot the AI in the head after they have done this it repeats the cycle they play the death animation after a few secs they wake up and die again you can repeat this forever now the way of fixing it is setting the AI to not being unconscious when they die and removing the damage handler from them so i added to dzai_functions.sqf inside of the DZAI_unitDeath function underneath
    _victim setVariable ["deathhandled",true];
    _victim setDamage 1;
    i added
    _victim setVariable ["unconscious",false];
    _victim removeAllEventHandlers "HandleDamage";
    _victim removeAllEventHandlers "Killed";
    _victim removeAllEventHandlers "Fired";
    so the full function is now
    Code:
    DZAI_unitDeath = {
        private["_victim","_killer","_unitGroup","_unitType"];
        _victim = _this select 0;
        _killer = _this select 1;
     
        if (_victim getVariable ["deathhandled",false]) exitWith {};
        _victim setVariable ["deathhandled",true];
        _victim setDamage 1;
        _victim setVariable ["unconscious",false];
        _victim removeAllEventHandlers "HandleDamage";
        _victim removeAllEventHandlers "Killed";
        _victim removeAllEventHandlers "Fired";
     
     
        _unitGroup = (group _victim);
        _unitType = _unitGroup getVariable ["unitType",""];
        switch (_unitType) do {
            case "static":
            {
                [_victim,_unitGroup] spawn DZAI_AI_killed_static;
            };
            case "dynamic":
            {
                [_victim,_unitGroup] spawn DZAI_AI_killed_dynamic;
            };
            case "air":
                _victim setVariable ["DZAI_deathTime",time];
                _victim removeWeapon "NVGoggles";
            {
            };
            case default {
                if (DZAI_debugMarkers > 0) then {
                    private ["_unitsAlive"];
                    if (({alive _x} count (units _unitGroup)) == 0) then {
                        {
                            deleteMarker (str _x);
                        } forEach (waypoints _unitGroup);
                    };
                };
            };
        };
     
        if (_unitType in ["static","dynamic"]) then {
            0 = [_victim,_killer,_unitGroup] call DZAI_AI_killed_all;
        };
        //diag_log format ["DEBUG :: AI %1 (Group %2) killed by %3",_victim,_unitGroup,_killer];
     
        true
    };
     
  2. Buttface

    Buttface OpenDayZ Rockstar!

    Joined:
    Dec 6, 2012
    Messages:
    599
    Likes Received:
    141
    Simply removing the handle damage event handler afer death should be enough to solve this issue. Thanks for reporting this.
     
  3. Bushwookie420

    Bushwookie420 Well-Known Member

    Joined:
    Feb 7, 2013
    Messages:
    71
    Likes Received:
    25
    i prefer to clean up it all :p
     
  4. Buttface

    Buttface OpenDayZ Rockstar!

    Joined:
    Dec 6, 2012
    Messages:
    599
    Likes Received:
    141
    Haha, we both have our own OCD tendencies it seems. Just to drive the point home, I spotted a significant typo I made in the code in the example you quoted and will be fixing that also.

    A bit of trivia: the only eventhandler added to the AI unit is a single HandleDamage EH, unless AI weapon noise is enabled, in which there's also a Fired EH. AI don't use any Killed EHs after 1.8.0.

    Because a unit's "unconscious" variable must be "false" (normal) in order to be set "true" (knocked out), manually setting the variable to "true" effectively prevents the unit from ever being knocked out. In a normal case when an AI is knocked out, there is a timer that sets a "true" value back to "false" after the unit regains consciousness, manually setting the variable means there's no such timer. AI helicopter units have their "unconscious" value set to "true" for exactly this reason, otherwise you would see their bodies fall flat while continuing to fly normally if they happen to take damage.
     

Share This Page