mirror of
https://github.com/acemod/ACE3.git
synced 2024-08-30 18:23:18 +00:00
6a25e9365a
* Refactor safemode * Further improvements and fixes * Update XEH_postInit.sqf * Don't allow binoculars to be set to safe * Add API for getting weapon safety status * Update fnc_jamWeapon.sqf * Added doc * Update fnc_playChangeFiremodeSound.sqf * Update addons/overheating/functions/fnc_jamWeapon.sqf Co-authored-by: PabstMirror <pabstmirror@gmail.com> * Update addons/weaponselect/functions/fnc_selectWeaponMode.sqf Co-authored-by: PabstMirror <pabstmirror@gmail.com> --------- Co-authored-by: PabstMirror <pabstmirror@gmail.com>
115 lines
4.4 KiB
Plaintext
115 lines
4.4 KiB
Plaintext
#include "..\script_component.hpp"
|
|
/*
|
|
* Author: Commy2, based on KK_fnc_playerWeaponMulfunction from KillzoneKid
|
|
* Jam the weapon
|
|
*
|
|
* Arguments:
|
|
* 0: Unit <OBJECT>
|
|
* 1: Weapon <STRING>
|
|
*
|
|
* Return Value:
|
|
* None
|
|
*
|
|
* Example:
|
|
* [player, currentWeapon player] call ace_overheating_fnc_jamWeapon
|
|
*
|
|
* Public: No
|
|
*/
|
|
|
|
params ["_unit", "_weapon"];
|
|
TRACE_2("params",_unit,_weapon);
|
|
|
|
// don't jam a weapon with no rounds left
|
|
private _ammo = _unit ammo _weapon;
|
|
if (_ammo < 1) exitWith {};
|
|
|
|
private _jammedWeapons = _unit getVariable [QGVAR(jammedWeapons), []];
|
|
_jammedWeapons pushBack _weapon;
|
|
|
|
_unit setVariable [QGVAR(jammedWeapons), _jammedWeapons];
|
|
|
|
// Get jam types, select one from available types
|
|
// Cookoffs only happen on Fire and Dud, dud rounds are lost on jam clear.
|
|
// Reduce chance of duds as temp increases (functionally increasing the chance of the others but with fewer commands)
|
|
private _temp = 1 max (_unit getVariable [format [QGVAR(%1_temp), _weapon], 0]);
|
|
private _jamTypesAllowed = getArray (configFile >> 'CfgWeapons' >> currentWeapon _unit >> QGVAR(jamTypesAllowed));
|
|
|
|
if (_jamTypesAllowed isEqualTo []) then {
|
|
_jamTypesAllowed = ["Eject", 1, "Extract", 1, "Feed", 1, "Fire", 1, "Dud", (5 / (_temp / 5))];
|
|
} else {
|
|
for "_i" from count _jamTypesAllowed to 1 step -1 do {
|
|
private _jamCurretType = _jamTypesAllowed select _i;
|
|
if !(_jamCurretType in ["Eject", "Extract", "Feed", "Fire", "Dud"]) exitWith { // check config values and switch to default values if unusual value found
|
|
ERROR_2("Weapon '%1' has unexpected value %2 in QQGVAR(jamTypesAllowed). Expected values are 'Eject', 'Extract', 'Feed', 'Fire', 'Dud'.",_weapon,_jamCurretType);
|
|
_jamTypesAllowed = ["Eject", 1, "Extract", 1, "Feed", 1, "Fire", 1, "Dud", (5 / (_temp / 5))];
|
|
};
|
|
if (_jamCurretType == "Dud") then {
|
|
_jamTypesAllowed insert [_i, [5 / (_temp / 5)]];
|
|
} else {
|
|
_jamTypesAllowed insert [_i, [1]];
|
|
};
|
|
};
|
|
};
|
|
|
|
private _jamType = selectRandomWeighted _jamTypesAllowed;
|
|
_unit setVariable [format [QGVAR(%1_jamType), _weapon], _jamType];
|
|
|
|
|
|
// Stop current burst
|
|
_unit setAmmo [_weapon, 0];
|
|
// this is to re-activate the 'DefaultAction', so you can jam a weapon while full auto shooting
|
|
[{
|
|
params ["_unit", "_weapon", "_ammo"];
|
|
_unit setAmmo [_weapon, _ammo];
|
|
}, [_unit, _weapon, _ammo]] call CBA_fnc_execNextFrame;
|
|
|
|
if (_weapon == primaryWeapon _unit) then {
|
|
playSound QGVAR(jamming_rifle);
|
|
} else {
|
|
if (_weapon == handgunWeapon _unit) then {
|
|
playSound QGVAR(jamming_pistol);
|
|
};
|
|
};
|
|
|
|
// only display the hint once, after you try to shoot an already jammed weapon
|
|
GVAR(knowAboutJam) = false;
|
|
|
|
["ace_weaponJammed", [_unit, _weapon, _jamType]] call CBA_fnc_localEvent;
|
|
|
|
if (_unit getVariable [QGVAR(JammingActionID), -1] == -1) then {
|
|
|
|
private _condition = {
|
|
private _unit = _this select 1;
|
|
(weaponState _unit) params ["_currentWeapon", "_currentMuzzle"];
|
|
|
|
_unit call CBA_fnc_canUseWeapon
|
|
&& {_currentMuzzle in (_unit getVariable [QGVAR(jammedWeapons), []])}
|
|
&& {!(["ace_safemode"] call EFUNC(common,isModLoaded)) || {!([_unit, _currentWeapon, _currentMuzzle] call EFUNC(safemode,getWeaponSafety))}}
|
|
};
|
|
|
|
private _statement = {
|
|
params ["_zero","_one"];
|
|
|
|
playSound3D ["a3\sounds_f\weapons\Other\dry9.wss", _zero, false, eyePos _zero, 1, 1, 15];
|
|
|
|
if (!(missionNamespace getVariable [QGVAR(knowAboutJam), false]) && {_one ammo currentWeapon _one > 0} && {GVAR(DisplayTextOnJam)}) then {
|
|
private _jamType = _one getVariable [format [QGVAR(%1_jamType), currentWeapon _one], "None"];
|
|
private _jamMessage = localize LSTRING(FailureToFire);
|
|
switch true do {
|
|
case (_jamType isEqualTo "Eject"): {_jamMessage = localize LSTRING(FailureToEject)};
|
|
case (_jamType isEqualTo "Extract"): {_jamMessage = localize LSTRING(FailureToExtract)};
|
|
case (_jamType isEqualTo "Feed"): {_jamMessage = localize LSTRING(FailureToFeed)};
|
|
};
|
|
[
|
|
[localize LSTRING(WeaponJammed)],
|
|
[_jamMessage]
|
|
] call CBA_fnc_notify;
|
|
GVAR(knowAboutJam) = true;
|
|
};
|
|
};
|
|
|
|
private _id = [_unit, "DefaultAction", _condition, _statement] call EFUNC(common,addActionEventHandler);
|
|
|
|
_unit setVariable [QGVAR(JammingActionID), _id];
|
|
};
|