ACE3/addons/respawn/functions/fnc_restoreGear.sqf

184 lines
4.2 KiB
Plaintext
Raw Normal View History

2015-01-12 09:07:03 +00:00
/*
2015-09-26 14:26:41 +00:00
* Author: bux578
* Restores previously saved gear.
*
* Arguments:
* 0: Unit <OBJECT>
* 1: All Gear based on return value of ACE_common_fnc_getAllGear <ARRAY>
*
* Return Value:
* None
*
* Example:
* [ACE_Player, stored_allGear] call ace_respawn_fnc_restoreGear
*
* Public: No
*/
#include "script_component.hpp"
2015-09-26 14:26:41 +00:00
params ["_unit", "_allGear"];
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;
2015-09-26 14:26:41 +00:00
_allGear params [
"_headgear", "_goggles",
"_uniform", "_uniformitems",
"_vest", "_vestitems",
"_backpack", "_backpackitems",
"_primaryweapon", "_primaryweaponitems", "_primaryweaponmagazine",
"_secondaryweapon", "_secondaryweaponitems", "_secondaryweaponmagazine",
"_handgunweapon", "_handgunweaponitems", "_handgunweaponmagazine",
"_assigneditems", "_binocular",
"_activeWeaponAndMuzzle"
];
2015-01-12 09:07:03 +00:00
// start restoring the items
2015-09-26 14:26:41 +00:00
if (_headgear != "") then {_unit addHeadgear _headgear};
if (_goggles != "") then {_unit addGoggles _goggles};
if (_uniform != "") then {_unit forceAddUniform _uniform};
if (_vest != "") then {_unit addVest _vest};
2015-01-12 09:07:03 +00:00
{
2015-01-13 14:28:03 +00:00
_unit addItemToUniform _x;
2015-09-26 14:26:41 +00:00
false
} count _uniformitems;
2015-01-12 09:07:03 +00:00
{
2015-01-13 14:28:03 +00:00
_unit addItemToVest _x;
2015-09-26 14:26:41 +00:00
false
} count _vestitems;
2015-01-12 09:07:03 +00:00
2015-04-14 23:50:58 +00:00
private "_flagRemoveDummyBag";
2015-01-12 09:07:03 +00:00
2015-09-26 14:26:41 +00:00
if (format ["%1", _backpack] != "") then {
2015-01-13 14:28:03 +00:00
_unit addBackpack _backpack;
2015-09-26 14:26:41 +00:00
// make sure the backpack is empty. Some bags are prefilled by config
private "_backpackObject";
_backpackObject = unitBackpack _unit;
clearMagazineCargoGlobal _backpackObject;
clearWeaponCargoGlobal _backpackObject;
clearItemCargoGlobal _backpackObject;
2015-01-13 14:28:03 +00:00
{
_unit addItemToBackpack _x;
2015-09-26 14:26:41 +00:00
false
} count _backpackitems;
2015-04-14 23:50:58 +00:00
2015-09-26 14:26:41 +00:00
_flagRemoveDummyBag = false;
2015-04-14 23:50:58 +00:00
} else {
// dummy backpack to ensure mags being loaded
2015-09-26 14:26:41 +00:00
_unit addBackpack "Bag_Base";
2015-04-14 23:50:58 +00:00
_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;
2015-09-26 14:26:41 +00:00
false
} count _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;
};
2015-09-26 14:26:41 +00:00
false
} count _primaryweaponitems;
2015-01-12 09:07:03 +00:00
};
// secondaryWeapon
if (_secondaryweapon != "") then {
2015-01-13 14:28:03 +00:00
{
_unit addMagazine _x;
2015-09-26 14:26:41 +00:00
false
} count _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;
};
2015-09-26 14:26:41 +00:00
false
} count _secondaryweaponitems;
2015-01-12 09:07:03 +00:00
};
// handgun
if (_handgunweapon != "") then {
2015-01-13 14:28:03 +00:00
{
_unit addMagazine _x;
2015-09-26 14:26:41 +00:00
false
} count _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;
};
2015-09-26 14:26:41 +00:00
false
} count _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-09-26 14:26:41 +00:00
_assignedItems deleteAt (_assignedItems find _binocular);
2015-01-12 09:07:03 +00:00
// items
2015-09-26 14:26:41 +00:00
{_unit linkItem _x; false} count _assignedItems;
2015-01-12 09:07:03 +00:00
_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
2015-09-26 14:26:41 +00:00
_activeWeaponAndMuzzle params ["_activeWeapon", "_activeMuzzle", "_activeWeaponMode"]
2015-09-03 16:17:53 +00:00
2015-09-26 14:26:41 +00:00
if (
(_activeMuzzle != "") &&
{_activeMuzzle != _activeWeapon} &&
{_activeMuzzle in getArray (configfile >> "CfgWeapons" >> _activeWeapon >> "muzzles")}
) then {
_unit selectWeapon _activeMuzzle;
} else {
2015-09-26 14:26:41 +00:00
if (_activeWeapon != "") then {
_unit selectWeapon _activeWeapon;
};
};
2015-09-26 14:26:41 +00:00
if (currentWeapon _unit != "") then {
private "_index";
_index = 0;
2015-09-26 14:26:41 +00:00
while {
_index < 100 && {currentWeaponMode _unit != _activeWeaponMode}
} do {
_unit action ["SwitchWeapon", _unit, _unit, _index];
_index = _index + 1;
};
2015-01-12 09:07:03 +00:00
};