2015-01-11 20:39:49 +00:00
|
|
|
/*
|
2015-03-24 04:18:00 +00:00
|
|
|
* Author: eRazeri and esteldunedain
|
2015-02-01 20:56:19 +00:00
|
|
|
* Detach an item from a unit
|
|
|
|
*
|
|
|
|
* Arguments:
|
2015-03-27 05:02:54 +00:00
|
|
|
* 0: vehicle that it will be detached from (player or vehicle) <OBJECT>
|
|
|
|
* 1: unit doing the detaching (player) <OBJECT>
|
2015-02-01 20:56:19 +00:00
|
|
|
*
|
|
|
|
* Return Value:
|
|
|
|
* Nothing
|
|
|
|
*
|
|
|
|
* Example:
|
2015-03-27 05:02:54 +00:00
|
|
|
* [car, bob] call ace_attach_fnc_detach
|
2015-02-01 20:56:19 +00:00
|
|
|
*
|
|
|
|
* Public: No
|
|
|
|
*/
|
|
|
|
#include "script_component.hpp"
|
2015-01-11 20:39:49 +00:00
|
|
|
|
2015-08-04 22:47:31 +00:00
|
|
|
params ["_attachToVehicle","_unit"],
|
2015-08-06 18:17:59 +00:00
|
|
|
TRACE_2("params",_attachToVehicle,_unit);
|
|
|
|
|
2016-06-14 01:06:05 +00:00
|
|
|
private ["_attachedList", "_itemDisplayName", "_attachedObject", "_attachedIndex", "_itemName", "_minDistance", "_isChemlight"];
|
2015-08-28 21:57:16 +00:00
|
|
|
|
|
|
|
_attachedList = _attachToVehicle getVariable [QGVAR(attached), []];
|
2015-02-15 14:31:09 +00:00
|
|
|
|
2015-01-30 20:32:21 +00:00
|
|
|
_attachedObject = objNull;
|
|
|
|
_attachedIndex = -1;
|
|
|
|
_itemName = "";
|
|
|
|
|
|
|
|
//Find closest attached object
|
|
|
|
_minDistance = 1000;
|
2015-08-28 21:57:16 +00:00
|
|
|
|
2015-01-30 20:32:21 +00:00
|
|
|
{
|
2015-08-28 21:57:16 +00:00
|
|
|
_x params ["_xObject", "_xItemName"];
|
|
|
|
|
|
|
|
if (((getPos _unit) distance2d (getPos _xObject)) < _minDistance) then {
|
|
|
|
_minDistance = ((getPos _unit) distance2d (getPos _xObject));
|
|
|
|
_attachedObject = _xObject;
|
|
|
|
_itemName = _xItemName;
|
2015-02-01 20:56:19 +00:00
|
|
|
_attachedIndex = _forEachIndex;
|
|
|
|
};
|
2015-08-28 21:57:16 +00:00
|
|
|
} forEach _attachedList;
|
2015-01-11 20:39:49 +00:00
|
|
|
|
|
|
|
// Check if unit has an attached item
|
2015-02-15 14:31:09 +00:00
|
|
|
if (isNull _attachedObject || {_itemName == ""}) exitWith {ERROR("Could not find attached object")};
|
2015-01-11 20:39:49 +00:00
|
|
|
|
2016-06-14 01:06:05 +00:00
|
|
|
// Check if item is a chemlight
|
|
|
|
_isChemlight = _attachedObject isKindOf "Chemlight_base";
|
|
|
|
|
2015-02-15 14:31:09 +00:00
|
|
|
// Exit if can't add the item
|
2016-06-14 01:06:05 +00:00
|
|
|
if (!(_unit canAdd _itemName) && {!_isChemlight}) exitWith {
|
2015-05-28 19:59:04 +00:00
|
|
|
[localize LSTRING(Inventory_Full)] call EFUNC(common,displayTextStructured);
|
2015-01-11 20:39:49 +00:00
|
|
|
};
|
|
|
|
|
2016-06-14 01:06:05 +00:00
|
|
|
// Add item to inventory (unless it's a chemlight)
|
|
|
|
if (!_isChemlight) then {
|
|
|
|
_unit addItem _itemName;
|
|
|
|
};
|
2015-02-15 14:31:09 +00:00
|
|
|
|
|
|
|
if (toLower _itemName in ["b_ir_grenade", "o_ir_grenade", "i_ir_grenade"]) then {
|
2015-02-01 20:56:19 +00:00
|
|
|
// Hack for dealing with X_IR_Grenade effect not dissapearing on deleteVehicle
|
|
|
|
detach _attachedObject;
|
2015-02-15 14:31:09 +00:00
|
|
|
_attachedObject setPos ((getPos _unit) vectorAdd [0, 0, -1000]);
|
2015-02-01 20:56:19 +00:00
|
|
|
// Delete attached item after 0.5 seconds
|
2016-05-22 13:27:24 +00:00
|
|
|
[{deleteVehicle (_this select 0)}, [_attachedObject], 2] call CBA_fnc_waitAndExecute;
|
2015-01-13 09:06:24 +00:00
|
|
|
} else {
|
2016-08-27 08:19:39 +00:00
|
|
|
//handle any objects that may be attached to the object
|
|
|
|
{
|
|
|
|
detach _x;
|
|
|
|
deleteVehicle _x;
|
|
|
|
} forEach (attachedObjects _attachedObject);
|
|
|
|
|
2015-02-01 20:56:19 +00:00
|
|
|
// Delete attached item
|
2016-06-14 01:06:05 +00:00
|
|
|
detach _attachedObject;
|
2015-02-01 20:56:19 +00:00
|
|
|
deleteVehicle _attachedObject;
|
2015-01-11 20:39:49 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// Reset unit variables
|
2015-08-28 21:57:16 +00:00
|
|
|
_attachedList deleteAt _attachedIndex;
|
|
|
|
_attachToVehicle setVariable [QGVAR(attached), _attachedList, true];
|
2015-01-11 20:39:49 +00:00
|
|
|
|
|
|
|
// Display message
|
2015-04-10 01:49:50 +00:00
|
|
|
_itemDisplayName = getText (configFile >> "CfgWeapons" >> _itemName >> "displayName");
|
|
|
|
if (_itemDisplayName == "") then {
|
|
|
|
_itemDisplayName = getText (configFile >> "CfgMagazines" >> _itemName >> "displayName");
|
2015-01-11 20:39:49 +00:00
|
|
|
};
|
2015-04-10 01:49:50 +00:00
|
|
|
|
2015-05-28 19:59:04 +00:00
|
|
|
[format [localize LSTRING(Item_Detached), _itemDisplayName]] call EFUNC(common,displayTextStructured);
|