ACE3/addons/grenades/functions/fnc_nextMode.sqf

79 lines
2.4 KiB
Plaintext
Raw Normal View History

#include "..\script_component.hpp"
/*
* Author: commy2
* Select the next throwing mode and display message.
*
* Arguments:
2015-08-13 20:36:58 +00:00
* None
*
* Return Value:
* Handled <BOOL>
*
* Example:
* call ace_grenades_fnc_nextMode
*
* Public: No
*/
// _mode is 0-4, don't overflow
private _mode = (GVAR(currentThrowMode) + 1) % 5;
private _currentThrowable = currentThrowable ACE_player;
// Make sure grenade can be rolled if in roll mode (detonation time has to be >= 1 second and player isn't in a vehicle)
if (
_mode == 3 &&
{_currentThrowable isNotEqualTo []} &&
{
!isNull objectParent ACE_player ||
{getNumber (configFile >> "CfgAmmo" >> getText (configFile >> "CfgMagazines" >> _currentThrowable select 0 >> "ammo") >> "explosionTime") < MIN_EXPLOSION_TIME_FOR_ROLL}
}
) then {
_mode = _mode + 1;
};
2016-01-06 21:42:02 +00:00
private _hint = localize ([
LSTRING(NormalThrow),
LSTRING(HighThrow),
LSTRING(PreciseThrow),
LSTRING(RollGrenade),
LSTRING(DropGrenade)
2016-01-06 21:42:02 +00:00
] select _mode);
2015-01-14 09:06:47 +00:00
[_hint] call EFUNC(common,displayTextStructured);
GVAR(throwModePFEH) call CBA_fnc_removePerFrameHandler;
2015-01-14 09:06:47 +00:00
GVAR(currentThrowMode) = _mode;
2015-01-14 19:48:08 +00:00
// If in rolling mode, check every frame if current throwable is rollable
if (GVAR(currentThrowMode) == 3) then {
GVAR(currentThrowable) = _currentThrowable;
GVAR(throwModePFEH) = {
private _currentThrowable = currentThrowable ACE_player;
if (GVAR(currentThrowable) isEqualTo _currentThrowable) exitWith {};
GVAR(currentThrowable) = _currentThrowable;
// Make sure grenade can be rolled if in roll mode (detonation time has to be >= 1 second and player isn't in a vehicle)
if !(
GVAR(currentThrowMode) == 3 &&
{_currentThrowable isNotEqualTo []} &&
{
!isNull objectParent ACE_player ||
{getNumber (configFile >> "CfgAmmo" >> getText (configFile >> "CfgMagazines" >> _currentThrowable select 0 >> "ammo") >> "explosionTime") < MIN_EXPLOSION_TIME_FOR_ROLL}
}
) exitWith {};
// Force the user into the normal throw mode
// Next throw mode after roll would be drop, which isn't ideal if the user tries to throw unknowingly...
[format [LLSTRING(RollGrenadeDisabled), LLSTRING(NormalThrow)], 2] call EFUNC(common,displayTextStructured);
GVAR(throwModePFEH) call CBA_fnc_removePerFrameHandler;
GVAR(currentThrowMode) = 0;
} call CBA_fnc_addPerFrameHandler;
};
2015-01-14 20:40:37 +00:00
true