ACE3/addons/field_rations/functions/fnc_drinkFromSource.sqf
GhostIsSpooky 68ed19911a
General - Change object config lookups to configOf (#8795)
* configOf lookups

* forEach, missed configOf

* revert handcuff distance change

Co-authored-by: Filip Maciejewski <veteran29@users.noreply.github.com>

* optimize condition

Co-authored-by: Filip Maciejewski <veteran29@users.noreply.github.com>

* capitalization

Co-authored-by: Filip Maciejewski <veteran29@users.noreply.github.com>

* use object in getVehicleIcon

Co-authored-by: Filip Maciejewski <veteran29@users.noreply.github.com>

* add return comment

Co-authored-by: Filip Maciejewski <veteran29@users.noreply.github.com>

* remove extra brackets

Co-authored-by: Filip Maciejewski <veteran29@users.noreply.github.com>

* add missing brackets

Co-authored-by: Filip Maciejewski <veteran29@users.noreply.github.com>

* add return comment pt2

Co-authored-by: Filip Maciejewski <veteran29@users.noreply.github.com>

* revert to cursorTarget

Co-authored-by: Filip Maciejewski <veteran29@users.noreply.github.com>
Co-authored-by: PabstMirror <pabstmirror@gmail.com>
2022-03-08 21:41:21 -06:00

81 lines
2.2 KiB
Plaintext

#include "script_component.hpp"
/*
* Author: mharis001
* Makes the player drink directly from the given water source.
*
* Arguments:
* 0: Player <OBJECT>
* 1: Water Source <OBJECT>
*
* Return Value:
* None
*
* Example:
* [_player, _source] call ace_field_rations_drinkFromSource
*
* Public: No
*/
params ["_player", "_source"];
// Store current animation for resetting
_player setVariable [QGVAR(previousAnim), animationState _player];
private _animation = [_player, _source] call FUNC(getDrinkAnimation);
[_player, _animation, 1] call EFUNC(common,doAnimation);
private _fnc_onSuccess = {
params ["_args"];
_args params ["_player", "_source"];
// Reduce player thirst
private _thirst = _player getVariable [QXGVAR(thirst), 0];
_player setVariable [QXGVAR(thirst), (_thirst - (DRINK_FROM_SOURCE_QUENCHED * XGVAR(thirstQuenched))) max 0];
_player setVariable [QGVAR(previousAnim), nil];
// Update remaining water in source
private _waterInSource = _source call FUNC(getRemainingWater);
if (_waterInSource != REFILL_WATER_INFINITE) then {
[_source, (_waterInSource - DRINK_FROM_SOURCE_AMOUNT) max 0] call FUNC(setRemainingWater);
};
};
private _fnc_onFailure = {
params ["_args"];
_args params ["_player"];
// 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"];
_args params ["_player", "_source"];
[_player, _source] call FUNC(canDrinkFromSource)
};
private _sourceConfig = configOf _source;
private _progressText = if (isNull _sourceConfig) then {
LLSTRING(DrinkingFromSource)
} else {
format [LLSTRING(DrinkingFromX), getText (_sourceConfig >> "displayName")]
};
[
DRINK_FROM_SOURCE_TIME,
[_player, _source],
_fnc_onSuccess,
_fnc_onFailure,
_progressText,
_fnc_condition
] call EFUNC(common,progressBar);