From 9fbcb7557f0cb65a699b5dd66f44d8e606781a48 Mon Sep 17 00:00:00 2001
From: johnb432 <58661205+johnb432@users.noreply.github.com>
Date: Sun, 12 May 2024 13:21:38 +0200
Subject: [PATCH 1/7] Add grenade rolling
---
addons/grenades/functions/fnc_nextMode.sqf | 5 -----
addons/grenades/functions/fnc_throwGrenade.sqf | 13 +++++++++++--
2 files changed, 11 insertions(+), 7 deletions(-)
diff --git a/addons/grenades/functions/fnc_nextMode.sqf b/addons/grenades/functions/fnc_nextMode.sqf
index 1a64cf9f7ba..a097fac503f 100644
--- a/addons/grenades/functions/fnc_nextMode.sqf
+++ b/addons/grenades/functions/fnc_nextMode.sqf
@@ -23,11 +23,6 @@ if (_mode == 4) then {
_mode = _mode + 1;
};
-// ROLL GRENADE DOESN'T WORK RIGHT NOW
-if (_mode == 3) then {
- _mode = 4;
-};
-
private _hint = localize ([
LSTRING(NormalThrow),
LSTRING(HighThrow),
diff --git a/addons/grenades/functions/fnc_throwGrenade.sqf b/addons/grenades/functions/fnc_throwGrenade.sqf
index 9a0168da3ea..4fde932d023 100644
--- a/addons/grenades/functions/fnc_throwGrenade.sqf
+++ b/addons/grenades/functions/fnc_throwGrenade.sqf
@@ -103,9 +103,18 @@ if (_mode != 0) then {
case 2 : {
_velocity = (_unit weaponDirection _weapon) vectorMultiply (vectorMagnitude _velocity);
};
- //roll grande
+ //roll grenade
case 3 : {
- //@todo
+ private _posASL = getPosASL _projectile;
+
+ // getPos is unreliable, as surfaces in some ruins are not recognised as surfaces
+ private _lisPos = (lineIntersectsSurfaces [_posASL, _posASL vectorAdd [0, 0, -1e11], ACE_player, objNull, true, 1, "ROADWAY", "FIRE"]) select 0;
+ _projectile setPosASL ((_lisPos select 0) vectorAdd [0, 0, 0.2]);
+
+ // Rotate throwables by 90° to the side, so cylindrical throwables can be rolled
+ [_projectile, [direction _projectile, 0, 90]] call BIS_fnc_setObjectRotation;
+
+ _velocity = (vectorDir _unit) vectorMultiply 10;
};
//drop grenade
case 4 : {
From a3ebd64617f25f4bcc3165264f3d478e754b06f6 Mon Sep 17 00:00:00 2001
From: johnb432 <58661205+johnb432@users.noreply.github.com>
Date: Sun, 12 May 2024 23:53:30 +0200
Subject: [PATCH 2/7] Added some safeguards
---
addons/compat_rhs_afrf3/CfgAmmo.hpp | 4 ++++
addons/grenades/XEH_postInit.sqf | 23 +++++++++++++++++++
addons/grenades/functions/fnc_nextMode.sqf | 9 ++++++++
.../grenades/functions/fnc_throwGrenade.sqf | 4 ++--
addons/grenades/script_component.hpp | 2 ++
addons/grenades/stringtable.xml | 3 +++
6 files changed, 43 insertions(+), 2 deletions(-)
diff --git a/addons/compat_rhs_afrf3/CfgAmmo.hpp b/addons/compat_rhs_afrf3/CfgAmmo.hpp
index 54ff3bd2c2d..2c618ee814e 100644
--- a/addons/compat_rhs_afrf3/CfgAmmo.hpp
+++ b/addons/compat_rhs_afrf3/CfgAmmo.hpp
@@ -219,6 +219,10 @@ class CfgAmmo {
EGVAR(frag,force) = 0;
};
+ class SmokeShell;
+ class rhs_ammo_rdg2_white: SmokeShell {
+ EGVAR(grenades,rotation) = 0;
+ };
class Sh_125mm_APFSDS;
class Sh_125mm_HE;
diff --git a/addons/grenades/XEH_postInit.sqf b/addons/grenades/XEH_postInit.sqf
index c23640bca59..db9b6cccf1b 100644
--- a/addons/grenades/XEH_postInit.sqf
+++ b/addons/grenades/XEH_postInit.sqf
@@ -32,3 +32,26 @@ GVAR(flashbangPPEffectCC) ppEffectForceInNVG true;
[] call FUNC(addChangeFuseItemContextMenuOptions);
};
}] call CBA_fnc_addEventHandler;
+
+GVAR(currentThrowable) = [];
+
+{
+ 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)
+ if !(
+ GVAR(currentThrowMode) == 3 &&
+ {_currentThrowable select 0 != ""} &&
+ {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.5] call EFUNC(common,displayTextStructured);
+
+ GVAR(currentThrowMode) = 0;
+} call CBA_fnc_addPerFrameHandler;
diff --git a/addons/grenades/functions/fnc_nextMode.sqf b/addons/grenades/functions/fnc_nextMode.sqf
index a097fac503f..1d0bcb1649c 100644
--- a/addons/grenades/functions/fnc_nextMode.sqf
+++ b/addons/grenades/functions/fnc_nextMode.sqf
@@ -23,6 +23,15 @@ if (_mode == 4) then {
_mode = _mode + 1;
};
+// Skip rolling if throwable can't be rolled (detonation time has to be >= 1 second)
+if (
+ _mode == 3 &&
+ {GVAR(currentThrowable) select 0 != ""} &&
+ {getNumber (configFile >> "CfgAmmo" >> getText (configFile >> "CfgMagazines" >> GVAR(currentThrowable) select 0 >> "ammo") >> "explosionTime") < MIN_EXPLOSION_TIME_FOR_ROLL}
+) then {
+ _mode = _mode + 1;
+};
+
private _hint = localize ([
LSTRING(NormalThrow),
LSTRING(HighThrow),
diff --git a/addons/grenades/functions/fnc_throwGrenade.sqf b/addons/grenades/functions/fnc_throwGrenade.sqf
index 4fde932d023..902eee1c19f 100644
--- a/addons/grenades/functions/fnc_throwGrenade.sqf
+++ b/addons/grenades/functions/fnc_throwGrenade.sqf
@@ -111,8 +111,8 @@ if (_mode != 0) then {
private _lisPos = (lineIntersectsSurfaces [_posASL, _posASL vectorAdd [0, 0, -1e11], ACE_player, objNull, true, 1, "ROADWAY", "FIRE"]) select 0;
_projectile setPosASL ((_lisPos select 0) vectorAdd [0, 0, 0.2]);
- // Rotate throwables by 90° to the side, so cylindrical throwables can be rolled
- [_projectile, [direction _projectile, 0, 90]] call BIS_fnc_setObjectRotation;
+ // Rotate throwables by 90° to the side by default, so cylindrical throwables can be rolled
+ [_projectile, [direction _projectile, 0, [_config >> QGVAR(rotation), "NUMBER", 90] call CBA_fnc_getConfigEntry]] call BIS_fnc_setObjectRotation;
_velocity = (vectorDir _unit) vectorMultiply 10;
};
diff --git a/addons/grenades/script_component.hpp b/addons/grenades/script_component.hpp
index 49dbe92a3f3..3da453de6fd 100644
--- a/addons/grenades/script_component.hpp
+++ b/addons/grenades/script_component.hpp
@@ -20,3 +20,5 @@
#define EFFECT_STAGE_DELETELIGHT 1
#define EFFECT_STAGE_PARTIALRECOVERY 2
#define EFFECT_STAGE_FULLRECOVERY 3
+
+#define MIN_EXPLOSION_TIME_FOR_ROLL 1
diff --git a/addons/grenades/stringtable.xml b/addons/grenades/stringtable.xml
index d5c1b142a65..f1e43147aae 100644
--- a/addons/grenades/stringtable.xml
+++ b/addons/grenades/stringtable.xml
@@ -103,6 +103,9 @@
下丟投擲
Bombayı Yere Bırak
+
+ This grenade can't be rolled, switched to %1
+
M84 Stun Grenade
M84 Blendgranate
From dd43720193ad0bcb86b1613649c20697b3f05031 Mon Sep 17 00:00:00 2001
From: johnb432 <58661205+johnb432@users.noreply.github.com>
Date: Mon, 13 May 2024 11:53:34 +0200
Subject: [PATCH 3/7] Use `setVectorDirAndUp` instead of rotation
---
addons/compat_rhs_afrf3/CfgAmmo.hpp | 2 +-
addons/compat_sog/CfgAmmo/grenades.hpp | 7 +++++++
addons/grenades/XEH_postInit.sqf | 2 +-
addons/grenades/functions/fnc_throwGrenade.sqf | 6 +++++-
docs/wiki/feature/grenades.md | 2 ++
docs/wiki/framework/grenades-framework.md | 6 ++++++
6 files changed, 22 insertions(+), 3 deletions(-)
diff --git a/addons/compat_rhs_afrf3/CfgAmmo.hpp b/addons/compat_rhs_afrf3/CfgAmmo.hpp
index 2c618ee814e..11aee03d795 100644
--- a/addons/compat_rhs_afrf3/CfgAmmo.hpp
+++ b/addons/compat_rhs_afrf3/CfgAmmo.hpp
@@ -221,7 +221,7 @@ class CfgAmmo {
class SmokeShell;
class rhs_ammo_rdg2_white: SmokeShell {
- EGVAR(grenades,rotation) = 0;
+ EGVAR(grenades,rollVectorDirAndUp)[] = {{0, 1, 0}, {0, 0, 1}};
};
class Sh_125mm_APFSDS;
diff --git a/addons/compat_sog/CfgAmmo/grenades.hpp b/addons/compat_sog/CfgAmmo/grenades.hpp
index d280443b6e8..6395756f640 100644
--- a/addons/compat_sog/CfgAmmo/grenades.hpp
+++ b/addons/compat_sog/CfgAmmo/grenades.hpp
@@ -4,6 +4,13 @@ class vn_molotov_grenade_ammo: vn_grenadehand {
EGVAR(frag,enabled) = 0;
};
+class vn_t67_grenade_ammo: vn_grenadehand {
+ EGVAR(grenades,rollVectorDirAndUp)[] = {{-1, 0, 0}, {0, 0, 1}};
+};
+class vn_chicom_grenade_ammo: vn_grenadehand {
+ EGVAR(grenades,rollVectorDirAndUp)[] = {{1, 0, 0}, {0, 0, 1}};
+};
+
class SmokeShell;
class vn_m14_grenade_ammo: SmokeShell {
EGVAR(grenades,incendiary) = 1;
diff --git a/addons/grenades/XEH_postInit.sqf b/addons/grenades/XEH_postInit.sqf
index db9b6cccf1b..f38f2d343e8 100644
--- a/addons/grenades/XEH_postInit.sqf
+++ b/addons/grenades/XEH_postInit.sqf
@@ -44,7 +44,7 @@ GVAR(currentThrowable) = [];
// Make sure grenade can be rolled if in roll mode (detonation time has to be >= 1 second)
if !(
- GVAR(currentThrowMode) == 3 &&
+ (missionNamespace getVariable [QGVAR(currentThrowMode), 0]) == 3 &&
{_currentThrowable select 0 != ""} &&
{getNumber (configFile >> "CfgAmmo" >> getText (configFile >> "CfgMagazines" >> _currentThrowable select 0 >> "ammo") >> "explosionTime") < MIN_EXPLOSION_TIME_FOR_ROLL}
) exitWith {};
diff --git a/addons/grenades/functions/fnc_throwGrenade.sqf b/addons/grenades/functions/fnc_throwGrenade.sqf
index 902eee1c19f..f31198242cc 100644
--- a/addons/grenades/functions/fnc_throwGrenade.sqf
+++ b/addons/grenades/functions/fnc_throwGrenade.sqf
@@ -112,7 +112,11 @@ if (_mode != 0) then {
_projectile setPosASL ((_lisPos select 0) vectorAdd [0, 0, 0.2]);
// Rotate throwables by 90° to the side by default, so cylindrical throwables can be rolled
- [_projectile, [direction _projectile, 0, [_config >> QGVAR(rotation), "NUMBER", 90] call CBA_fnc_getConfigEntry]] call BIS_fnc_setObjectRotation;
+ private _vectorDirAndUp = getArray (_config >> QGVAR(rollVectorDirAndUp));
+ _vectorDirAndUp params [["_vectorDir", [0, 1, 0], [[]], 3], ["_vectorUp", [1, 0, 0], [[]], 3]];
+
+ // Do as if object were facing north
+ _projectile setVectorDirAndUp ([[_vectorDir, _vectorUp], -(direction _projectile), 0, 0] call BIS_fnc_transformVectorDirAndUp);
_velocity = (vectorDir _unit) vectorMultiply 10;
};
diff --git a/docs/wiki/feature/grenades.md b/docs/wiki/feature/grenades.md
index 679b309b1ec..6bd3ce88483 100644
--- a/docs/wiki/feature/grenades.md
+++ b/docs/wiki/feature/grenades.md
@@ -23,6 +23,8 @@ version:
### 1.1 Throw modes
Provides different modes for throwing grenades (high throw, precision throw and drop mode).
+A grenade is only rollable if the fuse time (`explosionTime`) is >= 1 second.
+
### 1.2 Hand flares
Adds throwable hand flares in the colors white, red, green and yellow. Additionally buffs existing flares by making them brighter and last longer.
diff --git a/docs/wiki/framework/grenades-framework.md b/docs/wiki/framework/grenades-framework.md
index fce3b480c2d..dd7021c1644 100644
--- a/docs/wiki/framework/grenades-framework.md
+++ b/docs/wiki/framework/grenades-framework.md
@@ -103,6 +103,12 @@ If set to zero or left undefined, the grenade is not treated as a flare. If it i
Sets the color of the emitted light. The first 3 values of the array of the color, the last is the light intensity.
+### 2.4 Grenade Rolling
+
+#### 2.4.1 ace_grenades_rollVectorDirAndUp
+
+Sets the `setVectorDirAndUp` of the grenade when the grenade is rolled.
+
## 3. Events
### 3.1 Listenable
From 9092efd58db8ac6e4e37bc998b8cd0297b36cab3 Mon Sep 17 00:00:00 2001
From: johnb432 <58661205+johnb432@users.noreply.github.com>
Date: Fri, 24 May 2024 20:46:15 +0200
Subject: [PATCH 4/7] Don't allow players to roll grenades when in vehicles
---
addons/grenades/XEH_postInit.sqf | 31 +++++++++++++++----
addons/grenades/XEH_preInit.sqf | 3 ++
addons/grenades/functions/fnc_nextMode.sqf | 11 ++++---
.../grenades/functions/fnc_throwGrenade.sqf | 2 +-
4 files changed, 36 insertions(+), 11 deletions(-)
diff --git a/addons/grenades/XEH_postInit.sqf b/addons/grenades/XEH_postInit.sqf
index f38f2d343e8..1a74f7df189 100644
--- a/addons/grenades/XEH_postInit.sqf
+++ b/addons/grenades/XEH_postInit.sqf
@@ -33,8 +33,6 @@ GVAR(flashbangPPEffectCC) ppEffectForceInNVG true;
};
}] call CBA_fnc_addEventHandler;
-GVAR(currentThrowable) = [];
-
{
private _currentThrowable = currentThrowable ACE_player;
@@ -42,11 +40,14 @@ GVAR(currentThrowable) = [];
GVAR(currentThrowable) = _currentThrowable;
- // Make sure grenade can be rolled if in roll mode (detonation time has to be >= 1 second)
+ // 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 !(
- (missionNamespace getVariable [QGVAR(currentThrowMode), 0]) == 3 &&
- {_currentThrowable select 0 != ""} &&
- {getNumber (configFile >> "CfgAmmo" >> getText (configFile >> "CfgMagazines" >> _currentThrowable select 0 >> "ammo") >> "explosionTime") < MIN_EXPLOSION_TIME_FOR_ROLL}
+ 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
@@ -55,3 +56,21 @@ GVAR(currentThrowable) = [];
GVAR(currentThrowMode) = 0;
} call CBA_fnc_addPerFrameHandler;
+
+["vehicle", {
+ // 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 &&
+ {GVAR(currentThrowable) isNotEqualTo []} &&
+ {
+ !isNull objectParent ACE_player ||
+ {getNumber (configFile >> "CfgAmmo" >> getText (configFile >> "CfgMagazines" >> GVAR(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.5] call EFUNC(common,displayTextStructured);
+
+ GVAR(currentThrowMode) = 0;
+}, true] call CBA_fnc_addPlayerEventHandler;
diff --git a/addons/grenades/XEH_preInit.sqf b/addons/grenades/XEH_preInit.sqf
index 894773534a4..b5603568c45 100644
--- a/addons/grenades/XEH_preInit.sqf
+++ b/addons/grenades/XEH_preInit.sqf
@@ -6,6 +6,9 @@ PREP_RECOMPILE_START;
#include "XEH_PREP.hpp"
PREP_RECOMPILE_END;
+GVAR(currentThrowMode) = 0;
+GVAR(currentThrowable) = [];
+
#include "initSettings.inc.sqf"
ADDON = true;
diff --git a/addons/grenades/functions/fnc_nextMode.sqf b/addons/grenades/functions/fnc_nextMode.sqf
index 1d0bcb1649c..96a06c8b4b4 100644
--- a/addons/grenades/functions/fnc_nextMode.sqf
+++ b/addons/grenades/functions/fnc_nextMode.sqf
@@ -15,7 +15,7 @@
* Public: No
*/
-private _mode = missionNamespace getVariable [QGVAR(currentThrowMode), 0];
+private _mode = GVAR(currentThrowMode);
if (_mode == 4) then {
_mode = 0;
@@ -23,11 +23,14 @@ if (_mode == 4) then {
_mode = _mode + 1;
};
-// Skip rolling if throwable can't be rolled (detonation time has to be >= 1 second)
+// 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 &&
- {GVAR(currentThrowable) select 0 != ""} &&
- {getNumber (configFile >> "CfgAmmo" >> getText (configFile >> "CfgMagazines" >> GVAR(currentThrowable) select 0 >> "ammo") >> "explosionTime") < MIN_EXPLOSION_TIME_FOR_ROLL}
+ {GVAR(currentThrowable) isNotEqualTo []} &&
+ {
+ !isNull objectParent ACE_player ||
+ {getNumber (configFile >> "CfgAmmo" >> getText (configFile >> "CfgMagazines" >> GVAR(currentThrowable) select 0 >> "ammo") >> "explosionTime") < MIN_EXPLOSION_TIME_FOR_ROLL}
+ }
) then {
_mode = _mode + 1;
};
diff --git a/addons/grenades/functions/fnc_throwGrenade.sqf b/addons/grenades/functions/fnc_throwGrenade.sqf
index f31198242cc..939e0755da0 100644
--- a/addons/grenades/functions/fnc_throwGrenade.sqf
+++ b/addons/grenades/functions/fnc_throwGrenade.sqf
@@ -85,7 +85,7 @@ if (getNumber (_config >> QGVAR(incendiary)) == 1) then {
if (_unit != ACE_player) exitWith {};
if (_unit getVariable [QEGVAR(advanced_throwing,primed), false]) exitWith {LOG("advanced_throwing throw");};
-private _mode = missionNamespace getVariable [QGVAR(currentThrowMode), 0];
+private _mode = GVAR(currentThrowMode);
if (_mode != 0) then {
private _velocity = velocity _projectile;
From fc2689625f0bc5929e07b01dacf6adbd80fffb5c Mon Sep 17 00:00:00 2001
From: PabstMirror
Date: Sat, 25 May 2024 03:12:04 -0500
Subject: [PATCH 5/7] Grenades - Rolling only add PFEH when needed (#10015)
* Grenades - Rolling only add PFEH when needed
* Corrected minor typo, moved variable init in preInit, fixed bugs
---------
Co-authored-by: johnb432 <58661205+johnb432@users.noreply.github.com>
---
addons/grenades/XEH_postInit.sqf | 25 ++-------------
addons/grenades/XEH_preInit.sqf | 2 +-
addons/grenades/functions/fnc_nextMode.sqf | 37 ++++++++++++++++++++--
3 files changed, 38 insertions(+), 26 deletions(-)
diff --git a/addons/grenades/XEH_postInit.sqf b/addons/grenades/XEH_postInit.sqf
index 1a74f7df189..60645e876d4 100644
--- a/addons/grenades/XEH_postInit.sqf
+++ b/addons/grenades/XEH_postInit.sqf
@@ -33,13 +33,9 @@ GVAR(flashbangPPEffectCC) ppEffectForceInNVG true;
};
}] call CBA_fnc_addEventHandler;
-{
+["vehicle", {
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 &&
@@ -55,22 +51,5 @@ GVAR(flashbangPPEffectCC) ppEffectForceInNVG true;
[format [LLSTRING(RollGrenadeDisabled), LLSTRING(NormalThrow)], 2.5] call EFUNC(common,displayTextStructured);
GVAR(currentThrowMode) = 0;
-} call CBA_fnc_addPerFrameHandler;
-
-["vehicle", {
- // 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 &&
- {GVAR(currentThrowable) isNotEqualTo []} &&
- {
- !isNull objectParent ACE_player ||
- {getNumber (configFile >> "CfgAmmo" >> getText (configFile >> "CfgMagazines" >> GVAR(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.5] call EFUNC(common,displayTextStructured);
-
- GVAR(currentThrowMode) = 0;
+ GVAR(throwModePFEH) call CBA_fnc_removePerFrameHandler;
}, true] call CBA_fnc_addPlayerEventHandler;
diff --git a/addons/grenades/XEH_preInit.sqf b/addons/grenades/XEH_preInit.sqf
index b5603568c45..9456dc9c9fb 100644
--- a/addons/grenades/XEH_preInit.sqf
+++ b/addons/grenades/XEH_preInit.sqf
@@ -7,7 +7,7 @@ PREP_RECOMPILE_START;
PREP_RECOMPILE_END;
GVAR(currentThrowMode) = 0;
-GVAR(currentThrowable) = [];
+GVAR(throwModePFEH) = -1;
#include "initSettings.inc.sqf"
diff --git a/addons/grenades/functions/fnc_nextMode.sqf b/addons/grenades/functions/fnc_nextMode.sqf
index 96a06c8b4b4..13bc427dc56 100644
--- a/addons/grenades/functions/fnc_nextMode.sqf
+++ b/addons/grenades/functions/fnc_nextMode.sqf
@@ -23,13 +23,15 @@ if (_mode == 4) then {
_mode = _mode + 1;
};
+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 &&
- {GVAR(currentThrowable) isNotEqualTo []} &&
+ {_currentThrowable isNotEqualTo []} &&
{
!isNull objectParent ACE_player ||
- {getNumber (configFile >> "CfgAmmo" >> getText (configFile >> "CfgMagazines" >> GVAR(currentThrowable) select 0 >> "ammo") >> "explosionTime") < MIN_EXPLOSION_TIME_FOR_ROLL}
+ {getNumber (configFile >> "CfgAmmo" >> getText (configFile >> "CfgMagazines" >> _currentThrowable select 0 >> "ammo") >> "explosionTime") < MIN_EXPLOSION_TIME_FOR_ROLL}
}
) then {
_mode = _mode + 1;
@@ -45,6 +47,37 @@ private _hint = localize ([
[_hint] call EFUNC(common,displayTextStructured);
+GVAR(throwModePFEH) call CBA_fnc_removePerFrameHandler;
GVAR(currentThrowMode) = _mode;
+// 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.5] call EFUNC(common,displayTextStructured);
+
+ GVAR(throwModePFEH) call CBA_fnc_removePerFrameHandler;
+ GVAR(currentThrowMode) = 0;
+ } call CBA_fnc_addPerFrameHandler;
+};
+
true
From 98d0e96f8bc095a9a5cf99ee8694ff51a8b2cb4f Mon Sep 17 00:00:00 2001
From: johnb432 <58661205+johnb432@users.noreply.github.com>
Date: Sat, 25 May 2024 10:25:08 +0200
Subject: [PATCH 6/7] Don't switch modes if grenade can't be thrown
---
addons/grenades/XEH_postInit.sqf | 3 +++
1 file changed, 3 insertions(+)
diff --git a/addons/grenades/XEH_postInit.sqf b/addons/grenades/XEH_postInit.sqf
index ab3a65beb38..c49a6ecd01d 100644
--- a/addons/grenades/XEH_postInit.sqf
+++ b/addons/grenades/XEH_postInit.sqf
@@ -46,6 +46,9 @@ GVAR(flashbangPPEffectCC) ppEffectForceInNVG true;
}
) exitWith {};
+ // If the player can't use throwables, don't change it
+ if !(ACE_player call CBA_fnc_canUseWeapon) 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.5] call EFUNC(common,displayTextStructured);
From 7048d8b85657907805a23a9228586d2a6188b7b6 Mon Sep 17 00:00:00 2001
From: johnb432 <58661205+johnb432@users.noreply.github.com>
Date: Sun, 26 May 2024 09:40:53 +0200
Subject: [PATCH 7/7] Minor tweaks
---
addons/grenades/XEH_postInit.sqf | 2 +-
addons/grenades/functions/fnc_nextMode.sqf | 2 +-
addons/grenades/stringtable.xml | 2 +-
docs/wiki/feature/grenades.md | 2 +-
4 files changed, 4 insertions(+), 4 deletions(-)
diff --git a/addons/grenades/XEH_postInit.sqf b/addons/grenades/XEH_postInit.sqf
index c49a6ecd01d..21282ab1cef 100644
--- a/addons/grenades/XEH_postInit.sqf
+++ b/addons/grenades/XEH_postInit.sqf
@@ -51,7 +51,7 @@ GVAR(flashbangPPEffectCC) ppEffectForceInNVG true;
// 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.5] call EFUNC(common,displayTextStructured);
+ [format [LLSTRING(RollGrenadeDisabled), LLSTRING(NormalThrow)], 2] call EFUNC(common,displayTextStructured);
GVAR(currentThrowMode) = 0;
GVAR(throwModePFEH) call CBA_fnc_removePerFrameHandler;
diff --git a/addons/grenades/functions/fnc_nextMode.sqf b/addons/grenades/functions/fnc_nextMode.sqf
index 13bc427dc56..d3d25027b17 100644
--- a/addons/grenades/functions/fnc_nextMode.sqf
+++ b/addons/grenades/functions/fnc_nextMode.sqf
@@ -73,7 +73,7 @@ if (GVAR(currentThrowMode) == 3) then {
// 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.5] call EFUNC(common,displayTextStructured);
+ [format [LLSTRING(RollGrenadeDisabled), LLSTRING(NormalThrow)], 2] call EFUNC(common,displayTextStructured);
GVAR(throwModePFEH) call CBA_fnc_removePerFrameHandler;
GVAR(currentThrowMode) = 0;
diff --git a/addons/grenades/stringtable.xml b/addons/grenades/stringtable.xml
index f1e43147aae..ec009fa2baa 100644
--- a/addons/grenades/stringtable.xml
+++ b/addons/grenades/stringtable.xml
@@ -104,7 +104,7 @@
Bombayı Yere Bırak
- This grenade can't be rolled, switched to %1
+ Can't roll this grenade, switched to %1
M84 Stun Grenade
diff --git a/docs/wiki/feature/grenades.md b/docs/wiki/feature/grenades.md
index 6bd3ce88483..2b60c08d4ec 100644
--- a/docs/wiki/feature/grenades.md
+++ b/docs/wiki/feature/grenades.md
@@ -23,7 +23,7 @@ version:
### 1.1 Throw modes
Provides different modes for throwing grenades (high throw, precision throw and drop mode).
-A grenade is only rollable if the fuse time (`explosionTime`) is >= 1 second.
+A grenade is only rollable if the fuse time (`explosionTime`) is >= 1 second and the player isn't in a vehicle.
### 1.2 Hand flares
Adds throwable hand flares in the colors white, red, green and yellow. Additionally buffs existing flares by making them brighter and last longer.