From f8819d3ee4c138e0b6926766ca4fa7ea7c83dc82 Mon Sep 17 00:00:00 2001 From: commy2 Date: Sun, 27 Sep 2015 14:55:36 +0200 Subject: [PATCH] WeaponSelect cleanup --- addons/weaponselect/XEH_postInit.sqf | 70 ++++++++----------- .../functions/fnc_fireSmokeLauncher.sqf | 10 +-- .../functions/fnc_playChangeFiremodeSound.sqf | 38 ++++------ .../functions/fnc_putWeaponAway.sqf | 2 +- 4 files changed, 49 insertions(+), 71 deletions(-) diff --git a/addons/weaponselect/XEH_postInit.sqf b/addons/weaponselect/XEH_postInit.sqf index 4d0df68f52..336358381a 100644 --- a/addons/weaponselect/XEH_postInit.sqf +++ b/addons/weaponselect/XEH_postInit.sqf @@ -4,8 +4,7 @@ if (!hasInterface) exitWith {}; // add keybinds -["ACE3 Weapons", QGVAR(SelectPistolNew), localize LSTRING(SelectPistol), -{ +["ACE3 Weapons", QGVAR(SelectPistolNew), localize LSTRING(SelectPistol), { // Conditions: canInteract if !([ACE_player, ACE_player, ["isNotInside", "isNotEscorting"]] call EFUNC(common,canInteractWith)) exitWith {false}; // Conditions: specific @@ -16,10 +15,9 @@ if (!hasInterface) exitWith {}; false }, {false}, -[0, [false, false, false]], false] call cba_fnc_addKeybind; //Unbound (was 1 Key) +[0, [false, false, false]], false] call CBA_fnc_addKeybind; //Unbound (was 1 Key) -["ACE3 Weapons", QGVAR(SelectRifleNew), localize LSTRING(SelectRifle), -{ +["ACE3 Weapons", QGVAR(SelectRifleNew), localize LSTRING(SelectRifle), { // Conditions: canInteract if !([ACE_player, ACE_player, ["isNotInside", "isNotEscorting"]] call EFUNC(common,canInteractWith)) exitWith {false}; // Conditions: specific @@ -30,10 +28,9 @@ if (!hasInterface) exitWith {}; false }, {false}, -[0, [false, false, false]], false] call cba_fnc_addKeybind; //Unbound (was 2 Key) +[0, [false, false, false]], false] call CBA_fnc_addKeybind; //Unbound (was 2 Key) -["ACE3 Weapons", QGVAR(SelectRifleMuzzleNew), localize LSTRING(SelectRifleMuzzle), -{ +["ACE3 Weapons", QGVAR(SelectRifleMuzzleNew), localize LSTRING(SelectRifleMuzzle), { // Conditions: canInteract if !([ACE_player, ACE_player, ["isNotInside", "isNotEscorting"]] call EFUNC(common,canInteractWith)) exitWith {false}; // Conditions: specific @@ -44,10 +41,9 @@ if (!hasInterface) exitWith {}; false }, {false}, -[0, [false, false, false]], false] call cba_fnc_addKeybind; //Unbound (was 3 Key) +[0, [false, false, false]], false] call CBA_fnc_addKeybind; //Unbound (was 3 Key) -["ACE3 Weapons", QGVAR(SelectLauncherNew), localize LSTRING(SelectLauncher), -{ +["ACE3 Weapons", QGVAR(SelectLauncherNew), localize LSTRING(SelectLauncher), { // Conditions: canInteract if !([ACE_player, ACE_player, ["isNotInside", "isNotEscorting"]] call EFUNC(common,canInteractWith)) exitWith {false}; // Conditions: specific @@ -58,10 +54,9 @@ if (!hasInterface) exitWith {}; false }, {false}, -[0, [false, false, false]], false] call cba_fnc_addKeybind; //Unbound (was 4 Key) +[0, [false, false, false]], false] call CBA_fnc_addKeybind; //Unbound (was 4 Key) -["ACE3 Weapons", QGVAR(SelectBinocularNew), localize LSTRING(SelectBinocular), -{ +["ACE3 Weapons", QGVAR(SelectBinocularNew), localize LSTRING(SelectBinocular), { // Conditions: canInteract if !([ACE_player, ACE_player, ["isNotInside", "isNotEscorting"]] call EFUNC(common,canInteractWith)) exitWith {false}; // Conditions: specific @@ -72,10 +67,9 @@ if (!hasInterface) exitWith {}; false }, {false}, -[0, [false, false, false]], false] call cba_fnc_addKeybind; //Unbound (was 5 Key) +[0, [false, false, false]], false] call CBA_fnc_addKeybind; //Unbound (was 5 Key) -["ACE3 Weapons", QGVAR(SelectGrenadeFrag), localize LSTRING(SelectGrenadeFrag), -{ +["ACE3 Weapons", QGVAR(SelectGrenadeFrag), localize LSTRING(SelectGrenadeFrag), { // Conditions: canInteract if !([ACE_player, ACE_player, ["isNotInside", "isNotEscorting"]] call EFUNC(common,canInteractWith)) exitWith {false}; // Conditions: specific @@ -86,10 +80,9 @@ if (!hasInterface) exitWith {}; true }, {false}, -[7, [false, false, false]], false] call cba_fnc_addKeybind; //6 Key +[7, [false, false, false]], false] call CBA_fnc_addKeybind; //6 Key -["ACE3 Weapons", QGVAR(SelectGrenadeOther), localize LSTRING(SelectGrenadeOther), -{ +["ACE3 Weapons", QGVAR(SelectGrenadeOther), localize LSTRING(SelectGrenadeOther), { // Conditions: canInteract if !([ACE_player, ACE_player, ["isNotInside", "isNotEscorting"]] call EFUNC(common,canInteractWith)) exitWith {false}; // Conditions: specific @@ -100,10 +93,9 @@ if (!hasInterface) exitWith {}; true }, {false}, -[8, [false, false, false]], false] call cba_fnc_addKeybind; //7 Key +[8, [false, false, false]], false] call CBA_fnc_addKeybind; //7 Key -["ACE3 Weapons", QGVAR(HolsterWeapon), localize LSTRING(HolsterWeapon), -{ +["ACE3 Weapons", QGVAR(HolsterWeapon), localize LSTRING(HolsterWeapon), { // Conditions: canInteract if !([ACE_player, ACE_player, ["isNotInside", "isNotEscorting"]] call EFUNC(common,canInteractWith)) exitWith {false}; // Conditions: specific @@ -125,10 +117,9 @@ if (!hasInterface) exitWith {}; true }, {false}, -[11, [false, false, false]], false] call cba_fnc_addKeybind; //0 Key +[11, [false, false, false]], false] call CBA_fnc_addKeybind; //0 Key -["ACE3 Vehicles", QGVAR(EngineOn), localize LSTRING(EngineOn), -{ +["ACE3 Vehicles", QGVAR(EngineOn), localize LSTRING(EngineOn), { // Conditions: canInteract if !([ACE_player, vehicle ACE_player, []] call EFUNC(common,canInteractWith)) exitWith {false}; // Conditions: specific @@ -139,10 +130,9 @@ if (!hasInterface) exitWith {}; true }, {false}, -[3, [false, false, false]], false] call cba_fnc_addKeybind; //2 Key +[3, [false, false, false]], false] call CBA_fnc_addKeybind; //2 Key -["ACE3 Vehicles", QGVAR(EngineOff), localize LSTRING(EngineOff), -{ +["ACE3 Vehicles", QGVAR(EngineOff), localize LSTRING(EngineOff), { // Conditions: canInteract if !([ACE_player, vehicle ACE_player, []] call EFUNC(common,canInteractWith)) exitWith {false}; // Conditions: specific @@ -153,10 +143,9 @@ if (!hasInterface) exitWith {}; true }, {false}, -[2, [false, false, false]], false] call cba_fnc_addKeybind; //1 Key +[2, [false, false, false]], false] call CBA_fnc_addKeybind; //1 Key -["ACE3 Vehicles", QGVAR(SelectMainGunNew), localize LSTRING(SelectMainGun), -{ +["ACE3 Vehicles", QGVAR(SelectMainGunNew), localize LSTRING(SelectMainGun), { // Conditions: canInteract if !([ACE_player, vehicle ACE_player, []] call EFUNC(common,canInteractWith)) exitWith {false}; // Conditions: specific @@ -167,10 +156,9 @@ if (!hasInterface) exitWith {}; true }, {false}, -[0, [false, false, false]], false] call cba_fnc_addKeybind; //Unbound (was 3 Key) +[0, [false, false, false]], false] call CBA_fnc_addKeybind; //Unbound (was 3 Key) -["ACE3 Vehicles", QGVAR(SelectMachineGunNew), localize LSTRING(SelectMachineGun), -{ +["ACE3 Vehicles", QGVAR(SelectMachineGunNew), localize LSTRING(SelectMachineGun), { // Conditions: canInteract if !([ACE_player, vehicle ACE_player, []] call EFUNC(common,canInteractWith)) exitWith {false}; // Conditions: specific @@ -181,10 +169,9 @@ if (!hasInterface) exitWith {}; true }, {false}, -[0, [false, false, false]], false] call cba_fnc_addKeybind; //Unbound (was 4 Key) +[0, [false, false, false]], false] call CBA_fnc_addKeybind; //Unbound (was 4 Key) -["ACE3 Vehicles", QGVAR(SelectMissilesNew), localize LSTRING(SelectMissiles), -{ +["ACE3 Vehicles", QGVAR(SelectMissilesNew), localize LSTRING(SelectMissiles), { // Conditions: canInteract if !([ACE_player, vehicle ACE_player, []] call EFUNC(common,canInteractWith)) exitWith {false}; // Conditions: specific @@ -195,10 +182,9 @@ if (!hasInterface) exitWith {}; true }, {false}, -[0, [false, false, false]], false] call cba_fnc_addKeybind; //Unbound (was 5 Key) +[0, [false, false, false]], false] call CBA_fnc_addKeybind; //Unbound (was 5 Key) -["ACE3 Vehicles", QGVAR(FireSmokeLauncher), localize LSTRING(FireSmokeLauncher), -{ +["ACE3 Vehicles", QGVAR(FireSmokeLauncher), localize LSTRING(FireSmokeLauncher), { // Conditions: canInteract if !([ACE_player, vehicle ACE_player, []] call EFUNC(common,canInteractWith)) exitWith {false}; // Conditions: specific @@ -209,4 +195,4 @@ if (!hasInterface) exitWith {}; true }, {false}, -[10, [false, false, false]], false] call cba_fnc_addKeybind; //9 Key +[10, [false, false, false]], false] call CBA_fnc_addKeybind; //9 Key diff --git a/addons/weaponselect/functions/fnc_fireSmokeLauncher.sqf b/addons/weaponselect/functions/fnc_fireSmokeLauncher.sqf index 20ef674dae..71ef89ecf6 100644 --- a/addons/weaponselect/functions/fnc_fireSmokeLauncher.sqf +++ b/addons/weaponselect/functions/fnc_fireSmokeLauncher.sqf @@ -15,10 +15,10 @@ */ #include "script_component.hpp" -private ["_turret", "_weapons"]; - params ["_vehicle"]; +private ["_turret", "_weapons"]; + _turret = [_vehicle] call EFUNC(common,getTurretCommander); _weapons = _vehicle weaponsTurret _turret; @@ -29,11 +29,10 @@ if ( ) then { //This doesn't work reliably for vehilces with additional weapons for the commander. Select smoke launcher instead. - private "_index"; - // avoid infinite loop if !("SmokeLauncher" in _weapons) exitWith {}; + private "_index"; _index = 0; while { _vehicle currentWeaponTurret _turret != "SmokeLauncher" @@ -46,8 +45,9 @@ if ( // fire away! private "_logic"; - _logic = createGroup sideLogic createUnit ["Logic", [0,0,0], [], 0, "NONE"]; + _logic action ["useWeapon", _vehicle, commander _vehicle, 0]; + deleteVehicle _logic; }; diff --git a/addons/weaponselect/functions/fnc_playChangeFiremodeSound.sqf b/addons/weaponselect/functions/fnc_playChangeFiremodeSound.sqf index c79f03c6f2..28ef5d21e5 100644 --- a/addons/weaponselect/functions/fnc_playChangeFiremodeSound.sqf +++ b/addons/weaponselect/functions/fnc_playChangeFiremodeSound.sqf @@ -1,6 +1,6 @@ /* * Author: commy2 - * Play the change firemode sound for specified weapon at units position. + * Play weapon firemode change sound. * * Arguments: * 0: Unit @@ -16,32 +16,24 @@ */ #include "script_component.hpp" -private ["_sound"]; - params ["_unit", "_weapon"]; +private ["_sound", "_position"]; + _sound = getArray (configFile >> "CfgWeapons" >> _weapon >> "changeFiremodeSound"); -if (count _sound == 0) exitWith {}; +if (_sound isEqualTo []) exitWith {}; -// add file extension -if call { - { - if (toLower (_sound select 0) find _x == count toArray (_sound select 0) - count toArray _x - 1) exitWith {false}; - true - } forEach [".wav", ".ogg", ".wss"]; -} then { - _sound set [0, (_sound select 0) + ".wss"]; +// get position where to play the sound (position of the weapon) +_position = AGLToASL (_unit modelToWorldVisual (_unit selectionPosition "RightHand")); + +_sound params ["_filename", ["_volume", 1], ["_soundPitch", 1], ["_distance", 0]]; + +if (_filename == "") exitWith {}; + +// add file extension .wss as default +if !(toLower (_filename select [count _filename - 4]) in [".wav", ".ogg", ".wss"]) then { + _filename = format ["%1.wss", _filename]; }; -// add default volume, pitch and distance -if (count _sound < 2) then {_sound pushBack 1}; -if (count _sound < 3) then {_sound pushBack 1}; -if (count _sound < 4) then {_sound pushBack 0}; - -private "_position"; - -_position = _unit modelToWorldVisual (_unit selectionPosition "RightHand"); -_position set [2, (_position select 2) + ((getPosASLW _unit select 2) - (getPosATL _unit select 2) max 0)]; - -playSound3D [_sound select 0, objNull, false, _position, _sound select 1, _sound select 2, _sound select 3]; +playSound3D [_filename, objNull, false, _position, _volume, _soundPitch, _distance]; diff --git a/addons/weaponselect/functions/fnc_putWeaponAway.sqf b/addons/weaponselect/functions/fnc_putWeaponAway.sqf index faddb4d869..fd1e463a4d 100644 --- a/addons/weaponselect/functions/fnc_putWeaponAway.sqf +++ b/addons/weaponselect/functions/fnc_putWeaponAway.sqf @@ -11,7 +11,7 @@ * Example: * [player] call ace_weaponselect_fnc_putWeaponAway * - * Public: NO + * Public: Yes */ #include "script_component.hpp"