From 626a05816428ca6c7d3490fabee040629d8c67be Mon Sep 17 00:00:00 2001 From: Dystopian Date: Tue, 24 Sep 2024 13:41:46 +0300 Subject: [PATCH 1/5] Fix unit being vanilla engineer --- addons/repair/XEH_postInit.sqf | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/addons/repair/XEH_postInit.sqf b/addons/repair/XEH_postInit.sqf index 2e9a9178ffd..4fc1eeb6694 100644 --- a/addons/repair/XEH_postInit.sqf +++ b/addons/repair/XEH_postInit.sqf @@ -39,12 +39,28 @@ ["CAManBase", "InitPost", { params ["_unit"]; - if !(local _unit && {_unit getUnitTrait "engineer"}) exitWith {}; + // getUnitTrait can return nil so check config instead + if (getNumber (configOf _unit >> "engineer") < 1) exitWith {}; + + // unit can be local here for both server and client so use CBA_fnc_execNextFrame for safe + [{ + params ["_unit"]; + if !(local _unit) exitWith {}; + private _isEngineer = _unit getUnitTrait "engineer"; + if (isNil "_isEngineer" || {_isEngineer isNotEqualTo true}) exitWith {}; + _unit setUnitTrait ["engineer", false]; + TRACE_3("setUnitTrait2",_unit,typeOf _unit,_unit getUnitTrait "engineer"); + }, _unit] call CBA_fnc_execNextFrame; + + if !(local _unit) exitWith {}; + private _isEngineer = _unit getUnitTrait "engineer"; + if (isNil "_isEngineer" || {_isEngineer isNotEqualTo true}) exitWith {}; _unit setUnitTrait ["engineer", false]; + TRACE_3("setUnitTrait1",_unit,typeOf _unit,_unit getUnitTrait "engineer"); + if (_unit getVariable ["ACE_IsEngineer", -1] isEqualTo -1) then { _unit setVariable ["ACE_IsEngineer", true, true]; }; - TRACE_3("setUnitTrait",_unit,typeOf _unit,_unit getUnitTrait "engineer"); }, true, [], true] call CBA_fnc_addClassEventHandler; From 4047f4e9c4191d945eca1ca64f57b6c2aeea2e49 Mon Sep 17 00:00:00 2001 From: Dystopian Date: Thu, 26 Sep 2024 20:27:56 +0300 Subject: [PATCH 2/5] Improve comment MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Jouni Järvinen --- addons/repair/XEH_postInit.sqf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/addons/repair/XEH_postInit.sqf b/addons/repair/XEH_postInit.sqf index 4fc1eeb6694..38effcb992b 100644 --- a/addons/repair/XEH_postInit.sqf +++ b/addons/repair/XEH_postInit.sqf @@ -42,7 +42,7 @@ // getUnitTrait can return nil so check config instead if (getNumber (configOf _unit >> "engineer") < 1) exitWith {}; - // unit can be local here for both server and client so use CBA_fnc_execNextFrame for safe + // unit can be local here for both server and client for one frame so use CBA_fnc_execNextFrame to be safe [{ params ["_unit"]; if !(local _unit) exitWith {}; From 0f03855f12b0535b7dd3c9e5cc88bad66c4eee24 Mon Sep 17 00:00:00 2001 From: Dystopian Date: Thu, 26 Sep 2024 22:23:37 +0300 Subject: [PATCH 3/5] Use getUnitTrait instead of config lookup --- addons/repair/XEH_postInit.sqf | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/addons/repair/XEH_postInit.sqf b/addons/repair/XEH_postInit.sqf index 38effcb992b..c0a16b424ad 100644 --- a/addons/repair/XEH_postInit.sqf +++ b/addons/repair/XEH_postInit.sqf @@ -39,24 +39,20 @@ ["CAManBase", "InitPost", { params ["_unit"]; - // getUnitTrait can return nil so check config instead - if (getNumber (configOf _unit >> "engineer") < 1) exitWith {}; + private _isEngineer = _unit getUnitTrait "engineer"; + if (isNil "_isEngineer" || {_isEngineer isNotEqualTo true}) exitWith {}; // unit can be local here for both server and client for one frame so use CBA_fnc_execNextFrame to be safe [{ params ["_unit"]; - if !(local _unit) exitWith {}; - private _isEngineer = _unit getUnitTrait "engineer"; - if (isNil "_isEngineer" || {_isEngineer isNotEqualTo true}) exitWith {}; + if !(local _unit && {_unit getUnitTrait "engineer"}) exitWith {}; _unit setUnitTrait ["engineer", false]; TRACE_3("setUnitTrait2",_unit,typeOf _unit,_unit getUnitTrait "engineer"); }, _unit] call CBA_fnc_execNextFrame; if !(local _unit) exitWith {}; - private _isEngineer = _unit getUnitTrait "engineer"; - if (isNil "_isEngineer" || {_isEngineer isNotEqualTo true}) exitWith {}; _unit setUnitTrait ["engineer", false]; - TRACE_3("setUnitTrait1",_unit,typeOf _unit,_unit getUnitTrait "engineer"); + TRACE_3("setUnitTrait1",_unit,typeOf _unit,_isEngineer); if (_unit getVariable ["ACE_IsEngineer", -1] isEqualTo -1) then { _unit setVariable ["ACE_IsEngineer", true, true]; From adfc1f0155391d09ebb3c580c115fe2c86f5d7bc Mon Sep 17 00:00:00 2001 From: Dystopian Date: Sat, 28 Sep 2024 02:55:55 +0300 Subject: [PATCH 4/5] Rework with locality pass waiting --- addons/repair/XEH_postInit.sqf | 31 +++++++++++++++++++------------ 1 file changed, 19 insertions(+), 12 deletions(-) diff --git a/addons/repair/XEH_postInit.sqf b/addons/repair/XEH_postInit.sqf index c0a16b424ad..7d6673a8c35 100644 --- a/addons/repair/XEH_postInit.sqf +++ b/addons/repair/XEH_postInit.sqf @@ -41,22 +41,29 @@ params ["_unit"]; private _isEngineer = _unit getUnitTrait "engineer"; if (isNil "_isEngineer" || {_isEngineer isNotEqualTo true}) exitWith {}; + TRACE_4("setUnitTrait 1",_unit,typeOf _unit,local _unit,ACE_player); - // unit can be local here for both server and client for one frame so use CBA_fnc_execNextFrame to be safe - [{ - params ["_unit"]; - if !(local _unit && {_unit getUnitTrait "engineer"}) exitWith {}; + if (local _unit) exitWith { _unit setUnitTrait ["engineer", false]; - TRACE_3("setUnitTrait2",_unit,typeOf _unit,_unit getUnitTrait "engineer"); - }, _unit] call CBA_fnc_execNextFrame; - if !(local _unit) exitWith {}; - _unit setUnitTrait ["engineer", false]; - TRACE_3("setUnitTrait1",_unit,typeOf _unit,_isEngineer); - - if (_unit getVariable ["ACE_IsEngineer", -1] isEqualTo -1) then { - _unit setVariable ["ACE_IsEngineer", true, true]; + if (_unit getVariable ["ACE_IsEngineer", -1] isEqualTo -1) then { + _unit setVariable ["ACE_IsEngineer", true, true]; + }; }; + + // handle delay of player locality pass + if (_unit isNotEqualTo ACE_player) exitWith {}; + [ + {local _this}, + { + params ["_unit"]; + TRACE_3("setUnitTrait 2",_unit,typeOf _unit,_unit getUnitTrait "engineer"); + _unit setUnitTrait ["engineer", false]; + }, + _unit, + 60, + {ERROR_3("setUnitTrait locality timeout unit=%1 type=%2 isEngineer=%3",_this,typeOf _this,_this getUnitTrait "engineer");} + ] call CBA_fnc_waitUntilAndExecute; }, true, [], true] call CBA_fnc_addClassEventHandler; From 404d7ea5ee58f4f3b802638aaf920c5753d3722a Mon Sep 17 00:00:00 2001 From: Dystopian Date: Sat, 28 Sep 2024 03:33:50 +0300 Subject: [PATCH 5/5] Replace CBA_fnc_waitUntilAndExecute with Local event --- addons/repair/XEH_postInit.sqf | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/addons/repair/XEH_postInit.sqf b/addons/repair/XEH_postInit.sqf index 7d6673a8c35..f75151bad26 100644 --- a/addons/repair/XEH_postInit.sqf +++ b/addons/repair/XEH_postInit.sqf @@ -53,17 +53,13 @@ // handle delay of player locality pass if (_unit isNotEqualTo ACE_player) exitWith {}; - [ - {local _this}, - { - params ["_unit"]; - TRACE_3("setUnitTrait 2",_unit,typeOf _unit,_unit getUnitTrait "engineer"); - _unit setUnitTrait ["engineer", false]; - }, - _unit, - 60, - {ERROR_3("setUnitTrait locality timeout unit=%1 type=%2 isEngineer=%3",_this,typeOf _this,_this getUnitTrait "engineer");} - ] call CBA_fnc_waitUntilAndExecute; + _unit addEventHandler ["Local", { + params ["_unit", "_isLocal"]; + if (!_isLocal) exitWith {}; + TRACE_3("setUnitTrait 2",_unit,typeOf _unit,_unit getUnitTrait "engineer"); + _unit setUnitTrait ["engineer", false]; + _unit removeEventHandler ["Local", _thisEventHandler]; + }]; }, true, [], true] call CBA_fnc_addClassEventHandler;