2021-10-14 15:46:43 +00:00
|
|
|
#include "script_component.hpp"
|
|
|
|
/*
|
|
|
|
* Author: mharis001, Glowbal, PabstMirror
|
|
|
|
* Consumes an item. Creates a progress bar and handles relevant thirst/hunger values.
|
|
|
|
*
|
|
|
|
* Arguments:
|
|
|
|
* 0: Target (not used) <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
|
|
|
* [objNull, ACE_player, "["ACE_WaterBottle_Empty", configFile >> "CfgWeapons" >> "ACE_WaterBottle_Empty", false]] call ace_field_rations_fnc_consumeItem
|
2021-10-14 15:46:43 +00:00
|
|
|
*
|
|
|
|
* Public: No
|
|
|
|
*/
|
|
|
|
|
2022-09-06 11:21:45 +00:00
|
|
|
params ["", "_player", "_consumeData"];
|
|
|
|
_consumeData params ["_consumeItem", "_config", "_isMagazine"];
|
|
|
|
TRACE_3("Consume item started",_player,_consumeItem,_config);
|
2021-10-14 15:46:43 +00:00
|
|
|
|
|
|
|
// Get consume time for item
|
|
|
|
private _consumeTime = getNumber (_config >> QXGVAR(consumeTime));
|
|
|
|
|
|
|
|
// Get restored values and replacement item
|
|
|
|
private _thirstQuenched = XGVAR(thirstQuenched) * getNumber (_config >> QXGVAR(thirstQuenched));
|
|
|
|
private _hungerSatiated = XGVAR(hungerSatiated) * getNumber (_config >> QXGVAR(hungerSatiated));
|
|
|
|
private _replacementItem = getText (_config >> QXGVAR(replacementItem));
|
|
|
|
|
|
|
|
// Create consume text for item
|
|
|
|
private _displayName = getText (_config >> "displayName");
|
|
|
|
private _consumeText = getText (_config >> QXGVAR(consumeText));
|
|
|
|
|
|
|
|
if (_consumeText == "") then {
|
|
|
|
_consumeText = if (_hungerSatiated > 0) then {
|
|
|
|
LLSTRING(EatingX);
|
|
|
|
} else {
|
|
|
|
LLSTRING(DrinkingX);
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
// Format displayName onto consume text
|
|
|
|
// Allows for common strings to be used for multiple items
|
|
|
|
_consumeText = format [_consumeText, _displayName];
|
|
|
|
|
|
|
|
// Get consume animation and sound for item
|
|
|
|
private _stanceIndex = ["STAND", "CROUCH", "PRONE"] find stance _player;
|
|
|
|
|
|
|
|
// Handle in vehicle when stance is UNDEFINED
|
|
|
|
if (vehicle _player != _player) then {_stanceIndex = 0};
|
|
|
|
|
|
|
|
private _consumeAnim = getArray (_config >> QXGVAR(consumeAnims)) param [_stanceIndex, "", [""]];
|
|
|
|
private _consumeSound = getArray (_config >> QXGVAR(consumeSounds)) param [_stanceIndex, "", [""]];
|
|
|
|
|
|
|
|
private _soundPlayed = if (_consumeAnim != "" && {vehicle _player == _player && {!(_player call EFUNC(common,isSwimming))}}) then {
|
|
|
|
// Store current animation for resetting
|
|
|
|
_player setVariable [QGVAR(previousAnim), animationState _player];
|
|
|
|
[_player, _consumeAnim, 1] call EFUNC(common,doAnimation);
|
|
|
|
false
|
|
|
|
} else {
|
|
|
|
// No animation to sync sound to
|
|
|
|
if (_consumeSound != "") then {
|
|
|
|
playSound _consumeSound;
|
|
|
|
};
|
|
|
|
true
|
|
|
|
};
|
|
|
|
|
|
|
|
private _fnc_onSuccess = {
|
|
|
|
params ["_args"];
|
2022-09-06 11:21:45 +00:00
|
|
|
_args params ["_player", "_consumeItem", "_replacementItem", "_thirstQuenched", "_hungerSatiated", "", "", "", "_isMagazine"];
|
2021-10-14 15:46:43 +00:00
|
|
|
TRACE_1("Consume item successful",_args);
|
|
|
|
|
|
|
|
// Remove consumed item
|
2022-09-06 11:21:45 +00:00
|
|
|
if (_isMagazine) then {
|
|
|
|
_player removeMagazineGlobal _consumeItem;
|
|
|
|
} else {
|
|
|
|
_player removeItem _consumeItem;
|
|
|
|
};
|
2021-10-14 15:46:43 +00:00
|
|
|
|
|
|
|
// Add replacement item if needed
|
|
|
|
if (_replacementItem != "") then {
|
|
|
|
[_player, _replacementItem] call EFUNC(common,addToInventory);
|
|
|
|
};
|
|
|
|
|
|
|
|
// Handle thirst and hunger values
|
|
|
|
if (_thirstQuenched > 0) then {
|
|
|
|
private _thirst = _player getVariable [QXGVAR(thirst), 0];
|
|
|
|
_player setVariable [QXGVAR(thirst), (_thirst - _thirstQuenched) max 0];
|
|
|
|
};
|
|
|
|
|
|
|
|
if (_hungerSatiated > 0) then {
|
|
|
|
private _hunger = _player getVariable [QXGVAR(hunger), 0];
|
|
|
|
_player setVariable [QXGVAR(hunger), (_hunger - _hungerSatiated) max 0];
|
|
|
|
};
|
|
|
|
|
2022-09-06 11:21:45 +00:00
|
|
|
["acex_rationConsumed", [_player, _consumeItem, _replacementItem, _thirstQuenched, _hungerSatiated, _isMagazine]] call CBA_fnc_localEvent;
|
2021-10-14 15:46:43 +00:00
|
|
|
|
|
|
|
_player setVariable [QGVAR(previousAnim), nil];
|
|
|
|
};
|
|
|
|
|
|
|
|
private _fnc_onFailure = {
|
|
|
|
params ["_args"];
|
|
|
|
_args params ["_player"];
|
|
|
|
TRACE_1("Consume item failed",_args);
|
|
|
|
|
|
|
|
// Reset animation if needed
|
|
|
|
if (vehicle _player == _player && {!(_player call EFUNC(common,isSwimming))}) then {
|
|
|
|
private _previousAnim = _player getVariable [QGVAR(previousAnim), ""];
|
|
|
|
if (_previousAnim != "") then {
|
|
|
|
[_player, _previousAnim, 2] call EFUNC(common,doAnimation);
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
_player setVariable [QGVAR(previousAnim), nil];
|
|
|
|
};
|
|
|
|
|
|
|
|
private _fnc_condition = {
|
|
|
|
params ["_args"];
|
2022-09-06 11:21:45 +00:00
|
|
|
_args params ["_player", "_consumeItem", "", "", "", "_consumeAnim", "_consumeSound", "_soundPlayed", "_isMagazine"];
|
2021-10-14 15:46:43 +00:00
|
|
|
|
|
|
|
// Attempt to sync sound with animation start
|
|
|
|
if (!_soundPlayed && {_consumeSound != "" && {_consumeAnim == "" || {animationState _player == _consumeAnim}}}) then {
|
|
|
|
playSound _consumeSound;
|
|
|
|
_args set [7, true];
|
|
|
|
};
|
|
|
|
|
2022-09-06 11:21:45 +00:00
|
|
|
if (_isMagazine) exitWith {
|
|
|
|
_consumeItem in magazines _player // return
|
|
|
|
};
|
|
|
|
_consumeItem in (_player call EFUNC(common,uniqueItems)) // return
|
2021-10-14 15:46:43 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
[
|
|
|
|
_consumeTime,
|
|
|
|
[
|
|
|
|
_player,
|
|
|
|
_consumeItem,
|
|
|
|
_replacementItem,
|
|
|
|
_thirstQuenched,
|
|
|
|
_hungerSatiated,
|
|
|
|
_consumeAnim,
|
|
|
|
_consumeSound,
|
2022-09-06 11:21:45 +00:00
|
|
|
_soundPlayed,
|
|
|
|
_isMagazine
|
2021-10-14 15:46:43 +00:00
|
|
|
],
|
|
|
|
_fnc_onSuccess,
|
|
|
|
_fnc_onFailure,
|
|
|
|
_consumeText,
|
|
|
|
_fnc_condition,
|
|
|
|
["isNotInside"]
|
|
|
|
] call EFUNC(common,progressBar);
|