fn_fillStorage

This commit is contained in:
Wyqer 2019-12-05 16:36:17 +01:00
parent 1d94daa16a
commit 2d0a300177
No known key found for this signature in database
GPG Key ID: D7E2F8BD7F1E48FA
1 changed files with 21 additions and 13 deletions

View File

@ -2,19 +2,23 @@
File: fn_fillStorage.sqf
Author: KP Liberation Dev Team - https://github.com/KillahPotatoes
Date: 2019-12-03
Last Update: 2019-12-03
Last Update: 2019-12-04
License: MIT License - http://www.opensource.org/licenses/MIT
Description:
No description added yet.
Fills given storage with given amounts of resources.
Parameter(s):
_localVariable - Description [DATATYPE, defaults to DEFAULTVALUE]
_supply - Amount of supply resource [NUMBER, defaults to 0]
_ammo - Amount of ammo resource [NUMBER, defaults to 0]
_fuel - Amount of fuel resource [NUMBER, defaults to 0]
_storage - Storage object to fill [OBJECT, defaults to objNull]
_delay - Enable a small delay between crate create and attach to storage [BOOL, defaults to false]
Returns:
Function reached the end [BOOL]
*/
// TODO
params [
["_supply", 0, [0]],
["_ammo", 0, [0]],
@ -23,24 +27,28 @@ params [
["_delay", false, [false]]
];
if (isNull _storage) exitWith {false};
if (isNull _storage) exitWith {["Null object given"] call BIS_fnc_error; false};
// Make sure it's scheduled, if delay is enabled
if (_delay && {!canSuspend}) exitWith {_this spawn KPLIB_fnc_fillStorage};
private _crateType = KP_liberation_supply_crate;
private _amount = 0;
private _crate = objNull;
private _pos = getPos _storage;
{
_crateType = [KP_liberation_supply_crate, KP_liberation_ammo_crate, KP_liberation_fuel_crate] select _forEachIndex;
while {_x > 0} do {
_amount = 100;
if ((_x / 100) < 1) then {
_amount = _x;
};
_amount = 100 min _x;
_x = _x - _amount;
_crate = [_crateType, _amount, _pos] call KPLIB_fnc_createCrate;
_crate = [
[KP_liberation_supply_crate, KP_liberation_ammo_crate, KP_liberation_fuel_crate] select _forEachIndex,
_amount,
_pos
] call KPLIB_fnc_createCrate;
if (_delay) then {sleep 0.1;};
[_crate, _storage] call KPLIB_fnc_crateToStorage;
};
} forEach [_supply, _ammo, _fuel];