ACE3/addons/attach/functions/fnc_detach.sqf

87 lines
2.6 KiB
Plaintext
Raw Normal View History

#include "script_component.hpp"
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:
* 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:
* None
2015-02-01 20:56:19 +00:00
*
* Example:
* [car, bob] call ace_attach_fnc_detach
2015-02-01 20:56:19 +00:00
*
* Public: No
*/
2015-01-11 20:39:49 +00:00
params ["_attachToVehicle","_unit"],
2015-08-06 18:17:59 +00:00
TRACE_2("params",_attachToVehicle,_unit);
private _attachedList = _attachToVehicle getVariable [QGVAR(attached), []];
private _attachedObject = objNull;
private _attachedIndex = -1;
private _itemName = "";
//Find closest attached object
private _minDistance = 1000;
{
_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;
};
} 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
// Check if item is a chemlight
private _isChemlight = _attachedObject isKindOf "Chemlight_base";
2015-02-15 14:31:09 +00:00
// Exit if can't add the item
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
};
// 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
[{deleteVehicle (_this select 0)}, [_attachedObject], 2] call CBA_fnc_waitAndExecute;
2015-01-13 09:06:24 +00:00
} else {
//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
detach _attachedObject;
2015-02-01 20:56:19 +00:00
deleteVehicle _attachedObject;
2015-01-11 20:39:49 +00:00
};
// Reset unit variables
_attachedList deleteAt _attachedIndex;
_attachToVehicle setVariable [QGVAR(attached), _attachedList, true];
2015-01-11 20:39:49 +00:00
// Display message
private _itemDisplayName = getText (configFile >> "CfgWeapons" >> _itemName >> "displayName");
if (_itemDisplayName == "") then {
_itemDisplayName = getText (configFile >> "CfgMagazines" >> _itemName >> "displayName");
2015-01-11 20:39:49 +00:00
};
[format [localize LSTRING(Item_Detached), _itemDisplayName], 2] call EFUNC(common,displayTextStructured);