From 073805148b545d2aa1e1fcc5655cc0192210beb2 Mon Sep 17 00:00:00 2001 From: PabstMirror Date: Tue, 13 Jan 2015 03:06:24 -0600 Subject: [PATCH] Replace Spawn/Sleep in attach --- addons/attach/XEH_preInit.sqf | 1 + addons/attach/functions/fnc_detach.sqf | 19 ++++++---------- .../attach/functions/fnc_detachDelayFix.sqf | 22 +++++++++++++++++++ 3 files changed, 30 insertions(+), 12 deletions(-) create mode 100644 addons/attach/functions/fnc_detachDelayFix.sqf diff --git a/addons/attach/XEH_preInit.sqf b/addons/attach/XEH_preInit.sqf index bcbd7e543c..5efadc1f68 100644 --- a/addons/attach/XEH_preInit.sqf +++ b/addons/attach/XEH_preInit.sqf @@ -4,4 +4,5 @@ PREP(attach); PREP(canAttach); PREP(canDetach); PREP(detach); +PREP(detachDelayFix); PREP(openAttachUI); \ No newline at end of file diff --git a/addons/attach/functions/fnc_detach.sqf b/addons/attach/functions/fnc_detach.sqf index 5f50720d3e..07d1eda906 100644 --- a/addons/attach/functions/fnc_detach.sqf +++ b/addons/attach/functions/fnc_detach.sqf @@ -16,6 +16,7 @@ private ["_unit", "_itemName", "_count", "_attachedItem"]; _unit = _this select 0; _itemName = _unit getVariable [QGVAR(ItemName), ""]; +_attachedItem = _unit getVariable [QGVAR(Item), objNull]; // Check if unit has an attached item if (_itemName == "") exitWith {}; @@ -29,19 +30,13 @@ if ((count items _unit) + (count magazines _unit) <= _count) exitWith { if (_itemName == "B_IR_Grenade" or _itemName == "O_IR_Grenade" or _itemName == "I_IR_Grenade") then { // Hack for dealing with X_IR_Grenade effect not dissapearing on deleteVehicle - [_unit getVariable QGVAR(Item), _unit] spawn { - _attachedItem = _this select 0; - _unit = _this select 1; - detach _attachedItem; - _attachedItem setPos [getPos _unit select 0, getPos _unit select 1, (getPos _unit select 2) -1000]; - sleep 0.5; - deleteVehicle _attachedItem; - }; -} -else -{ + detach _attachedItem; + _attachedItem setPos [getPos _unit select 0, getPos _unit select 1, ((getPos _unit select 2) - 1000)]; + // Delete attached item after 0.5 seconds + [FUNC(detachFix), 0.5, [_attachedItem, (time + 0.5)]] call CBA_fnc_addPerFrameHandler; +} else { // Delete attached item - deleteVehicle (_unit getVariable QGVAR(Item)); + deleteVehicle _attachedItem; }; // Reset unit variables diff --git a/addons/attach/functions/fnc_detachDelayFix.sqf b/addons/attach/functions/fnc_detachDelayFix.sqf new file mode 100644 index 0000000000..b84761c9fe --- /dev/null +++ b/addons/attach/functions/fnc_detachDelayFix.sqf @@ -0,0 +1,22 @@ +/* + Name: ACE_attach_fnc_detachFix + + Author: Pabst Mirror + + Description: + Waits then deletes the object. Fixes IR_Grenade's effect not disapearing. + + Parameters: + 0: ARRAY - [OBJECT - item, NUMBER - time to wait until] + 1: NUMBER - CBA's PerFrameHandler ID +*/ + +_attachedItem = (_this select 0) select 0; +_waitUntilTime = (_this select 0) select 1; + +if (time < _waitUntilTime) exitWith {}; + +deleteVehicle _attachedItem; + +//Remove the frame handler +[(_this select 1)] call cba_fnc_removePerFrameHandler;