2023-09-12 18:58:10 +00:00
|
|
|
#include "..\script_component.hpp"
|
2021-10-14 15:46:43 +00:00
|
|
|
/*
|
|
|
|
* Author: mharis001, Glowbal, PabstMirror
|
|
|
|
* Refills an item from given water source.
|
|
|
|
*
|
|
|
|
* Arguments:
|
|
|
|
* 0: Water source <OBJECT>
|
|
|
|
* 1: Player <OBJECT>
|
2022-09-06 11:21:45 +00:00
|
|
|
* 2: Item data <ARRAY>
|
|
|
|
* 0: Item classname <STRING>
|
|
|
|
* 1: Item config <CONFIG>
|
|
|
|
* 2: Is item magazine <BOOL>
|
2021-10-14 15:46:43 +00:00
|
|
|
*
|
|
|
|
* Return Value:
|
|
|
|
* None
|
|
|
|
*
|
|
|
|
* Example:
|
2022-09-06 11:21:45 +00:00
|
|
|
* [_source, _player, ["ACE_WaterBottle_Empty", configFile >> "CfgWeapons" >> "ACE_WaterBottle_Empty", false]] call ace_field_rations_fnc_refillItem
|
2021-10-14 15:46:43 +00:00
|
|
|
*
|
|
|
|
* Public: No
|
|
|
|
*/
|
|
|
|
|
2022-09-06 11:21:45 +00:00
|
|
|
params ["_source", "_player", "_itemData"];
|
|
|
|
_itemData params ["_item", "_config", "_isMagazine"];
|
2021-10-14 15:46:43 +00:00
|
|
|
TRACE_3("Item refill started",_source,_player,_item);
|
|
|
|
|
|
|
|
// Get config values for refill
|
|
|
|
private _refillItem = getText (_config >> QXGVAR(refillItem));
|
|
|
|
private _refillAmount = getNumber (_config >> QXGVAR(refillAmount));
|
|
|
|
private _refillTime = getNumber (_config >> QXGVAR(refillTime));
|
|
|
|
|
|
|
|
private _fnc_onSuccess = {
|
|
|
|
params ["_args"];
|
2022-09-06 11:21:45 +00:00
|
|
|
_args params ["_source", "_player", "_itemData", "_refillItem", "_refillAmount", "_itemData"];
|
|
|
|
_itemData params ["_item", "", "_isMagazine"];
|
2021-10-14 15:46:43 +00:00
|
|
|
TRACE_1("Refill item successful",_args);
|
|
|
|
|
|
|
|
// Replace item with refilled one
|
2022-09-06 11:21:45 +00:00
|
|
|
if (_isMagazine) then {
|
|
|
|
_player removeMagazineGlobal _item;
|
|
|
|
} else {
|
|
|
|
_player removeItem _item;
|
|
|
|
};
|
2021-10-14 15:46:43 +00:00
|
|
|
[_player, _refillItem] call EFUNC(common,addToInventory);
|
|
|
|
|
|
|
|
// Update remaining water in source
|
|
|
|
private _waterInSource = _source call FUNC(getRemainingWater);
|
|
|
|
if (_waterInSource != REFILL_WATER_INFINITE) then {
|
|
|
|
_waterInSource = (_waterInSource - _refillAmount) max 0;
|
|
|
|
[_source, _waterInSource] call FUNC(setRemainingWater);
|
|
|
|
};
|
|
|
|
|
2022-09-06 11:21:45 +00:00
|
|
|
["acex_rationRefilled", [_source, _player, _item, _refillItem, _refillAmount, _isMagazine]] call CBA_fnc_localEvent;
|
2021-10-14 15:46:43 +00:00
|
|
|
|
|
|
|
// Show refilled item hint
|
|
|
|
private _picture = getText (configFile >> "CfgWeapons" >> _refillItem >> "picture");
|
|
|
|
[LSTRING(ItemRefilled), _picture] call EFUNC(common,displayTextPicture);
|
|
|
|
};
|
|
|
|
|
|
|
|
private _fnc_onFailure = {
|
|
|
|
TRACE_1("Refill item failed",_this);
|
|
|
|
};
|
|
|
|
|
|
|
|
private _fnc_condition = {
|
|
|
|
params ["_args"];
|
|
|
|
_args call FUNC(canRefillItem);
|
|
|
|
};
|
|
|
|
|
|
|
|
[
|
|
|
|
_refillTime,
|
|
|
|
[
|
|
|
|
_source,
|
|
|
|
_player,
|
2022-09-06 11:21:45 +00:00
|
|
|
_itemData,
|
2021-10-14 15:46:43 +00:00
|
|
|
_refillItem,
|
|
|
|
_refillAmount
|
|
|
|
],
|
|
|
|
_fnc_onSuccess,
|
|
|
|
_fnc_onFailure,
|
|
|
|
LLSTRING(Refilling),
|
|
|
|
_fnc_condition
|
|
|
|
] call EFUNC(common,progressBar);
|