From d06680e2a0bc03a47d9fb7f8dbfa4222d8ab75b2 Mon Sep 17 00:00:00 2001 From: PabstMirror Date: Sat, 29 Aug 2015 11:47:56 -0500 Subject: [PATCH] #1571 - Handle Null Attached Objects --- addons/attach/functions/fnc_canDetach.sqf | 10 +++++++++- addons/attach/functions/fnc_handleKilled.sqf | 5 +++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/addons/attach/functions/fnc_canDetach.sqf b/addons/attach/functions/fnc_canDetach.sqf index 303d0baf44..915295e6c9 100644 --- a/addons/attach/functions/fnc_canDetach.sqf +++ b/addons/attach/functions/fnc_canDetach.sqf @@ -19,13 +19,21 @@ params ["_attachToVehicle", "_unit"]; TRACE_2("params",_attachToVehicle,_unit); +_attachedList = _attachToVehicle getVariable [QGVAR(attached), []]; +if ((count _attachedList) == 0) exitWith {false}; + private ["_inRange"]; _inRange = false; { _x params ["_xObject"]; + if (isNull _xObject) exitWith { + TRACE_1("Null attached",_x); + _attachedList deleteAt _forEachIndex; + _attachToVehicle setVariable [QGVAR(attached), _attachedList, true]; + }; if (((getPos _unit) distance2d (getPos _xObject)) < 4) exitWith {_inRange = true}; -} forEach (_attachToVehicle getVariable [QGVAR(attached), []]); +} forEach _attachedList; _inRange && {(_unit == _attachToVehicle) || {canStand _unit}} && diff --git a/addons/attach/functions/fnc_handleKilled.sqf b/addons/attach/functions/fnc_handleKilled.sqf index 355360d95f..06c5473c88 100644 --- a/addons/attach/functions/fnc_handleKilled.sqf +++ b/addons/attach/functions/fnc_handleKilled.sqf @@ -29,6 +29,11 @@ if ((count _attachedList) == 0) exitWith {}; _x params ["_xObject"]; TRACE_2("detaching",_xObject,_deadUnit); detach _xObject; + //If it's a vehicle, also delete the attached + if (!(_deadUnit isKindOf "CAManBase")) then { + _xObject setPos ((getPos _deadUnit) vectorAdd [0, 0, -1000]); + [{deleteVehicle (_this select 0)}, [_xObject], 2] call EFUNC(common,waitAndExecute); + }; } forEach _attachedList; _deadUnit setVariable [QGVAR(attached), nil, true];