ACE3/addons/weaponselect/functions/fnc_selectWeaponMuzzle.sqf
johnb432 5cada7d397
General - Remove "SwitchWeapon" spam (#10113)
* Remove "switchWeapon" spam

* Update fnc_startDragLocal.sqf

* Don't add invalid fire modes

* Tweaks & fix
2024-07-20 08:13:42 +02:00

40 lines
965 B
Plaintext

#include "..\script_component.hpp"
/*
* Author: commy2
* The player will select the specified weapon and change to the first additional muzzle. E.g. the grenade launcher of a assault rifle.
*
* Arguments:
* 0: Unit <OBJECT>
* 1: Weapon <STRING>
*
* Return Value:
* None
*
* Example:
* [player, currentWeapon player] call ace_weaponselect_fnc_selectWeaponMuzzle
*
* Public: No
*/
params ["_unit", "_weapon"];
if (_weapon == "" || {!(_unit hasWeapon _weapon)}) exitWith {};
private _muzzles = _weapon call EFUNC(common,getWeaponMuzzles);
if (count _muzzles <= 1) exitWith {};
private _muzzle = (_unit weaponState _weapon) select 1;
private _index = if (currentWeapon _unit == _weapon) then {
(((_muzzles find currentMuzzle _unit) + 1) % (count _muzzles)) max 1
} else {
1
};
private _muzzle = _muzzles select _index;
_unit selectWeapon [_weapon, _muzzle, ([_weapon, _muzzle] call EFUNC(common,getWeaponModes)) select 0];
nil // return