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);
|
|
|
|
|
2015-08-29 14:38:57 +00:00
|
|
|
private ["_attachedList", "_itemDisplayName", "_attachedObject", "_attachedIndex", "_itemName", "_minDistance"];
|
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
|
|
|
|
2015-02-15 14:31:09 +00:00
|
|
|
// Exit if can't add the item
|
|
|
|
if !(_unit canAdd _itemName) 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
|
|
|
};
|
|
|
|
|
2015-02-15 14:31:09 +00:00
|
|
|
// Add item to inventory
|
|
|
|
_unit addItem _itemName;
|
|
|
|
|
|
|
|
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
|
2015-06-13 19:08:21 +00:00
|
|
|
[{deleteVehicle (_this select 0)}, [_attachedObject], 2] call EFUNC(common,waitAndExecute);
|
2015-01-13 09:06:24 +00:00
|
|
|
} else {
|
2015-02-01 20:56:19 +00:00
|
|
|
// Delete attached item
|
|
|
|
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);
|