Skip to content

Commit

Permalink
Fix Advanced Throwing vanilla throw block for primed throwables (#4370)
Browse files Browse the repository at this point in the history
* Fix vanilla throwing block failing after priming, simplify muzzle ammo (can only be 1 or 0, 1 doesn't influence anything if no appliccable throwable in inventory)

* Disable select grenade keys when advanced throwing is active

* Fix #4375 - select next grenade cycles between first 2 grenade muzzles due to setAmmo
  • Loading branch information
jonpas authored and thojkooi committed Sep 12, 2016
1 parent e85abbe commit 0400a85
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 13 deletions.
16 changes: 8 additions & 8 deletions addons/advanced_throwing/functions/fnc_drawThrowable.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -63,33 +63,33 @@ private _power = linearConversion [0, 180, _phi - 30, 1, 0.3, true];
ACE_player setVariable [QGVAR(throwSpeed), _throwSpeed * _power];

#ifdef DEBUG_MODE_FULL
hintSilent format ["Heading: %1\nPower: %2\nSpeed: %3\nThrowMag: %4", _phi, _power, _throwSpeed * _power, _throwableMag];
hintSilent format ["Heading: %1\nPower: %2\nSpeed: %3\nThrowMag: %4\nMuzzle: %5", _phi, _power, _throwSpeed * _power, _throwableMag, ACE_player getVariable [QGVAR(activeMuzzle), ""]];
#endif

private _throwableType = getText (configFile >> "CfgMagazines" >> _throwableMag >> "ammo");

if (!([ACE_player] call FUNC(canThrow)) && {!_primed}) exitWith {
if (!isNull _activeThrowable) then {
deleteVehicle _activeThrowable;
// Restore muzzle ammo to original
ACE_player setAmmo (ACE_player getVariable [QGVAR(activeMuzzle), ["", 0]]);
// Restore muzzle ammo (setAmmo 1 has no impact if no appliccable throwable in inventory)
ACE_player setAmmo [ACE_player getVariable [QGVAR(activeMuzzle), ""], 1];
};
};

if (isNull _activeThrowable || {(_throwableType != typeOf _activeThrowable) && {!_primed}}) then {
if (!isNull _activeThrowable) then {
deleteVehicle _activeThrowable;
// Restore muzzle ammo to original
ACE_player setAmmo (ACE_player getVariable [QGVAR(activeMuzzle), ["", 0]]);
// Restore muzzle ammo (setAmmo 1 has no impact if no appliccable throwable in inventory)
ACE_player setAmmo [ACE_player getVariable [QGVAR(activeMuzzle), ""], 1];
};
_activeThrowable = _throwableType createVehicleLocal [0, 0, 0];
_activeThrowable enableSimulation false;
ACE_player setVariable [QGVAR(activeThrowable), _activeThrowable];

// Set muzzle ammo to 0 to block vanilla throwing, save to variable for later restoration
private _muzzle = _throwableType call FUNC(getMuzzle);
ACE_player setVariable [QGVAR(activeMuzzle), [_muzzle, ACE_player ammo _muzzle]];
// Set muzzle ammo to 0 to block vanilla throwing (can only be 0 or 1)
private _muzzle = _throwableMag call FUNC(getMuzzle);
ACE_player setAmmo [_muzzle, 0];
ACE_player setVariable [QGVAR(activeMuzzle), _muzzle];
};

// Exit in case of explosion in hand
Expand Down
7 changes: 4 additions & 3 deletions addons/advanced_throwing/functions/fnc_exitThrowMode.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,19 @@ if !(_unit getVariable [QGVAR(inHand), false]) exitWith {};
private _activeThrowable = _unit getVariable [QGVAR(activeThrowable), objNull];
if !(_unit getVariable [QGVAR(primed), false]) then {
deleteVehicle _activeThrowable;
// Set muzzle ammo to original
_unit setAmmo (_unit getVariable [QGVAR(activeMuzzle), ["", 0]]);
} else {
_unit setVariable [QGVAR(lastThrownTime), CBA_missionTime];
// Fix floating for throwables without proper physics (eg. IR Grenade)
_activeThrowable setVelocity [0, 0, -0.1];
};

// Restore muzzle ammo (setAmmo 1 has no impact if no appliccable throwable in inventory)
_unit setAmmo [_unit getVariable [QGVAR(activeMuzzle), ""], 1];

_unit setVariable [QGVAR(inHand), false];
_unit setVariable [QGVAR(primed), false];
_unit setVariable [QGVAR(activeThrowable), objNull];
_unit setVariable [QGVAR(activeMuzzle), ["", 0]];
_unit setVariable [QGVAR(activeMuzzle), ""];
_unit setVariable [QGVAR(throwType), THROW_TYPE_DEFAULT];
_unit setVariable [QGVAR(throwSpeed), THROW_SPEED_DEFAULT];
_unit setVariable [QGVAR(dropMode), false];
Expand Down
5 changes: 4 additions & 1 deletion addons/advanced_throwing/functions/fnc_prepare.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,15 @@ if (_unit getVariable [QGVAR(inHand), false]) exitWith {
TRACE_1("inHand",_unit);
if (!(_unit getVariable [QGVAR(primed), false])) then {
TRACE_1("not primed",_unit);
// Restore muzzle ammo (setAmmo 1 has no impact if no appliccable throwable in inventory)
// selectNextGrenade relies on muzzles array (setAmmo 0 removes the muzzle from the array and current can't be found, cycles between 0 and 1 muzzles)
ACE_player setAmmo [ACE_player getVariable [QGVAR(activeMuzzle), ""], 1];
[_unit] call EFUNC(weaponselect,selectNextGrenade);
};
};

// Try selecting next throwable if none currently selected
if ((isNull (_unit getVariable [QGVAR(activeThrowable), objNull])) && {(currentThrowable _unit) isEqualTo []} && {!([_unit] call EFUNC(weaponselect,selectNextGrenade))}) exitWith {
if (isNull (_unit getVariable [QGVAR(activeThrowable), objNull]) && {(currentThrowable _unit) isEqualTo []} && {!([_unit] call EFUNC(weaponselect,selectNextGrenade))}) exitWith {
TRACE_1("no throwables",_unit);
};

Expand Down
5 changes: 4 additions & 1 deletion addons/advanced_throwing/functions/fnc_prime.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,10 @@ private _throwableMag = (currentThrowable _unit) select 0;
_unit removeItem _throwableMag;

private _throwableType = getText (configFile >> "CfgMagazines" >> _throwableMag >> "ammo");
private _muzzle = (_unit getVariable [QGVAR(activeMuzzle), ["", 0]]) select 0;
private _muzzle = _unit getVariable [QGVAR(activeMuzzle), ""];

// Set muzzle ammo to 0 to block vanilla throwing (can only be 0 or 1), removeItem above resets it
_unit setAmmo [_muzzle, 0];

// Create actual throwable globally
private _activeThrowableOld = _unit getVariable [QGVAR(activeThrowable), objNull];
Expand Down
4 changes: 4 additions & 0 deletions addons/weaponselect/XEH_postInit.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ if (!hasInterface) exitWith {};
["ACE3 Weapons", QGVAR(SelectGrenadeFrag), localize LSTRING(SelectGrenadeFrag), {
// Conditions: canInteract
if !([ACE_player, ACE_player, ["isNotInside", "isNotEscorting"]] call EFUNC(common,canInteractWith)) exitWith {false};
// Don't change mode or show hint if advanced throwing is active
if (ACE_player getVariable [QEGVAR(advanced_throwing,inHand), false]) exitWith {false};

// Statement
[ACE_player, 1] call FUNC(selectNextGrenade);
Expand All @@ -83,6 +85,8 @@ if (!hasInterface) exitWith {};
["ACE3 Weapons", QGVAR(SelectGrenadeOther), localize LSTRING(SelectGrenadeOther), {
// Conditions: canInteract
if !([ACE_player, ACE_player, ["isNotInside", "isNotEscorting"]] call EFUNC(common,canInteractWith)) exitWith {false};
// Don't change mode or show hint if advanced throwing is active
if (ACE_player getVariable [QEGVAR(advanced_throwing,inHand), false]) exitWith {false};

// Statement
[ACE_player, 2] call FUNC(selectNextGrenade);
Expand Down

0 comments on commit 0400a85

Please sign in to comment.