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" #include "..\script_component.hpp"
/* /*
* Author: commy2 * Author: commy2, johnb43
* Get the available firing modes of a weapon. Will ignore the AI helper modes. * Get the available firing modes of a weapon. Will ignore the AI helper modes.
* *
* Arguments: * Arguments:
* 0: Weapon <STRING> * 0: Weapon <STRING>
* 1: Muzzle <STRING> (default: weapon)
* *
* Return Value: * Return Value:
* Firing Modes <ARRAY> * Firing Modes <ARRAY>
* *
* Example: * Example:
* ["gun"] call ace_common_fnc_getWeaponModes * "arifle_AK12_F" call ace_common_fnc_getWeaponModes
* *
* Public: Yes * Public: Yes
*/ */
params [["_weapon", "", [""]]]; params [["_weapon", "", [""]], ["_muzzle", nil, [""]]];
private _config = configFile >> "CfgWeapons" >> _weapon; private _config = configFile >> "CfgWeapons" >> _weapon;
if (!isNil "_muzzle") then {
_config = _config >> _muzzle
};
if (!isClass _config) exitWith {
[] // return
};
private _modes = []; private _modes = [];
{ {
if (getNumber (_config >> _x >> "showToPlayer") == 1) then { if (getNumber (_config >> _x >> "showToPlayer") == 1) then {
_modes pushBack _x; if (_x == "this") then {
}; _modes pushBack (configName _config);
} else {
if (_x == "this") then { if (isClass (_config >> _x)) then {
_modes pushBack _weapon; _modes pushBack (configName (_config >> _x));
};
};
}; };
} forEach getArray (_config >> "modes"); } 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"; _unit removeWeapon "ACE_FakePrimaryWeapon";
// Reselect weapon and re-enable sprint // Reselect weapon and re-enable sprint
private _previousWeaponIndex = _unit getVariable [QGVAR(previousWeapon), -1]; private _previousWeaponState = _unit getVariable QGVAR(previousWeapon);
_unit setVariable [QGVAR(previousWeapon), nil, true];
if (_previousWeaponIndex != -1) then { if (!isNil "_previousWeaponState") then {
_unit action ["SwitchWeapon", _unit, _unit, _previousWeaponIndex]; _unit selectWeapon _previousWeaponState;
_unit setVariable [QGVAR(previousWeapon), nil, true];
}; };
[_unit, "forceWalk", QUOTE(ADDON), false] call EFUNC(common,statusEffect_set); [_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 // 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 // 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; [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; _timer = CBA_missionTime + 10;
} else { } else {
// Select no weapon and stop sprinting // Select no weapon and stop sprinting
private _previousWeaponIndex = [_unit] call EFUNC(common,getFiremodeIndex); if (currentWeapon _unit != "") then {
_unit setVariable [QGVAR(previousWeapon), _previousWeaponIndex, true]; _unit setVariable [QGVAR(previousWeapon), (weaponState _unit) select [0, 3], true];
_unit action ["SwitchWeapon", _unit, _unit, 299]; _unit action ["SwitchWeapon", _unit, _unit, 299];
};
[_unit, "AmovPercMstpSnonWnonDnon", 0] call EFUNC(common,doAnimation); [_unit, "AmovPercMstpSnonWnonDnon", 0] call EFUNC(common,doAnimation);

View File

@ -46,7 +46,10 @@ if (!GVAR(dragAndFire)) then {
_primaryWeapon = "ACE_FakePrimaryWeapon"; _primaryWeapon = "ACE_FakePrimaryWeapon";
}; };
_unit selectWeapon _primaryWeapon; // 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 } else { // Making sure the unit is holding a primary weapon or handgun
private _handgunWeapon = handgunWeapon _unit; private _handgunWeapon = handgunWeapon _unit;

View File

@ -1,7 +1,7 @@
#include "..\script_component.hpp" #include "..\script_component.hpp"
/* /*
* Author: PabstMirror * Author: PabstMirror
* Handles player getting into new vehicle. Loads PFEG for mortar display if it is a mortar. * Handles player getting into new vehicle. Loads PFEG for mortar display if it is a mortar.
* *
* Arguments: * Arguments:
* 0: Player <OBJECT> * 0: Player <OBJECT>
@ -11,7 +11,7 @@
* None * None
* *
* Example: * Example:
* [bob, mortar] call ace_mk6mortar_fnc_handlePlayerVehicleChanged; * [player, cursorObject] call ace_mk6mortar_fnc_handlePlayerVehicleChanged
* *
* Public: No * Public: No
*/ */
@ -24,83 +24,78 @@ if !(_newVehicle isKindOf "Mortar_01_base_F") exitWith {};
private _tubeWeaponName = (weapons _newVehicle) select 0; private _tubeWeaponName = (weapons _newVehicle) select 0;
private _fireModes = getArray (configFile >> "CfgWeapons" >> _tubeWeaponName >> "modes"); private _fireModes = getArray (configFile >> "CfgWeapons" >> _tubeWeaponName >> "modes");
//Restore last firemode: // Restore last firemode
private _lastFireMode = _newVehicle getVariable [QGVAR(lastFireMode), -1]; private _lastSavedWeaponsInfo = _newVehicle getVariable QGVAR(lastFireMode);
if (_lastFireMode != -1) then {
_player action ["SwitchWeapon", _newVehicle, _player, _lastFireMode]; if (!isNil "_lastSavedWeaponsInfo") then {
_newVehicle selectWeaponTurret [_lastSavedWeaponsInfo select 0, [0], _lastSavedWeaponsInfo select 1, _lastSavedWeaponsInfo select 2];
}; };
[{ [{
params ["_args", "_pfID"]; params ["_mortarVeh", "_pfhID"];
_args params ["_mortarVeh", "_fireModes"];
if ((vehicle ACE_player) != _mortarVeh) then { if ((vehicle ACE_player) != _mortarVeh) exitWith {
[_pfID] call CBA_fnc_removePerFrameHandler; _pfhID call CBA_fnc_removePerFrameHandler;
};
// 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
closeDialog 0;
[parseText "Computer Disabled"] call EFUNC(common,displayTextStructured);
};
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 {
(_display displayCtrl 80156) ctrlSetText "";
} else { } else {
if (_useMils) then {
private _useMils = _mortarVeh getVariable [QGVAR(useMils), true]; (_display displayCtrl 80156) ctrlSetText str (((round (_realAzimuth * 6400 / 360)) + 6400) % 6400);
//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];
if (shownArtilleryComputer && {!GVAR(allowComputerRangefinder)}) then {
//Don't like this solution, but it works
closeDialog 0;
[parseText "Computer Disabled"] call EFUNC(common,displayTextStructured);
};
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";
// 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 {
(_display displayCtrl 80156) ctrlSetText "";
} else { } else {
(_display displayCtrl 80156) ctrlSetText str ((round (_realAzimuth + 360)) % 360);
};
};
// Update CurrentElevation Display
if (_notGunnerView) then {
(_display displayCtrl 80175) ctrlSetText "";
} else {
if (_useMils) then {
(_display displayCtrl 80175) ctrlSetText str ((round (_realElevation * 6400 / 360)) % 6400);
} else {
(_display displayCtrl 80175) ctrlSetText str (((round (_realElevation * 100)) / 100) % 360);
};
};
// Update ElevationNeeded Display
if (_notGunnerView || !GVAR(allowComputerRangefinder)) then {
(_display displayCtrl 80176) ctrlSetText "";
} else {
private _elevDeg = parseNumber ctrlText (_display displayCtrl 176);
if (_elevDeg <= 0) then { // Bad data means "----" out of range
(_display displayCtrl 80176) ctrlSetText (ctrlText (_display displayCtrl 176));
} else {
_elevDeg = _elevDeg + (_realElevation - (parseNumber ctrlText (_display displayCtrl 175)));
if (_useMils) then { if (_useMils) then {
(_display displayCtrl 80156) ctrlSetText str (((round (_realAzimuth * 6400 / 360)) + 6400) % 6400); (_display displayCtrl 80176) ctrlSetText str round ((round (_elevDeg * 6400 / 360)) % 6400);
} else { } else {
(_display displayCtrl 80156) ctrlSetText str ((round (_realAzimuth + 360)) % 360); (_display displayCtrl 80176) ctrlSetText str (((round (_elevDeg * 100)) / 100) % 360);
};
};
//Update CurrentElevation Display
if (_notGunnerView) then {
(_display displayCtrl 80175) ctrlSetText "";
} else {
if (_useMils) then {
(_display displayCtrl 80175) ctrlSetText str ((round (_realElevation * 6400 / 360)) % 6400);
} else {
(_display displayCtrl 80175) ctrlSetText str (((round (_realElevation * 100)) / 100) % 360);
};
};
//Update ElevationNeeded Display:
if (_notGunnerView || (!GVAR(allowComputerRangefinder))) then {
(_display displayCtrl 80176) ctrlSetText "";
} else {
private _elevDeg = parseNumber ctrlText (_display displayCtrl 176);
if (_elevDeg <= 0) then { //Bad data means "----" out of range
(_display displayCtrl 80176) ctrlSetText (ctrlText (_display displayCtrl 176));
} else {
_elevDeg = _elevDeg + (_realElevation - (parseNumber ctrlText (_display displayCtrl 175)));
if (_useMils) then {
(_display displayCtrl 80176) ctrlSetText str round ((round (_elevDeg * 6400 / 360)) % 6400);
} else {
(_display displayCtrl 80176) ctrlSetText str (((round (_elevDeg * 100)) / 100) % 360);
};
}; };
}; };
}; };
}, 0, [_newVehicle, _fireModes]] call CBA_fnc_addPerFrameHandler; }, 0, _newVehicle] call CBA_fnc_addPerFrameHandler;

View File

@ -28,7 +28,9 @@
#define REARM_HOLSTER_WEAPON \ #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); \ TRACE_2("REARM_HOLSTER_WEAPON",_unit,currentWeapon _unit); \
_unit action ["SwitchWeapon", _unit, _unit, 299]; _unit action ["SwitchWeapon", _unit, _unit, 299];

View File

@ -149,10 +149,15 @@ if (_callbackProgress == "") then {
// Player Animation // Player Animation
private _callerAnim = [getText (_config >> "animationCaller"), getText (_config >> "animationCallerProne")] select (stance _caller == "PRONE"); private _callerAnim = [getText (_config >> "animationCaller"), getText (_config >> "animationCallerProne")] select (stance _caller == "PRONE");
private _loopAnim = (getNumber (_config >> "loopAnimation")) isEqualTo 1; 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 // Cannot use secondairy weapon for animation
if (currentWeapon _caller == secondaryWeapon _caller) then { if (_currentWeapon == secondaryWeapon _caller) then {
_caller selectWeapon (primaryWeapon _caller); _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(repairCurrentAnimCaller), nil];
_caller setVariable [QGVAR(repairPrevAnimCaller), nil]; _caller setVariable [QGVAR(repairPrevAnimCaller), nil];
private _weaponSelect = (_caller getVariable [QGVAR(selectedWeaponOnrepair), ""]); private _weaponSelect = _caller getVariable QGVAR(selectedWeaponOnrepair);
if (_weaponSelect != "") then {
if (!isNil "_weaponSelect") then {
_caller selectWeapon _weaponSelect; _caller selectWeapon _weaponSelect;
_caller setVariable [QGVAR(selectedWeaponOnrepair), nil];
} else { } else {
_caller action ["SwitchWeapon", _caller, _caller, 299]; _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(repairCurrentAnimCaller), nil];
_caller setVariable [QGVAR(repairPrevAnimCaller), nil]; _caller setVariable [QGVAR(repairPrevAnimCaller), nil];
private _weaponSelect = (_caller getVariable [QGVAR(selectedWeaponOnrepair), ""]); private _weaponSelect = _caller getVariable QGVAR(selectedWeaponOnrepair);
if (_weaponSelect != "") then {
if (!isNil "_weaponSelect") then {
_caller selectWeapon _weaponSelect; _caller selectWeapon _weaponSelect;
_caller setVariable [QGVAR(selectedWeaponOnrepair), nil];
} else { } else {
_caller action ["SwitchWeapon", _caller, _caller, 299]; _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 // Saves the gear when the player! (and only him) is killed
if (ACE_player == _unit && {GVAR(SavePreDeathGear)}) then { if (ACE_player == _unit && {GVAR(SavePreDeathGear)}) then {
_unit setVariable [QGVAR(unitGear), [_unit] call CBA_fnc_getLoadout]; _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; [QGVAR(saveGear), _unit] call CBA_fnc_localEvent;
}; };

View File

@ -5,7 +5,8 @@
* *
* Arguments: * Arguments:
* 0: Unit <OBJECT> * 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: * Return Value:
* None * None
@ -19,36 +20,12 @@
params ["_unit", "_allGear", "_activeWeaponAndMuzzle"]; params ["_unit", "_allGear", "_activeWeaponAndMuzzle"];
TRACE_3("restoreGear",_unit,count _allGear,_activeWeaponAndMuzzle); TRACE_3("restoreGear",_unit,count _allGear,_activeWeaponAndMuzzle);
// restore all gear // Restore all gear
if (!isNil "_allGear") then { if (!isNil "_allGear") then {
[_unit, _allGear] call CBA_fnc_setLoadout; [_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 { if (!isNil "_activeWeaponAndMuzzle") then {
// @todo, replace this with CBA_fnc_selectWeapon after next CBA update _unit selectWeapon _activeWeaponAndMuzzle;
_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;
};
};
}; };

View File

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

View File

@ -18,35 +18,23 @@
params ["_unit", "_weapon"]; 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 { 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 { if (_weapon in (_unit getVariable [QEGVAR(safemode,safedWeapons), []])) exitWith {
[_unit, _weapon, _weapon] call EFUNC(safemode,unlockSafety); [_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}; // Play fire mode selector sound
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
[_unit, _weapon] call FUNC(playChangeFiremodeSound); [_unit, _weapon] call FUNC(playChangeFiremodeSound);

View File

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