ACE3/addons/respawn/functions/fnc_restoreGear.sqf

203 lines
4.7 KiB
Plaintext
Raw Normal View History

2015-01-12 09:07:03 +00:00
/*
Name: ACE_Respawn_fnc_restoreGear
Author(s):
bux578
Description:
Restores previously saved gear
Parameters:
0: OBJECT - unit
1: ARRAY<String, Array, ...> - Array containing all gear (result of ACE_common_fnc_getAllGear)
Returns:
VOID
2015-01-12 09:07:03 +00:00
*/
#include "script_component.hpp"
2015-04-17 23:13:09 +00:00
PARAMS_2(_unit,_allGear);
2015-01-12 09:07:03 +00:00
private ["_unit", "_allGear", "_headgear", "_goggles",
"_uniform", "_uniformitems",
"_vest", "_vestitems",
"_backpack", "_backpackitems", "_backpa",
"_primaryweapon", "_primaryweaponitems", "_primaryweaponmagazine",
"_secondaryweapon", "_secondaryweaponitems", "_secondaryweaponmagazine",
"_handgunweapon", "_handgunweaponitems", "_handgunweaponmagazine",
"_assigneditems", "_binocular",
"_activeWeaponAndMuzzle", "_activeWeapon", "_activeMuzzle", "_activeWeaponMode"];
2015-01-12 09:07:03 +00:00
// remove all starting gear of a player
removeAllWeapons _unit;
removeGoggles _unit;
removeHeadgear _unit;
removeVest _unit;
removeUniform _unit;
removeAllAssignedItems _unit;
clearAllItemsFromBackpack _unit;
removeBackpack _unit;
_headgear = _allGear select 0;
_goggles = _allGear select 1;
_uniform = _allGear select 2;
_uniformitems = _allGear select 3;
_vest = _allGear select 4;
_vestitems = _allGear select 5;
_backpack = _allGear select 6;
_backpackitems = _allGear select 7;
_primaryweapon = _allGear select 8;
_primaryweaponitems = _allGear select 9;
_primaryweaponmagazine = _allGear select 10;
_secondaryweapon = _allGear select 11;
_secondaryweaponitems = _allGear select 12;
_secondaryweaponmagazine = _allGear select 13;
_handgunweapon = _allGear select 14;
_handgunweaponitems = _allGear select 15;
_handgunweaponmagazine = _allGear select 16;
_assigneditems = _allGear select 17;
_binocular = _allGear select 18;
_activeWeaponAndMuzzle = _allGear select 19;
2015-01-12 09:07:03 +00:00
// start restoring the items
if (_headgear != "") then {
2015-01-13 14:28:03 +00:00
_unit addHeadgear _headgear;
2015-01-12 09:07:03 +00:00
};
if (_uniform != "") then {
2015-01-13 14:28:03 +00:00
_unit forceAddUniform _uniform;
2015-01-12 09:07:03 +00:00
};
if (_vest != "") then {
2015-01-13 14:28:03 +00:00
_unit addVest _vest;
2015-01-12 09:07:03 +00:00
};
if (_goggles != "") then {
2015-01-13 14:28:03 +00:00
_unit addGoggles _goggles;
2015-01-12 09:07:03 +00:00
};
{
2015-01-13 14:28:03 +00:00
_unit addItemToUniform _x;
} forEach _uniformitems;
2015-01-12 09:07:03 +00:00
{
2015-01-13 14:28:03 +00:00
_unit addItemToVest _x;
} forEach _vestitems;
2015-01-12 09:07:03 +00:00
2015-04-14 23:50:58 +00:00
private "_flagRemoveDummyBag";
_flagRemoveDummyBag = false;
2015-01-12 09:07:03 +00:00
if (format["%1", _backpack] != "") then {
2015-01-13 14:28:03 +00:00
_unit addBackpack _backpack;
_backpa = unitBackpack _unit;
clearMagazineCargoGlobal _backpa;
clearWeaponCargoGlobal _backpa;
clearItemCargoGlobal _backpa;
{
_unit addItemToBackpack _x;
} forEach _backpackitems;
2015-04-14 23:50:58 +00:00
} else {
// dummy backpack to ensure mags being loaded
_unit addBackpack "B_Kitbag_Base";
_flagRemoveDummyBag = true;
2015-01-12 09:07:03 +00:00
};
// primaryWeapon
if ((_primaryweapon != "") && {_primaryweapon != "ACE_FakePrimaryWeapon"}) then {
2015-01-13 14:28:03 +00:00
{
_unit addMagazine _x;
} forEach _primaryweaponmagazine;
2015-01-12 09:07:03 +00:00
2015-01-13 14:28:03 +00:00
_unit addWeapon _primaryweapon;
2015-01-12 09:07:03 +00:00
2015-01-13 14:28:03 +00:00
{
if (_x != "") then {
_unit addPrimaryWeaponItem _x;
};
} forEach _primaryweaponitems;
2015-01-12 09:07:03 +00:00
};
// secondaryWeapon
if (_secondaryweapon != "") then {
2015-01-13 14:28:03 +00:00
{
_unit addMagazine _x;
} forEach _secondaryweaponmagazine;
2015-01-12 09:07:03 +00:00
2015-01-13 14:28:03 +00:00
_unit addWeapon _secondaryweapon;
2015-01-12 09:07:03 +00:00
2015-01-13 14:28:03 +00:00
{
if (_x != "") then {
_unit addSecondaryWeaponItem _x;
};
} forEach _secondaryweaponitems;
2015-01-12 09:07:03 +00:00
};
// handgun
if (_handgunweapon != "") then {
2015-01-13 14:28:03 +00:00
{
_unit addMagazine _x;
} forEach _handgunweaponmagazine;
2015-01-12 09:07:03 +00:00
2015-01-13 14:28:03 +00:00
_unit addWeapon _handgunweapon;
2015-01-12 09:07:03 +00:00
2015-01-13 14:28:03 +00:00
{
if (_x != "") then {
_unit addHandgunItem _x;
};
} forEach _handgunweaponitems;
2015-01-12 09:07:03 +00:00
};
2015-04-14 23:50:58 +00:00
// remove dummy bagpack
if (_flagRemoveDummyBag) then {
removeBackpack _unit;
};
2015-01-12 09:07:03 +00:00
_assignedItems = _assignedItems - [_binocular];
// items
{_unit linkItem _x} forEach _assignedItems;
_unit addWeapon _binocular;
// reload Laserdesignator
// we assume that if the unit had a Laserdesignator it probably had batteries for it
2015-01-12 09:07:03 +00:00
if ("Laserdesignator" in assignedItems _unit) then {
2015-01-13 14:28:03 +00:00
_unit selectWeapon "Laserdesignator";
if (currentMagazine _unit == "") then {
_unit addMagazine "Laserbatteries";
};
};
// restore the last active weapon, muzzle and weaponMode
_activeWeapon = _activeWeaponAndMuzzle select 0;
_activeMuzzle = _activeWeaponAndMuzzle select 1;
_activeWeaponMode = _activeWeaponAndMuzzle select 2;
if (_activeMuzzle != "" and _activeMuzzle != _activeWeapon) then {
_unit selectWeapon _activeMuzzle;
} else {
if (_activeWeapon != "") then {
_unit selectWeapon _activeWeapon;
};
};
if (currentWeapon _unit != "") then {
private ["_index"];
_index = 0;
while {
_index < 100 && {currentWeaponMode _unit != _activeWeaponMode}
} do {
_unit action ["SwitchWeapon", _unit, _unit, _index];
_index = _index + 1;
};
2015-01-12 09:07:03 +00:00
};