From 771284a2979bf00f9f1c64fa7a156a3963781866 Mon Sep 17 00:00:00 2001 From: ebaydayz Date: Tue, 6 Sep 2016 16:36:45 -0400 Subject: [PATCH] Auto select main weapon after throwing Also added to gear unload so player will auto select pistol if picking one up with flares in their hands. Vanilla commit: https://github.com/DayZMod/DayZ/commit/08449fdfda6a3c7d5c3522e64de9b50eedb13454 --- .../Configs/RscDisplay/RscDisplayGear.hpp | 2 +- SQF/dayz_code/compile/player_fired.sqf | 3 +++ SQF/dayz_code/compile/player_selectWeapon.sqf | 22 +++++++++++++++++++ SQF/dayz_code/init/compiles.sqf | 1 + 4 files changed, 27 insertions(+), 1 deletion(-) create mode 100644 SQF/dayz_code/compile/player_selectWeapon.sqf diff --git a/SQF/dayz_code/Configs/RscDisplay/RscDisplayGear.hpp b/SQF/dayz_code/Configs/RscDisplay/RscDisplayGear.hpp index 3ef106199..cde641e04 100644 --- a/SQF/dayz_code/Configs/RscDisplay/RscDisplayGear.hpp +++ b/SQF/dayz_code/Configs/RscDisplay/RscDisplayGear.hpp @@ -7,7 +7,7 @@ class RscDisplayGear //onLoad = "[] spawn object_monitorGear; {player removeMagazines _x} count MeleeMagazines; call gear_ui_init; call ui_gear_sound; if (isNil('IGUI_GEAR_activeFilter')) then { IGUI_GEAR_activeFilter = 0;}; [_this,'onLoad'] execVM '\z\addons\dayz_code\system\handleGear.sqf'";/* diag_log 'RscDisplayGear : : onLoad'; */ //onUnload = "{player removeMagazines _x} count MeleeMagazines; call player_forceSave; call dayz_meleeMagazineCheck;"; /* diag_log 'RscDisplayGear : : onunLoad'; */ onLoad = "setMousePosition [0.5, 0.5];_this call fn_gearMenuChecks; false call dz_fn_meleeMagazines; [] spawn object_monitorGear; call gear_ui_init; call ui_gear_sound; if (isNil 'IGUI_GEAR_activeFilter') then {IGUI_GEAR_activeFilter = 0}; [_this, 'onLoad'] execVM '\z\addons\dayz_code\system\handleGear.sqf'"; - onUnload = "true call dz_fn_meleeMagazines; call player_forceSave;"; + onUnload = "true call dz_fn_meleeMagazines; call player_selectWeapon; call player_forceSave;"; onMouseMoving = "[] call gear_ui_hide;"; onMouseHolding = "[] call gear_ui_hide;"; diff --git a/SQF/dayz_code/compile/player_fired.sqf b/SQF/dayz_code/compile/player_fired.sqf index 79abd8723..f6e721061 100644 --- a/SQF/dayz_code/compile/player_fired.sqf +++ b/SQF/dayz_code/compile/player_fired.sqf @@ -98,5 +98,8 @@ if ((_ammo isKindOf "SmokeShell") or (_ammo isKindOf "GrenadeHandTimedWest") or publicVariable "PVDZ_obj_RoadFlare"; [_this] spawn player_throwObject; }; + + //Auto select main weapon after throwing + call player_selectWeapon; }; }; \ No newline at end of file diff --git a/SQF/dayz_code/compile/player_selectWeapon.sqf b/SQF/dayz_code/compile/player_selectWeapon.sqf new file mode 100644 index 000000000..2f0f422e4 --- /dev/null +++ b/SQF/dayz_code/compile/player_selectWeapon.sqf @@ -0,0 +1,22 @@ +/* + Call this function to select primary or pistol (if no primary) + when the player's currently selected weapon is a throwable. +*/ + +private ["_main","_muzzle"]; + +if (currentWeapon player == "Throw") then { + _main = primaryWeapon player; + if (_main == "") then { + { + if (getNumber (configFile >> "CfgWeapons" >> _x >> "type") == 2) then {_main = _x;}; + } count (weapons player); + }; + + _muzzle = getArray (configFile >> "CfgWeapons" >> _main >> "muzzles"); + if (count _muzzle > 1) then { + player selectWeapon (_muzzle select 0); + } else { + player selectWeapon _main; + }; +}; \ No newline at end of file diff --git a/SQF/dayz_code/init/compiles.sqf b/SQF/dayz_code/init/compiles.sqf index d1248a28a..f53f1b94b 100644 --- a/SQF/dayz_code/init/compiles.sqf +++ b/SQF/dayz_code/init/compiles.sqf @@ -126,6 +126,7 @@ if (!isDedicated) then { //ui player_toggleSoundMute = compile preprocessFileLineNumbers "\z\addons\dayz_code\compile\player_toggleSoundMute.sqf"; player_selectSlot = compile preprocessFileLineNumbers "\z\addons\dayz_code\compile\ui_selectSlot.sqf"; + player_selectWeapon = compile preprocessFileLineNumbers "\z\addons\dayz_code\compile\player_selectWeapon.sqf"; player_gearSet = compile preprocessFileLineNumbers "\z\addons\dayz_code\compile\player_gearSet.sqf"; ui_changeDisplay = compile preprocessFileLineNumbers "\z\addons\dayz_code\compile\ui_changeDisplay.sqf"; ui_gear_sound = compile preprocessFileLineNumbers "\z\addons\dayz_code\compile\ui_gear_sound.sqf";