gruppe-adler / grad-replay

Records player and AI movment and replays at the end of the mission.
GNU General Public License v3.0
8 stars 1 forks source link

track shots #23

Closed McDiod closed 6 years ago

McDiod commented 6 years ago

Concept

Add FiredMan EH to all players (and all AI, if AI is being tracked):

_unit addEventHandler ["FiredMan", {
    params ["_unit", "", "", "", "", "", "_projectile", "_vehicle"];

    // a projectile is being tracked already
    if (_unit getVariable ["grad_replay_projectileTrackingRunning",false]) exitWith {};

    _unit setVariable ["grad_replay_projectileTrackingRunning",true];

    // track projectile
    _lastProjectilePos = [0,0,0];
    [{
        params ["_args","_handle"];
        _args params ["_projectile","_unit","_lastProjectilePos"];

        if (!isNull _projectile) then {
            _lastProjectilePos resize 0;
            _lastProjectilePos append (getPos _projectile);
        } else {
            _lastProjectilePos resize 2;
            _unit setVariable ["grad_replay_firedTarget",_lastProjectilePos];
            [_handle] call CBA_fnc_removePerFrameHandler;
            _unit setVariable ["grad_replay_projectileTrackingRunning",false];
        };
    },0,[_projectile,_unit,_lastProjectilePos]] call CBA_fnc_addPerFrameHandler;
}];

fn_startRecord:

...
_firedTarget = _unit getVariable "grad_replay_firedTarget";
if (!isNil "_firedTarget") then {
    /* do the saving */
    _unit setVariable ["grad_replay_firedTarget",nil];
};
...
nomisum commented 6 years ago

McDiod commented 6 years ago

Just leaving this here, in case its relevant. Haven't looked at it yet.

https://github.com/CBATeam/CBA_A3/blob/master/addons/diagnostic/fnc_projectileTracking_trackProjectile.sqf