ACE3/addons/attach/functions/fnc_detach.sqf

61 lines
1.9 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 ["_unit", "_itemName", "_count", "_attachedItem"];
_unit = _this select 0;
_itemName = _unit getVariable [QGVAR(ItemName), ""];
2015-01-13 09:06:24 +00:00
_attachedItem = _unit getVariable [QGVAR(Item), objNull];
2015-01-11 20:39:49 +00:00
// Check if unit has an attached item
if (_itemName == "") exitWith {};
// 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 05:14:27 +00:00
[localize "STR_AGM_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
2015-01-13 09:06:24 +00:00
detach _attachedItem;
_attachedItem setPos [getPos _unit select 0, getPos _unit select 1, ((getPos _unit select 2) - 1000)];
// Delete attached item after 0.5 seconds
[FUNC(detachFix), 0.5, [_attachedItem, (time + 0.5)]] call CBA_fnc_addPerFrameHandler;
} else {
2015-01-11 20:39:49 +00:00
// Delete attached item
2015-01-13 09:06:24 +00:00
deleteVehicle _attachedItem;
2015-01-11 20:39:49 +00:00
};
// Reset unit variables
_unit setVariable [QGVAR(ItemName),"", true];
_unit setVariable [QGVAR(Item),nil, true];
// Display message
switch true do {
case (_itemName == "AGM_IR_Strobe_Item") : {
2015-01-13 05:14:27 +00:00
[localize "STR_AGM_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 05:14:27 +00:00
[localize "STR_AGM_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 05:14:27 +00:00
[localize "STR_AGM_Attach_Chemlight_Detached"] call EFUNC(common,displayTextStructured);
2015-01-11 20:39:49 +00:00
};
default {
if (true) exitWith {};
};
};