diff --git a/addons/events/fnc_addPlayerEventHandler.sqf b/addons/events/fnc_addPlayerEventHandler.sqf index 51bb69786..f4eb0997d 100644 --- a/addons/events/fnc_addPlayerEventHandler.sqf +++ b/addons/events/fnc_addPlayerEventHandler.sqf @@ -108,10 +108,6 @@ if (_id != -1) then { GVAR(playerEHInfo) pushBack addMissionEventHandler ["EachFrame", { private _player = call CBA_fnc_currentUnit; - if !(_player isEqualTo GVAR(oldUnit)) then { - [QGVAR(unitEvent), [_player, GVAR(oldUnit)]] call CBA_fnc_localEvent; - GVAR(oldUnit) = _player; - }; private _data = currentWeapon _player; if !(_data isEqualTo GVAR(oldWeapon)) then { @@ -140,12 +136,6 @@ if (_id != -1) then { }; }; - _data = vehicle _player; - if !(_data isEqualTo GVAR(oldVehicle)) then { - GVAR(oldVehicle) = _data; - [QGVAR(vehicleEvent), [_player, _data]] call CBA_fnc_localEvent; - }; - _data = _player call CBA_fnc_turretPath; if !(_data isEqualTo GVAR(oldTurret)) then { GVAR(oldTurret) = _data; @@ -163,13 +153,56 @@ if (_id != -1) then { GVAR(oldCameraView) = _data; [QGVAR(cameraViewEvent), [_player, _data]] call CBA_fnc_localEvent; }; + }]; + + GVAR(playerEHInfo) pushBack addMissionEventHandler ["PlayerViewChanged", { + private _player = call CBA_fnc_currentUnit; + + if !(_player isEqualTo GVAR(oldUnit)) then { + [QGVAR(unitEvent), [_player, GVAR(oldUnit)]] call CBA_fnc_localEvent; + GVAR(oldUnit) = _player; + }; + + private _data = vehicle _player; + if !(_data isEqualTo GVAR(oldVehicle)) then { + GVAR(oldVehicle) = _data; + [QGVAR(vehicleEvent), [_player, _data]] call CBA_fnc_localEvent; + }; + }]; + + GVAR(playerEHInfo) pushBack addMissionEventHandler ["Map", { + params ["_data"]; //visibleMap is updated one frame later - _data = visibleMap; if !(_data isEqualTo GVAR(oldVisibleMap)) then { GVAR(oldVisibleMap) = _data; - [QGVAR(visibleMapEvent), [_player, _data]] call CBA_fnc_localEvent; + [QGVAR(visibleMapEvent), [call CBA_fnc_currentUnit, _data]] call CBA_fnc_localEvent; }; }]; + + // emulate change to first value from default one frame later + // using spawn-dc to not having to wait for postInit to complete + 0 spawn { + { + private _player = call CBA_fnc_currentUnit; + + if !(_player isEqualTo GVAR(oldUnit)) then { + [QGVAR(unitEvent), [_player, GVAR(oldUnit)]] call CBA_fnc_localEvent; + GVAR(oldUnit) = _player; + }; + + private _data = vehicle _player; + if !(_data isEqualTo GVAR(oldVehicle)) then { + GVAR(oldVehicle) = _data; + [QGVAR(vehicleEvent), [_player, _data]] call CBA_fnc_localEvent; + }; + + _data = visibleMap; + if !(_data isEqualTo GVAR(oldVisibleMap)) then { + GVAR(oldVisibleMap) = _data; + [QGVAR(visibleMapEvent), [_player, _data]] call CBA_fnc_localEvent; + }; + } call CBA_fnc_directCall; + }; }; GVAR(playerEHInfo) pushBack [_type, _id]; diff --git a/addons/events/fnc_removePlayerEventHandler.sqf b/addons/events/fnc_removePlayerEventHandler.sqf index 2fe679bf7..428b4a519 100644 --- a/addons/events/fnc_removePlayerEventHandler.sqf +++ b/addons/events/fnc_removePlayerEventHandler.sqf @@ -57,8 +57,10 @@ default {nil}; if (!isNil QGVAR(playerEHInfo)) then { GVAR(playerEHInfo) deleteAt (GVAR(playerEHInfo) find [_type, _id]); - if (count GVAR(playerEHInfo) == 1) then { - removeMissionEventHandler ["EachFrame", GVAR(playerEHInfo) select 0]; + if (count GVAR(playerEHInfo) == 3) then { + removeMissionEventHandler ["EachFrame", GVAR(playerEHInfo) select 0]; + removeMissionEventHandler ["PlayerViewChanged", GVAR(playerEHInfo) select 1]; + removeMissionEventHandler ["Map", GVAR(playerEHInfo) select 2]; GVAR(playerEHInfo) = nil; }; };