ACE3/addons/field_rations/functions/fnc_drinkFromSource.sqf
jonpas 6ca9d59443
Merge ACEX (#8415)
* Merge ACEX - first attempt
Backwards compatibility with XGVAR set of macros used on all settings and config entries
Public API functions not taken into account yet, many other things probably still missed

* Resolve issues

* Switch to addSetting, backward compatible CfgPatches, missed XGVAR.

* Remove unnecessary backwards compat

* Convert ACEX Categorised settings to initSettings / Fix Intel items magazine

* Apply suggestions from code review

Co-authored-by: PabstMirror <pabstmirror@gmail.com>

* Remove maintainers from merged ACEX components

* Cleanup unused module and faction classes

* Sitting - Add more object configs by @Dystopian
https://github.com/acemod/ACEX/pull/255

* Translations - Add Japanese by @classicarma
https://github.com/acemod/ACEX/pull/259

* Kill Tracker - Add killtracker.inc public include file by @Freddo3000"
https://github.com/acemod/ACEX/pull/251

* Add ACEX authors and sort authors file

* acex - final tweaks (#8513)

* acex - handle old funcs

* replace thirst/hunger setvars to acex naming

fix macro

Revert "fix macro"

This reverts commit d807e5e804c43916eaa42d34a89af94c6d9a48ad.

Revert "replace thirst/hunger setvars to acex naming"

This reverts commit bafc607884932d6e339daedc7c22e25dddbdd868.

x

Co-authored-by: TyroneMF <TyroneMF@hotmail.com>
Co-authored-by: PabstMirror <pabstmirror@gmail.com>
2021-10-14 10:46:43 -05: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 _sourceType = typeOf _source;
private _progressText = if (_sourceType == "") then {
LLSTRING(DrinkingFromSource)
} else {
format [LLSTRING(DrinkingFromX), getText (configFile >> "CfgVehicles" >> _sourceType >> "displayName")]
};
[
DRINK_FROM_SOURCE_TIME,
[_player, _source],
_fnc_onSuccess,
_fnc_onFailure,
_progressText,
_fnc_condition
] call EFUNC(common,progressBar);