ACE3/addons/attach/functions/fnc_detach.sqf

83 lines
2.7 KiB
Plaintext
Raw Normal View History

2015-01-11 20:39:49 +00:00
#include "script_component.hpp"
/*
Author: eRazeri and CAA-Picard
Detach an item from a unit
Arguments:
unit
Return Value:
none
*/
private ["_itemName", "_count", "_attachedItem", "_fnc_detachDelay"];
2015-01-11 20:39:49 +00:00
PARAMS_2(_unit, _attachToVehicle);
_attachedObjectsArray = _attachToVehicle getVariable ["ACE_AttachedObjects", []];
_attachedItemsArray = _attachToVehicle getVariable ["ACE_AttachedItemNames", []];
_attachedObject = objNull;
_attachedIndex = -1;
_itemName = "";
//Find closest attached object
_minDistance = 1000;
_unitPos = getPos _unit;
_unitPos set [2,0];
{
_objectPos = getPos _x;
_objectPos set [2, 0];
if ((_objectPos distance _unitPos) < _minDistance) then {
_minDistance = (_objectPos distance _unitPos);
_attachedObject = _x;
_itemName = _attachedItemsArray select _forEachIndex;
_attachedIndex = _forEachIndex;
};
} forEach _attachedObjectsArray;
2015-01-11 20:39:49 +00:00
// Check if unit has an attached item
if ((isNull _attachedObject) || {_itemName == ""}) exitWith {ERROR("Could not find attached object")};
2015-01-11 20:39:49 +00:00
// Add item to inventory
_count = (count items _unit) + (count magazines _unit);
_unit addItem _itemName;
if ((count items _unit) + (count magazines _unit) <= _count) exitWith {
2015-01-13 23:00:31 +00:00
[localize "STR_ACE_Attach_Inventory_Full"] call EFUNC(common,displayTextStructured);
2015-01-11 20:39:49 +00:00
};
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
detach _attachedObject;
_attachedObject setPos [getPos _unit select 0, getPos _unit select 1, ((getPos _unit select 2) - 1000)];
2015-01-13 09:06:24 +00:00
// Delete attached item after 0.5 seconds
2015-01-24 19:14:01 +00:00
_fnc_detachDelay = {
deleteVehicle (_this select 0);
};
[_fnc_detachDelay, [_attachedObject], 0.5, 0] call EFUNC(common,waitAndExecute);
2015-01-13 09:06:24 +00:00
} else {
2015-01-11 20:39:49 +00:00
// Delete attached item
deleteVehicle _attachedObject;
2015-01-11 20:39:49 +00:00
};
// Reset unit variables
_attachedObjectsArray deleteAt _attachedIndex;
_attachedItemsArray deleteAt _attachedIndex;
_attachToVehicle setVariable ["ACE_AttachedObjects", _attachedObjectsArray, true];
_attachToVehicle setVariable ["ACE_AttachedItemNames", _attachedItemsArray, true];
2015-01-11 20:39:49 +00:00
// Display message
switch true do {
2015-01-13 23:00:31 +00:00
case (_itemName == "ACE_IR_Strobe_Item") : {
[localize "STR_ACE_Attach_IrStrobe_Detached"] call EFUNC(common,displayTextStructured);
2015-01-11 20:39:49 +00:00
};
case (_itemName == "B_IR_Grenade" or _itemName == "O_IR_Grenade" or _itemName == "I_IR_Grenade") : {
2015-01-13 23:00:31 +00:00
[localize "STR_ACE_Attach_IrGrenade_Detached"] call EFUNC(common,displayTextStructured);
2015-01-11 20:39:49 +00:00
};
case (_itemName == "Chemlight_blue" or {_itemName == "Chemlight_green"} or {_itemName == "Chemlight_red"} or {_itemName == "Chemlight_yellow"}) : {
2015-01-13 23:00:31 +00:00
[localize "STR_ACE_Attach_Chemlight_Detached"] call EFUNC(common,displayTextStructured);
2015-01-11 20:39:49 +00:00
};
};