a3_vemf_reloaded/exile_vemf_reloaded/functions/fn_giveAmmo.sqf
2016-05-07 16:09:33 +02:00

75 lines
2.8 KiB
Plaintext

/*
Author: IT07
Description:
Adds magazines to given unit's vest/backpack if it flairTypes
Params:
_this: ARRAY
_this select 0: OBJECT - unit to give ammo to
Returns:
BOOLEAN - true if successful
*/
private ["_done"];
_done = false;
if (_this isEqualType []) then
{
private ["_unit"];
_unit = param [0, objNull, [objNull]];
if not isNull _unit then
{
if local _unit then
{
if not(primaryWeapon _unit isEqualTo "") then
{
private ["_weapon","_mag","_magMass","_vestMass","_itemMass"];
_weapon = primaryWeapon _unit;
_mag = selectRandom (getArray (configFile >> "CfgWeapons" >> _weapon >> "magazines"));
for "_m" from 1 to 5 do
{
if not(_unit canAdd _mag) exitWith {};
_unit addItem _mag;
};
};
if not (secondaryWeapon _unit isEqualTo "") then
{
if not(backPack _unit isEqualTo "") then
{
private ["_weapon","_mag","_magMass"];
_weapon = secondaryWeapon _unit;
_mag = selectRandom (getArray (configFile >> "CfgWeapons" >> _weapon >> "magazines"));
for "_m" from 1 to 3 do
{
if not(_unit canAdd _mag) exitWith {};
_unit addItem _mag;
};
};
};
if not (handGunWeapon _unit isEqualTo "") then
{
private ["_weapon","_mag","_magMass","_uniformMass"];
_weapon = handGunWeapon _unit;
_mag = selectRandom (getArray (configFile >> "CfgWeapons" >> _weapon >> "magazines"));
for "_m" from 1 to 4 do
{
if not(_unit canAdd _mag) exitWith {};
_unit addItem _mag;
};
};
_done = true;
} else // If unit is not local
{
["fn_giveAmmo", 0, format["%1 is not local. Can not execute!", _unit]] spawn VEMfr_fnc_log;
};
} else // If unit isNull
{
["fn_giveAmmo", 0, "_unit isNull. Can not execute!"] spawn VEMFr_fnc_log;
};
} else
{
["fn_giveAmmo", 0, "_this is not an ARRAY"] spawn VEMFr_fnc_log;
};
_done