General - Remove "SwitchWeapon" spam (#10113)

* Remove "switchWeapon" spam

* Update fnc_startDragLocal.sqf

* Don't add invalid fire modes

* Tweaks & fix
This commit is contained in:
johnb432 2024-07-20 08:13:42 +02:00 committed by GitHub
parent 68738316c2
commit 5cada7d397
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
14 changed files with 145 additions and 166 deletions

View File

@ -1,34 +1,45 @@
#include "..\script_component.hpp"
/*
* Author: commy2
* Author: commy2, johnb43
* Get the available firing modes of a weapon. Will ignore the AI helper modes.
*
* Arguments:
* 0: Weapon <STRING>
* 1: Muzzle <STRING> (default: weapon)
*
* Return Value:
* Firing Modes <ARRAY>
*
* Example:
* ["gun"] call ace_common_fnc_getWeaponModes
* "arifle_AK12_F" call ace_common_fnc_getWeaponModes
*
* Public: Yes
*/
params [["_weapon", "", [""]]];
params [["_weapon", "", [""]], ["_muzzle", nil, [""]]];
private _config = configFile >> "CfgWeapons" >> _weapon;
if (!isNil "_muzzle") then {
_config = _config >> _muzzle
};
if (!isClass _config) exitWith {
[] // return
};
private _modes = [];
{
if (getNumber (_config >> _x >> "showToPlayer") == 1) then {
_modes pushBack _x;
};
if (_x == "this") then {
_modes pushBack _weapon;
_modes pushBack (configName _config);
} else {
if (isClass (_config >> _x)) then {
_modes pushBack (configName (_config >> _x));
};
};
};
} forEach getArray (_config >> "modes");
_modes
_modes // return

View File

@ -59,11 +59,12 @@ if (_target isKindOf "CAManBase" || {animationState _unit in CARRY_ANIMATIONS})
_unit removeWeapon "ACE_FakePrimaryWeapon";
// Reselect weapon and re-enable sprint
private _previousWeaponIndex = _unit getVariable [QGVAR(previousWeapon), -1];
_unit setVariable [QGVAR(previousWeapon), nil, true];
private _previousWeaponState = _unit getVariable QGVAR(previousWeapon);
if (_previousWeaponIndex != -1) then {
_unit action ["SwitchWeapon", _unit, _unit, _previousWeaponIndex];
if (!isNil "_previousWeaponState") then {
_unit selectWeapon _previousWeaponState;
_unit setVariable [QGVAR(previousWeapon), nil, true];
};
[_unit, "forceWalk", QUOTE(ADDON), false] call EFUNC(common,statusEffect_set);

View File

@ -50,7 +50,7 @@ if (_target isKindOf "CAManBase") then {
};
// Select primary, otherwise the carry animation actions don't work
_unit selectWeapon _primaryWeapon;
_unit selectWeapon _primaryWeapon; // This turns off lasers/lights
// Move a bit closer and adjust direction when trying to pick up a person
[QEGVAR(common,setDir), [_target, getDir _unit + 180], _target] call CBA_fnc_targetEvent;
@ -62,10 +62,11 @@ if (_target isKindOf "CAManBase") then {
_timer = CBA_missionTime + 10;
} else {
// Select no weapon and stop sprinting
private _previousWeaponIndex = [_unit] call EFUNC(common,getFiremodeIndex);
_unit setVariable [QGVAR(previousWeapon), _previousWeaponIndex, true];
if (currentWeapon _unit != "") then {
_unit setVariable [QGVAR(previousWeapon), (weaponState _unit) select [0, 3], true];
_unit action ["SwitchWeapon", _unit, _unit, 299];
};
[_unit, "AmovPercMstpSnonWnonDnon", 0] call EFUNC(common,doAnimation);

View File

@ -46,7 +46,10 @@ if (!GVAR(dragAndFire)) then {
_primaryWeapon = "ACE_FakePrimaryWeapon";
};
// Keep the laser/light on if the weapon is already selected
if (currentWeapon _unit != _primaryWeapon) then {
_unit selectWeapon _primaryWeapon;
};
} else { // Making sure the unit is holding a primary weapon or handgun
private _handgunWeapon = handgunWeapon _unit;

View File

@ -11,7 +11,7 @@
* None
*
* Example:
* [bob, mortar] call ace_mk6mortar_fnc_handlePlayerVehicleChanged;
* [player, cursorObject] call ace_mk6mortar_fnc_handlePlayerVehicleChanged
*
* Public: No
*/
@ -24,28 +24,22 @@ if !(_newVehicle isKindOf "Mortar_01_base_F") exitWith {};
private _tubeWeaponName = (weapons _newVehicle) select 0;
private _fireModes = getArray (configFile >> "CfgWeapons" >> _tubeWeaponName >> "modes");
//Restore last firemode:
private _lastFireMode = _newVehicle getVariable [QGVAR(lastFireMode), -1];
if (_lastFireMode != -1) then {
_player action ["SwitchWeapon", _newVehicle, _player, _lastFireMode];
// Restore last firemode
private _lastSavedWeaponsInfo = _newVehicle getVariable QGVAR(lastFireMode);
if (!isNil "_lastSavedWeaponsInfo") then {
_newVehicle selectWeaponTurret [_lastSavedWeaponsInfo select 0, [0], _lastSavedWeaponsInfo select 1, _lastSavedWeaponsInfo select 2];
};
[{
params ["_args", "_pfID"];
_args params ["_mortarVeh", "_fireModes"];
params ["_mortarVeh", "_pfhID"];
if ((vehicle ACE_player) != _mortarVeh) then {
[_pfID] call CBA_fnc_removePerFrameHandler;
} else {
if ((vehicle ACE_player) != _mortarVeh) exitWith {
_pfhID call CBA_fnc_removePerFrameHandler;
};
private _useMils = _mortarVeh getVariable [QGVAR(useMils), true];
//Compute: 'charge' from weaponstate
private _currentFireMode = (weaponState [_mortarVeh, [0]]) select 2;
private _currentChargeMode = _fireModes find _currentFireMode;
//Save firemode on vehicle:
_mortarVeh setVariable [QGVAR(lastFireMode), _currentChargeMode];
// Save firemode ('charge' from weaponstate) on vehicle
_mortarVeh setVariable [QGVAR(lastFireMode), (weaponState [_mortarVeh, [0]]) select [0, 3]];
if (shownArtilleryComputer && {!GVAR(allowComputerRangefinder)}) then {
// Don't like this solution, but it works
@ -54,18 +48,20 @@ if (_lastFireMode != -1) then {
};
private _display = uiNamespace getVariable ["ACE_Mk6_RscWeaponRangeArtillery", displayNull];
if (isNull _display) exitWith {}; // It may be null for the first frame
// Hud should hidden in 3rd person
private _notGunnerView = cameraView != "GUNNER";
private _useMils = _mortarVeh getVariable [QGVAR(useMils), true];
// Get aiming values from ace_artillerytables
// Note: it also handles displaying the "charge" level
private _realAzimuth = missionNamespace getVariable [QEGVAR(artillerytables,predictedAzimuth), -1];
private _realElevation = missionNamespace getVariable [QEGVAR(artillerytables,predictedElevation), -1];
//Update Heading Display:
if (_notGunnerView || (!GVAR(allowCompass))) then {
// Update Heading Display
if (_notGunnerView || !GVAR(allowCompass)) then {
(_display displayCtrl 80156) ctrlSetText "";
} else {
if (_useMils) then {
@ -86,8 +82,8 @@ if (_lastFireMode != -1) then {
};
};
//Update ElevationNeeded Display:
if (_notGunnerView || (!GVAR(allowComputerRangefinder))) then {
// Update ElevationNeeded Display
if (_notGunnerView || !GVAR(allowComputerRangefinder)) then {
(_display displayCtrl 80176) ctrlSetText "";
} else {
private _elevDeg = parseNumber ctrlText (_display displayCtrl 176);
@ -102,5 +98,4 @@ if (_lastFireMode != -1) then {
};
};
};
};
}, 0, [_newVehicle, _fireModes]] call CBA_fnc_addPerFrameHandler;
}, 0, _newVehicle] call CBA_fnc_addPerFrameHandler;

View File

@ -28,7 +28,9 @@
#define REARM_HOLSTER_WEAPON \
_unit setVariable [QGVAR(selectedWeaponOnRearm), currentWeapon _unit]; \
if (currentWeapon _unit != "") then { \
_unit setVariable [QGVAR(selectedWeaponOnRearm), (weaponState _unit) select [0, 3]]; \
}; \
TRACE_2("REARM_HOLSTER_WEAPON",_unit,currentWeapon _unit); \
_unit action ["SwitchWeapon", _unit, _unit, 299];

View File

@ -149,10 +149,15 @@ if (_callbackProgress == "") then {
// Player Animation
private _callerAnim = [getText (_config >> "animationCaller"), getText (_config >> "animationCallerProne")] select (stance _caller == "PRONE");
private _loopAnim = (getNumber (_config >> "loopAnimation")) isEqualTo 1;
_caller setVariable [QGVAR(selectedWeaponOnrepair), currentWeapon _caller];
private _currentWeapon = currentWeapon _caller;
if (_currentWeapon != "") then {
_caller setVariable [QGVAR(selectedWeaponOnrepair), (weaponState _caller) select [0, 3]];
};
// Cannot use secondairy weapon for animation
if (currentWeapon _caller == secondaryWeapon _caller) then {
if (_currentWeapon == secondaryWeapon _caller) then {
_caller selectWeapon (primaryWeapon _caller);
};

View File

@ -38,9 +38,11 @@ if (vehicle _caller == _caller && {!(_caller call EFUNC(common,isSwimming))}) th
_caller setVariable [QGVAR(repairCurrentAnimCaller), nil];
_caller setVariable [QGVAR(repairPrevAnimCaller), nil];
private _weaponSelect = (_caller getVariable [QGVAR(selectedWeaponOnrepair), ""]);
if (_weaponSelect != "") then {
private _weaponSelect = _caller getVariable QGVAR(selectedWeaponOnrepair);
if (!isNil "_weaponSelect") then {
_caller selectWeapon _weaponSelect;
_caller setVariable [QGVAR(selectedWeaponOnrepair), nil];
} else {
_caller action ["SwitchWeapon", _caller, _caller, 299];
};

View File

@ -38,9 +38,11 @@ if (vehicle _caller == _caller && {!(_caller call EFUNC(common,isSwimming))}) th
_caller setVariable [QGVAR(repairCurrentAnimCaller), nil];
_caller setVariable [QGVAR(repairPrevAnimCaller), nil];
private _weaponSelect = (_caller getVariable [QGVAR(selectedWeaponOnrepair), ""]);
if (_weaponSelect != "") then {
private _weaponSelect = _caller getVariable QGVAR(selectedWeaponOnrepair);
if (!isNil "_weaponSelect") then {
_caller selectWeapon _weaponSelect;
_caller setVariable [QGVAR(selectedWeaponOnrepair), nil];
} else {
_caller action ["SwitchWeapon", _caller, _caller, 299];
};

View File

@ -21,7 +21,7 @@ params ["_unit"];
// Saves the gear when the player! (and only him) is killed
if (ACE_player == _unit && {GVAR(SavePreDeathGear)}) then {
_unit setVariable [QGVAR(unitGear), [_unit] call CBA_fnc_getLoadout];
_unit setVariable [QGVAR(activeWeaponAndMuzzle), [currentWeapon _unit, currentMuzzle _unit, currentWeaponMode _unit]];
_unit setVariable [QGVAR(activeWeaponAndMuzzle), (weaponState _unit) select [0, 3]];
[QGVAR(saveGear), _unit] call CBA_fnc_localEvent;
};

View File

@ -5,7 +5,8 @@
*
* Arguments:
* 0: Unit <OBJECT>
* 1: All Gear based on return value of ACE_common_fnc_getAllGear <ARRAY>
* 1: All Gear based on return value of ace_common_fnc_getAllGear <ARRAY>
* 2: All weapon info needed for restoring previous weapon status <ARRAY>
*
* Return Value:
* None
@ -19,36 +20,12 @@
params ["_unit", "_allGear", "_activeWeaponAndMuzzle"];
TRACE_3("restoreGear",_unit,count _allGear,_activeWeaponAndMuzzle);
// restore all gear
// Restore all gear
if (!isNil "_allGear") then {
[_unit, _allGear] call CBA_fnc_setLoadout;
};
// restore the last active weapon, muzzle and weaponMode
// Restore the last active weapon, muzzle and weapon mode
if (!isNil "_activeWeaponAndMuzzle") then {
// @todo, replace this with CBA_fnc_selectWeapon after next CBA update
_activeWeaponAndMuzzle params ["_activeWeapon", "_activeMuzzle", "_activeWeaponMode"];
if (
(_activeMuzzle != "") &&
{_activeMuzzle != _activeWeapon} &&
{_activeMuzzle in getArray (configFile >> "CfgWeapons" >> _activeWeapon >> "muzzles")}
) then {
_unit selectWeapon _activeMuzzle;
} else {
if (_activeWeapon != "") then {
_unit selectWeapon _activeWeapon;
};
};
if (currentWeapon _unit != "") then {
private _index = 0;
while {
_index < 299 && {currentWeaponMode _unit != _activeWeaponMode}
} do {
_unit action ["SwitchWeapon", _unit, _unit, _index];
_index = _index + 1;
};
};
_unit selectWeapon _activeWeaponAndMuzzle;
};

View File

@ -35,3 +35,5 @@ if !(toLowerANSI (_filename select [count _filename - 4]) in [".wav", ".ogg", ".
};
playSound3D [_filename, objNull, false, _position, _volume, _soundPitch, _distance];
nil // return

View File

@ -18,35 +18,23 @@
params ["_unit", "_weapon"];
if (_weapon == "") exitWith {};
if (_weapon == "" || {!(_unit hasWeapon _weapon)}) exitWith {};
private _currentWeaponMode = (_unit weaponState _weapon) select 2;
private _muzzle = (_weapon call EFUNC(common,getWeaponMuzzles)) select 0;
if (currentWeapon _unit != _weapon) exitWith {
_unit selectWeapon _weapon;
_unit selectWeapon [_weapon, _muzzle, _currentWeaponMode];
};
// unlock safety
// Unlock safety
if (_weapon in (_unit getVariable [QEGVAR(safemode,safedWeapons), []])) exitWith {
[_unit, _weapon, _weapon] call EFUNC(safemode,unlockSafety);
};
private _muzzles = [_weapon] call EFUNC(common,getWeaponMuzzles);
private _modes = [_weapon] call EFUNC(common,getWeaponModes);
private _modes = _weapon call EFUNC(common,getWeaponModes);
private _index = (_modes find currentWeaponMode _unit) + 1;
_unit selectWeapon [_weapon, _muzzle, _modes select (((_modes find _currentWeaponMode) + 1) % (count _modes))];
if (_index > count _modes - 1) then {_index = 0};
private _muzzle = _muzzles select 0;
private _mode = _modes select _index;
_index = 0;
while {
_index < 299 && {currentMuzzle _unit != _muzzle || {currentWeaponMode _unit != _mode}}
} do {
_unit action ["SwitchWeapon", _unit, _unit, _index];
_index = _index + 1;
};
// play fire mode selector sound
// Play fire mode selector sound
[_unit, _weapon] call FUNC(playChangeFiremodeSound);

View File

@ -18,32 +18,22 @@
params ["_unit", "_weapon"];
if (_weapon == "") exitWith {};
if (_weapon == "" || {!(_unit hasWeapon _weapon)}) exitWith {};
private _muzzles = _weapon call EFUNC(common,getWeaponMuzzles);
if (currentWeapon _unit != _weapon) exitWith {
if (count _muzzles > 1) then {
if (count _muzzles <= 1) exitWith {};
// unlock safety
/*if (_weapon in (_unit getVariable [QEGVAR(safemode,safedWeapons), []])) exitWith {
[_unit, _weapon, _muzzles select 1] call EFUNC(safemode,unlockSafety);
};*/
private _muzzle = (_unit weaponState _weapon) select 1;
_unit selectWeapon (_muzzles select 1);
private _index = if (currentWeapon _unit == _weapon) then {
(((_muzzles find currentMuzzle _unit) + 1) % (count _muzzles)) max 1
} else {
1
};
};
private _index = (_muzzles find currentMuzzle _unit) + 1;
if (_index > count _muzzles - 1) then {_index = 1};
private _muzzle = _muzzles select _index;
_index = 0;
while {
_index < 299 && {currentMuzzle _unit != _muzzle}
} do {
_unit action ["SwitchWeapon", _unit, _unit, _index];
_index = _index + 1;
};
_unit selectWeapon [_weapon, _muzzle, ([_weapon, _muzzle] call EFUNC(common,getWeaponModes)) select 0];
nil // return