From e56e18bff3a18d4e25a9e7dab5d9f218ef4121b5 Mon Sep 17 00:00:00 2001 From: commy2 Date: Wed, 6 Jan 2016 22:42:02 +0100 Subject: [PATCH 1/2] Code cleanup 1.54 --- .../functions/fnc_backpackOpened.sqf | 13 +-- addons/backpacks/functions/fnc_isBackpack.sqf | 5 +- .../functions/fnc_onOpenInventory.sqf | 5 +- .../functions/fnc_replaceATWeapon.sqf | 16 ++-- .../functions/fnc_takeLoadedATWeapon.sqf | 19 ++-- .../functions/fnc_updateInventoryDisplay.sqf | 10 +-- addons/grenades/functions/fnc_flare.sqf | 3 +- .../functions/fnc_flashbangExplosionEH.sqf | 21 +++-- .../functions/fnc_flashbangThrownFuze.sqf | 2 +- addons/grenades/functions/fnc_nextMode.sqf | 18 ++-- .../grenades/functions/fnc_throwGrenade.sqf | 26 +++--- addons/hitreactions/XEH_preInit.sqf | 1 + .../hitreactions/functions/fnc_fallDown.sqf | 50 +---------- .../functions/fnc_getRandomAnimation.sqf | 51 +++++++++++ addons/movement/XEH_postInit.sqf | 5 +- addons/movement/functions/fnc_canClimb.sqf | 33 ++++--- addons/movement/functions/fnc_climb.sqf | 4 +- addons/movement/functions/fnc_getWeight.sqf | 6 +- addons/movement/functions/fnc_handleClimb.sqf | 6 +- addons/recoil/functions/fnc_camshake.sqf | 88 ++++++++++--------- addons/reload/XEH_postInit.sqf | 31 ++++--- addons/reload/functions/fnc_canLinkBelt.sqf | 16 ++-- addons/reload/functions/fnc_checkAmmo.sqf | 5 +- addons/reload/functions/fnc_displayAmmo.sqf | 34 ++++--- .../reload/functions/fnc_startLinkingBelt.sqf | 25 +++--- .../vehicles/functions/fnc_speedLimiter.sqf | 7 +- addons/weaponselect/XEH_postInit.sqf | 3 +- addons/weaponselect/XEH_preInit.sqf | 8 +- .../fnc_displayGrenadeTypeAndNumber.sqf | 10 +-- .../functions/fnc_fireSmokeLauncher.sqf | 14 ++- .../functions/fnc_playChangeFiremodeSound.sqf | 6 +- .../functions/fnc_putWeaponAway.sqf | 2 +- .../functions/fnc_selectNextGrenade.sqf | 18 ++-- .../functions/fnc_selectWeaponMode.sqf | 14 ++- .../functions/fnc_selectWeaponMuzzle.sqf | 8 +- .../functions/fnc_selectWeaponVehicle.sqf | 17 ++-- .../functions/fnc_throwGrenade.sqf | 3 +- 37 files changed, 276 insertions(+), 327 deletions(-) create mode 100644 addons/hitreactions/functions/fnc_getRandomAnimation.sqf diff --git a/addons/backpacks/functions/fnc_backpackOpened.sqf b/addons/backpacks/functions/fnc_backpackOpened.sqf index 4e61e8fbccd..b7ab4cd1f40 100644 --- a/addons/backpacks/functions/fnc_backpackOpened.sqf +++ b/addons/backpacks/functions/fnc_backpackOpened.sqf @@ -17,24 +17,17 @@ params ["_target", "_backpack"]; // do cam shake if the target is the player -if ([_target] call EFUNC(common,isPlayer)) then { +if (_target call EFUNC(common,isPlayer)) then { addCamShake [4, 0.5, 5]; }; // play a zipper sound effect -private ["_sounds", "_position"]; - -_sounds = [ - /*"a3\sounds_f\characters\ingame\AinvPknlMstpSlayWpstDnon_medic.wss", - "a3\sounds_f\characters\ingame\AinvPknlMstpSlayWrflDnon_medic.wss", - "a3\sounds_f\characters\ingame\AinvPpneMstpSlayWpstDnon_medic.wss", - "a3\sounds_f\characters\ingame\AinvPpneMstpSlayWrflDnon_medic.wss"*/ - +private _sounds = [ QUOTE(PATHTO_R(sounds\zip_in.wav)), QUOTE(PATHTO_R(sounds\zip_out.wav)) ]; -_position = AGLToASL (_target modelToWorldVisual (_target selectionPosition "Spine3")); +private _position = AGLToASL (_target modelToWorldVisual (_target selectionPosition "Spine3")); playSound3D [ _sounds select floor random count _sounds, diff --git a/addons/backpacks/functions/fnc_isBackpack.sqf b/addons/backpacks/functions/fnc_isBackpack.sqf index 68b59f803e8..d6b0fb10717 100644 --- a/addons/backpacks/functions/fnc_isBackpack.sqf +++ b/addons/backpacks/functions/fnc_isBackpack.sqf @@ -12,13 +12,12 @@ */ #include "script_component.hpp" -params ["_backpack"]; +params [["_backpack", objNull, [objNull]]]; if (_backpack isEqualType objNull) then { _backpack = typeOf _backpack; }; -private "_config"; -_config = configFile >> "CfgVehicles" >> _backpack; +private _config = configFile >> "CfgVehicles" >> _backpack; getText (_config >> "vehicleClass") == "backpacks" && {getNumber (_config >> "maximumLoad") > 0} // return diff --git a/addons/backpacks/functions/fnc_onOpenInventory.sqf b/addons/backpacks/functions/fnc_onOpenInventory.sqf index 154000202d0..d9a99535ebd 100644 --- a/addons/backpacks/functions/fnc_onOpenInventory.sqf +++ b/addons/backpacks/functions/fnc_onOpenInventory.sqf @@ -16,11 +16,10 @@ params ["_unit", "_backpack"]; // exit if the target is not a real backpack, i.e. parachute, static weapon bag etc. -if !([_backpack] call FUNC(isBackpack)) exitWith {false}; +if !(_backpack call FUNC(isBackpack)) exitWith {false}; // get the unit that wears the backpack object -private "_target"; -_target = objectParent _backpack; +private _target = objectParent _backpack; if (isNull _target) exitWith {false}; diff --git a/addons/disposable/functions/fnc_replaceATWeapon.sqf b/addons/disposable/functions/fnc_replaceATWeapon.sqf index f0cee0a048f..88e27190eda 100644 --- a/addons/disposable/functions/fnc_replaceATWeapon.sqf +++ b/addons/disposable/functions/fnc_replaceATWeapon.sqf @@ -24,15 +24,13 @@ params ["_unit", "_weapon", "", "", "", "", "_projectile"]; TRACE_3("params",_unit,_weapon,_projectile); -if ((!local _unit) || {_weapon != (secondaryWeapon _unit)}) exitWith {}; +if (!local _unit || {_weapon != secondaryWeapon _unit}) exitWith {}; -private ["_replacementTube", "_items"]; -_replacementTube = getText (configFile >> "CfgWeapons" >> _weapon >> "ACE_UsedTube"); +private _replacementTube = getText (configFile >> "CfgWeapons" >> _weapon >> "ACE_UsedTube"); if (_replacementTube == "") exitWith {}; //If no replacement defined just exit - //Save array of items attached to launcher -_items = secondaryWeaponItems _unit; +private _items = secondaryWeaponItems _unit; //Replace the orginal weapon with the 'usedTube' weapon _unit addWeapon _replacementTube; //Makes sure the used tube is still equiped @@ -55,12 +53,10 @@ if !([_unit] call EFUNC(common,isPlayer)) then { [_idPFH] call CBA_fnc_removePerFrameHandler; //If (tube is dropped) OR (is dead) OR (is player) just exit - if (((secondaryWeapon _unit) != _tube) || {!alive _unit} || {([_unit] call EFUNC(common,isPlayer))}) exitWith {}; - - private ["_items", "_container"]; + if (secondaryWeapon _unit != _tube || {!alive _unit} || {[_unit] call EFUNC(common,isPlayer)}) exitWith {}; - // _items = secondaryWeaponItems _unit; - _container = createVehicle ["GroundWeaponHolder", position _unit, [], 0, "CAN_COLLIDE"]; + //private _items = secondaryWeaponItems _unit; + private _container = createVehicle ["GroundWeaponHolder", position _unit, [], 0, "CAN_COLLIDE"]; _container setPosAsl (getPosAsl _unit); _container addWeaponCargoGlobal [_tube, 1]; diff --git a/addons/disposable/functions/fnc_takeLoadedATWeapon.sqf b/addons/disposable/functions/fnc_takeLoadedATWeapon.sqf index c371c8d5a50..bd6dec057cc 100644 --- a/addons/disposable/functions/fnc_takeLoadedATWeapon.sqf +++ b/addons/disposable/functions/fnc_takeLoadedATWeapon.sqf @@ -20,17 +20,12 @@ TRACE_1("params",_unit); if (!local _unit) exitWith {}; -private ["_launcher", "_config"]; - -_launcher = secondaryWeapon _unit; -_config = configFile >> "CfgWeapons" >> _launcher; +private _launcher = secondaryWeapon _unit; +private _config = configFile >> "CfgWeapons" >> _launcher; if (isClass _config && {getText (_config >> "ACE_UsedTube") != ""} && {getNumber (_config >> "ACE_isUsedLauncher") != 1} && {count secondaryWeaponMagazine _unit == 0}) then { - private ["_magazine", "_isLauncherSelected", "_didAdd"]; - - _magazine = getArray (_config >> "magazines") select 0; - - _isLauncherSelected = currentWeapon _unit == _launcher; + private _magazine = getArray (_config >> "magazines") select 0; + private _isLauncherSelected = currentWeapon _unit == _launcher; _unit removeMagazines _magazine; @@ -38,8 +33,9 @@ if (isClass _config && {getText (_config >> "ACE_UsedTube") != ""} && {getNumber _unit addBackpack "ACE_FakeBackpack"; _unit removeWeapon _launcher; _unit addMagazine _magazine; - _didAdd = _magazine in (magazines _unit); + private _didAdd = _magazine in magazines _unit; _unit addWeapon _launcher; + if (!_didAdd) then { TRACE_1("Failed To Add Disposable Magazine Normally, doing backup method (no backpack)",_unit); _unit addSecondaryWeaponItem _magazine; @@ -48,8 +44,9 @@ if (isClass _config && {getText (_config >> "ACE_UsedTube") != ""} && {getNumber } else { _unit removeWeapon _launcher; _unit addMagazine _magazine; - _didAdd = _magazine in (magazines _unit); + private _didAdd = _magazine in magazines _unit; _unit addWeapon _launcher; + if (!_didAdd) then { TRACE_2("Failed To Add Disposable Magazine Normally, doing backup method",_unit,(backpack _unit)); _unit addSecondaryWeaponItem _magazine; diff --git a/addons/disposable/functions/fnc_updateInventoryDisplay.sqf b/addons/disposable/functions/fnc_updateInventoryDisplay.sqf index 7f50e45089a..9908c861869 100644 --- a/addons/disposable/functions/fnc_updateInventoryDisplay.sqf +++ b/addons/disposable/functions/fnc_updateInventoryDisplay.sqf @@ -24,13 +24,11 @@ _player removeMagazines "ACE_FiredMissileDummy"; if (isNull _display) exitWith {}; -private ["_launcher", "_control", "_config"]; - -_launcher = secondaryWeapon _player; +private _launcher = secondaryWeapon _player; if (_launcher == "" || {getText (configFile >> "CfgWeapons" >> _launcher >> "ACE_UsedTube") == ""}) then { - _control = _display displayCtrl 627; - _config = configFile >> "RscDisplayInventory" >> "controls" >> "SlotSecondaryMagazine"; + private _control = _display displayCtrl 627; + private _config = configFile >> "RscDisplayInventory" >> "controls" >> "SlotSecondaryMagazine"; _control ctrlSetPosition [getNumber (_config >> "x"), getNumber (_config >> "y"), getNumber (_config >> "w"), getNumber (_config >> "h")]; _control ctrlCommit 0; @@ -39,7 +37,7 @@ if (_launcher == "" || {getText (configFile >> "CfgWeapons" >> _launcher >> "ACE _control ctrlSetPosition [getNumber (_config >> "x"), getNumber (_config >> "y"), getNumber (_config >> "w"), getNumber (_config >> "h")]; _control ctrlCommit 0; } else { - _control = _display displayCtrl 627; + private _control = _display displayCtrl 627; _control ctrlSetPosition [0, 0, 0, 0]; _control ctrlCommit 0; diff --git a/addons/grenades/functions/fnc_flare.sqf b/addons/grenades/functions/fnc_flare.sqf index bf1d5716406..74360e39b97 100644 --- a/addons/grenades/functions/fnc_flare.sqf +++ b/addons/grenades/functions/fnc_flare.sqf @@ -20,8 +20,7 @@ params ["_projectile", "_color", "_intensity", "_timeToLive"]; -private "_light"; -_light = "#lightpoint" createVehicleLocal position _projectile; +private _light = "#lightpoint" createVehicleLocal position _projectile; _light setLightColor _color; _light setLightAmbient _color; diff --git a/addons/grenades/functions/fnc_flashbangExplosionEH.sqf b/addons/grenades/functions/fnc_flashbangExplosionEH.sqf index 0ac65022843..06466c70d44 100644 --- a/addons/grenades/functions/fnc_flashbangExplosionEH.sqf +++ b/addons/grenades/functions/fnc_flashbangExplosionEH.sqf @@ -17,14 +17,12 @@ params ["_grenade"]; -private ["_affected", "_strength", "_posGrenade", "_eyePos", "_losCount", "_eyeDir", "_dirToUnitVector", "_angleDiff", "_light"]; - -_affected = _grenade nearEntities ["CAManBase", 20]; +private _affected = _grenade nearEntities ["CAManBase", 20]; { if (local _x && {alive _x}) then { - _strength = 1 - ((_x distance _grenade) min 15) / 15; + private _strength = 1 - ((_x distance _grenade) min 15) / 15; TRACE_3("FlashBangEffect Start",_x,(_x distance _grenade),_strength); @@ -47,12 +45,12 @@ _affected = _grenade nearEntities ["CAManBase", 20]; } else { //Do effects for player // is there line of sight to the grenade? - _posGrenade = getPosASL _grenade; - _eyePos = eyePos ACE_player; //PositionASL + private _posGrenade = getPosASL _grenade; + private _eyePos = eyePos ACE_player; //PositionASL _posGrenade set [2, (_posGrenade select 2) + 0.2]; // compensate for grenade glitching into ground //Check for line of sight (check 4 points in case grenade is stuck in an object or underground) - _losCount = { + private _losCount = { !lineIntersects [_posGrenade vectorAdd _x, _eyePos, _grenade, ACE_player] } count [[0,0,0], [0,0,0.2], [0.1, 0.1, 0.1], [-0.1, -0.1, 0.1]]; @@ -68,9 +66,9 @@ _affected = _grenade nearEntities ["CAManBase", 20]; // account for people looking away by slightly // reducing the effect for visual effects. - _eyeDir = (positionCameraToWorld [0,0,1] vectorDiff positionCameraToWorld [0,0,0]); - _dirToUnitVector = _eyePos vectorFromTo _posGrenade; - _angleDiff = acos (_eyeDir vectorDotProduct _dirToUnitVector); + private _eyeDir = (positionCameraToWorld [0,0,1] vectorDiff positionCameraToWorld [0,0,0]); + private _dirToUnitVector = _eyePos vectorFromTo _posGrenade; + private _angleDiff = acos (_eyeDir vectorDotProduct _dirToUnitVector); // from 0-45deg, full effect if (_angleDiff > 45) then { @@ -85,7 +83,8 @@ _affected = _grenade nearEntities ["CAManBase", 20]; }; // create flash to illuminate environment - _light = "#lightpoint" createVehicleLocal (getPos _grenade); + private _light = "#lightpoint" createVehicleLocal getPos _grenade; + _light setLightBrightness 200; _light setLightAmbient [1,1,1]; _light setLightColor [1,1,1]; diff --git a/addons/grenades/functions/fnc_flashbangThrownFuze.sqf b/addons/grenades/functions/fnc_flashbangThrownFuze.sqf index ae50e96e39a..ef6224f8ce9 100644 --- a/addons/grenades/functions/fnc_flashbangThrownFuze.sqf +++ b/addons/grenades/functions/fnc_flashbangThrownFuze.sqf @@ -20,7 +20,7 @@ params ["_projectile"]; if (alive _projectile) then { playSound3D ["A3\Sounds_F\weapons\Explosion\explosion_mine_1.wss", _projectile, false, getPosASL _projectile, 5, 1.2, 400]; - private _affected = _projectile nearEntities ["CAManBase", 20]; + private _affected = _projectile nearEntities ["CAManBase", 50]; ["flashbangExplosion", _affected, [_projectile]] call EFUNC(common,targetEvent); }; diff --git a/addons/grenades/functions/fnc_nextMode.sqf b/addons/grenades/functions/fnc_nextMode.sqf index 7789e12ac40..99149f51854 100644 --- a/addons/grenades/functions/fnc_nextMode.sqf +++ b/addons/grenades/functions/fnc_nextMode.sqf @@ -15,9 +15,7 @@ */ #include "script_component.hpp" -private ["_mode", "_hint"]; - -_mode = missionNamespace getVariable [QGVAR(currentThrowMode), 0]; +private _mode = missionNamespace getVariable [QGVAR(currentThrowMode), 0]; if (_mode == 4) then { _mode = 0; @@ -30,13 +28,13 @@ if (_mode == 3) then { _mode = 4; }; -_hint = [ -localize LSTRING(NormalThrow), -localize LSTRING(HighThrow), -localize LSTRING(PreciseThrow), -localize LSTRING(RollGrenade), -localize LSTRING(DropGrenade) -] select _mode; +private _hint = localize ([ + LSTRING(NormalThrow), + LSTRING(HighThrow), + LSTRING(PreciseThrow), + LSTRING(RollGrenade), + LSTRING(DropGrenade) +] select _mode); [_hint] call EFUNC(common,displayTextStructured); diff --git a/addons/grenades/functions/fnc_throwGrenade.sqf b/addons/grenades/functions/fnc_throwGrenade.sqf index 9439aef4bdd..e66498a8547 100644 --- a/addons/grenades/functions/fnc_throwGrenade.sqf +++ b/addons/grenades/functions/fnc_throwGrenade.sqf @@ -30,24 +30,22 @@ if (isNull _projectile) then { _projectile = nearestObject [_unit, _ammo]; }; +private _config = configFile >> "CfgAmmo" >> _ammo; + // handle special grenades if (local _unit) then { - if (getNumber (configFile >> "CfgAmmo" >> _ammo >> QGVAR(flashbang)) == 1) then { - private "_fuzeTime"; - _fuzeTime = getNumber (configFile >> "CfgAmmo" >> _ammo >> "explosionTime"); + if (getNumber (_config >> QGVAR(flashbang)) == 1) then { + private _fuzeTime = getNumber (_config >> "explosionTime"); [FUNC(flashbangThrownFuze), [_projectile], _fuzeTime, 0] call EFUNC(common,waitAndExecute); }; }; -if (getNumber (configFile >> "CfgAmmo" >> _ammo >> QGVAR(flare)) == 1) then { - private ["_fuzeTime", "_timeToLive", "_color", "_intensity"]; - - _fuzeTime = getNumber (configFile >> "CfgAmmo" >> _ammo >> "explosionTime"); - _timeToLive = getNumber (configFile >> "CfgAmmo" >> _ammo >> "timeToLive"); - _color = getArray (configFile >> "CfgAmmo" >> _ammo >> QGVAR(color)); - _intensity = _color select 3; - _color resize 3; +if (getNumber (_config >> QGVAR(flare)) == 1) then { + private _fuzeTime = getNumber (_config >> "explosionTime"); + private _timeToLive = getNumber (_config >> "timeToLive"); + private _color = getArray (_config >> QGVAR(color)); + private _intensity = _color deleteAt 3; [FUNC(flare), [_projectile, _color, _intensity, _timeToLive], _fuzeTime, 0] call EFUNC(common,waitAndExecute); }; @@ -55,12 +53,10 @@ if (getNumber (configFile >> "CfgAmmo" >> _ammo >> QGVAR(flare)) == 1) then { // handle throw modes if (_unit != ACE_player) exitWith {}; -private "_mode"; -_mode = missionNamespace getVariable [QGVAR(currentThrowMode), 0]; +private _mode = missionNamespace getVariable [QGVAR(currentThrowMode), 0]; if (_mode != 0) then { - private "_velocity"; - _velocity = velocity _projectile; + private _velocity = velocity _projectile; switch (_mode) do { //high throw diff --git a/addons/hitreactions/XEH_preInit.sqf b/addons/hitreactions/XEH_preInit.sqf index d3c0973ee70..88df4102a13 100644 --- a/addons/hitreactions/XEH_preInit.sqf +++ b/addons/hitreactions/XEH_preInit.sqf @@ -3,5 +3,6 @@ ADDON = false; PREP(fallDown); +PREP(getRandomAnimation); ADDON = true; diff --git a/addons/hitreactions/functions/fnc_fallDown.sqf b/addons/hitreactions/functions/fnc_fallDown.sqf index d93b99bd6b2..9ed43ae14f1 100644 --- a/addons/hitreactions/functions/fnc_fallDown.sqf +++ b/addons/hitreactions/functions/fnc_fallDown.sqf @@ -35,8 +35,7 @@ if (!isNil QUOTE(EFUNC(medical,playInjuredSound))) then { [_unit] call EFUNC(medical,playInjuredSound); }; -private "_vehicle"; -_vehicle = vehicle _unit; +private _vehicle = vehicle _unit; // handle static weapons if (_vehicle isKindOf "StaticWeapon") exitWith { @@ -53,61 +52,20 @@ if (_vehicle != _unit) exitWith {}; if !([_unit, _vehicle] call EFUNC(common,canInteractWith)) exitWith {}; // handle ladders -if (getNumber (configFile >> "CfgMovesMaleSdr" >> "States" >> animationState _unit >> "AGM_isLadder") == 1) exitWith { +if (getNumber (configFile >> "CfgMovesMaleSdr" >> "States" >> animationState _unit >> "ACE_isLadder") == 1) exitWith { _unit action ["LadderOff", nearestObject [position _unit, "House"]]; }; // only play animation when standing due to lack of animations, sry if !(stance _unit in ["CROUCH", "STAND"]) exitWith {}; -private "_velocity"; -_velocity = vectorMagnitude velocity _unit; +private _velocity = vectorMagnitude velocity _unit; // only fall when moving if (_velocity < 2) exitWith {}; // get correct animation by weapon -private "_anim"; - -call { - private "_weapon"; - _weapon = currentWeapon _unit; - - if (_weapon == "") exitWith { - _anim = "AmovPercMsprSnonWnonDf_AmovPpneMstpSnonWnonDnon" - }; - - if (_weapon == primaryWeapon _unit) exitWith { - if ([_unit] call EFUNC(common,isPlayer)) then { - private "_isRunning"; - _isRunning = _velocity > 4; - - _anim = [ - ["AmovPercMsprSlowWrfldf_AmovPpneMstpSrasWrflDnon_2", "AmovPercMsprSlowWrfldf_AmovPpneMstpSrasWrflDnon"] select _isRunning, - ["AmovPercMsprSlowWrfldf_AmovPpneMstpSrasWrflDnon_2", "AmovPercMsprSlowWrfldf_AmovPpneMstpSrasWrflDnon"] select _isRunning, - "AmovPercMstpSrasWrflDnon_AadjPpneMstpSrasWrflDleft", - "AmovPercMstpSrasWrflDnon_AadjPpneMstpSrasWrflDright" - ] select floor random 4; - } else { - _anim = "AmovPercMsprSlowWrfldf_AmovPpneMstpSrasWrflDnon"; - }; - }; - - if (_weapon == handgunWeapon _unit) exitWith { - if ([_unit] call EFUNC(common,isPlayer)) then { - _anim = [ - "AmovPercMsprSlowWpstDf_AmovPpneMstpSrasWpstDnon", - "AmovPercMsprSlowWpstDf_AmovPpneMstpSrasWpstDnon", - "AmovPercMstpSrasWpstDnon_AadjPpneMstpSrasWpstDleft", - "AmovPercMstpSrasWpstDnon_AadjPpneMstpSrasWpstDright" - ] select floor random 4; - } else { - _anim = "AmovPercMsprSlowWpstDf_AmovPpneMstpSrasWpstDnon"; - }; - }; - - _anim = ""; -}; +private _anim = _unit call FUNC(getRandomAnimation); // exit if no animation for this weapon exists, i.e. binocular or rocket launcher if (_anim == "") exitWith {}; diff --git a/addons/hitreactions/functions/fnc_getRandomAnimation.sqf b/addons/hitreactions/functions/fnc_getRandomAnimation.sqf new file mode 100644 index 00000000000..996901a31e3 --- /dev/null +++ b/addons/hitreactions/functions/fnc_getRandomAnimation.sqf @@ -0,0 +1,51 @@ +/* + * Author: commy2 + * Get a random fall animation for the unit. + * + * Arguments: + * 0: unit + * + * Return Value: + * Fall animation + * + * Public: No + */ +#include "script_component.hpp" + +params ["_unit"]; + +private _weapon = currentWeapon _unit; + +if (_weapon == "") exitWith { + "AmovPercMsprSnonWnonDf_AmovPpneMstpSnonWnonDnon" +}; + +if (_weapon == primaryWeapon _unit) exitWith { + if (_unit call EFUNC(common,isPlayer)) then { + private _isRunning = _velocity > 4; + + [ + ["AmovPercMsprSlowWrfldf_AmovPpneMstpSrasWrflDnon_2", "AmovPercMsprSlowWrfldf_AmovPpneMstpSrasWrflDnon"] select _isRunning, + ["AmovPercMsprSlowWrfldf_AmovPpneMstpSrasWrflDnon_2", "AmovPercMsprSlowWrfldf_AmovPpneMstpSrasWrflDnon"] select _isRunning, + "AmovPercMstpSrasWrflDnon_AadjPpneMstpSrasWrflDleft", + "AmovPercMstpSrasWrflDnon_AadjPpneMstpSrasWrflDright" + ] select floor random 4 + } else { + "AmovPercMsprSlowWrfldf_AmovPpneMstpSrasWrflDnon" + }; +}; + +if (_weapon == handgunWeapon _unit) exitWith { + if (_unit call EFUNC(common,isPlayer)) then { + [ + "AmovPercMsprSlowWpstDf_AmovPpneMstpSrasWpstDnon", + "AmovPercMsprSlowWpstDf_AmovPpneMstpSrasWpstDnon", + "AmovPercMstpSrasWpstDnon_AadjPpneMstpSrasWpstDleft", + "AmovPercMstpSrasWpstDnon_AadjPpneMstpSrasWpstDright" + ] select floor random 4 + } else { + "AmovPercMsprSlowWpstDf_AmovPpneMstpSrasWpstDnon" + }; +}; + +"" diff --git a/addons/movement/XEH_postInit.sqf b/addons/movement/XEH_postInit.sqf index 68229684c65..7825134af38 100644 --- a/addons/movement/XEH_postInit.sqf +++ b/addons/movement/XEH_postInit.sqf @@ -6,9 +6,8 @@ if (!hasInterface) exitWith {}; ["inventoryDisplayLoaded", { [{ - private "_dialog"; - - _dialog = _this select 0; + disableSerialization; + params ["_dialog"]; if (isNull _dialog) exitWith { [_this select 1] call CBA_fnc_removePerFrameHandler; diff --git a/addons/movement/functions/fnc_canClimb.sqf b/addons/movement/functions/fnc_canClimb.sqf index 671ab0b808c..ec4202dbd5b 100644 --- a/addons/movement/functions/fnc_canClimb.sqf +++ b/addons/movement/functions/fnc_canClimb.sqf @@ -15,33 +15,30 @@ */ #include "script_component.hpp" -private ["_pos", "_dir"]; +params ["_unit"]; -PARAMS_1(_unit); +private _pos = getPosASL _unit; +private _dir = getDir _unit; -_pos = getPosASL _unit; -_dir = getDir _unit; _dir = [sin _dir, cos _dir, 0]; -private ["_checkPos0beg", "_checkPos0end", "_checkPos1beg", "_checkPos1end"]; +private _checkPos0beg = _pos vectorAdd [0, 0, 0.9]; +private _checkPos0end = _checkPos0beg vectorAdd (_dir vectorMultiply 1.3); -_checkPos0beg = _pos vectorAdd [0, 0, 0.9]; -_checkPos0end = _checkPos0beg vectorAdd (_dir vectorMultiply 1.3); +private _checkPos1beg = _pos vectorAdd [0, 0, 1.75]; +private _checkPos1end = _checkPos1beg vectorAdd (_dir vectorMultiply 1.3); -_checkPos1beg = _pos vectorAdd [0, 0, 1.75]; -_checkPos1end = _checkPos1beg vectorAdd (_dir vectorMultiply 1.3); +private _checkPos2beg = _pos vectorAdd [0.3 * (_dir select 1), 0.3 * -(_dir select 0), 2.0]; +private _checkPos2end = _checkPos2beg vectorAdd (_dir vectorMultiply 1.3); -_checkPos2beg = _pos vectorAdd [0.3 * (_dir select 1), 0.3 * -(_dir select 0), 2.0]; -_checkPos2end = _checkPos2beg vectorAdd (_dir vectorMultiply 1.3); +private _checkPos3beg = _pos vectorAdd [-0.2 * (_dir select 1), -0.2 * -(_dir select 0), 2.0]; +private _checkPos3end = _checkPos3beg vectorAdd (_dir vectorMultiply 1.3); -_checkPos3beg = _pos vectorAdd [-0.2 * (_dir select 1), -0.2 * -(_dir select 0), 2.0]; -_checkPos3end = _checkPos3beg vectorAdd (_dir vectorMultiply 1.3); +private _checkPos4beg = _pos vectorAdd [0.3 * (_dir select 1), 0.3 * -(_dir select 0), 1.5]; +private _checkPos4end = _checkPos4beg vectorAdd (_dir vectorMultiply 1.3); -_checkPos4beg = _pos vectorAdd [0.3 * (_dir select 1), 0.3 * -(_dir select 0), 1.5]; -_checkPos4end = _checkPos4beg vectorAdd (_dir vectorMultiply 1.3); - -_checkPos5beg = _pos vectorAdd [-0.2 * (_dir select 1), -0.2 * -(_dir select 0), 1.5]; -_checkPos5end = _checkPos5beg vectorAdd (_dir vectorMultiply 1.3); +private _checkPos5beg = _pos vectorAdd [-0.2 * (_dir select 1), -0.2 * -(_dir select 0), 1.5]; +private _checkPos5end = _checkPos5beg vectorAdd (_dir vectorMultiply 1.3); /* drawLine3D [ASLToATL _checkPos0beg, ASLToATL _checkPos0end, [0,1,0,1]]; diff --git a/addons/movement/functions/fnc_climb.sqf b/addons/movement/functions/fnc_climb.sqf index a0946b95d07..57df4e5991e 100644 --- a/addons/movement/functions/fnc_climb.sqf +++ b/addons/movement/functions/fnc_climb.sqf @@ -15,9 +15,7 @@ */ #include "script_component.hpp" -private "_unit"; - -_unit = _this select 0; +params ["_unit"]; if !([_unit] call FUNC(canClimb)) exitWith { [localize LSTRING(CanNotClimb)] call EFUNC(common,displayTextStructured); diff --git a/addons/movement/functions/fnc_getWeight.sqf b/addons/movement/functions/fnc_getWeight.sqf index 6941173fde8..11dd8c4ee6d 100644 --- a/addons/movement/functions/fnc_getWeight.sqf +++ b/addons/movement/functions/fnc_getWeight.sqf @@ -15,11 +15,9 @@ */ #include "script_component.hpp" -private ["_unit", "_weight"]; +params ["_unit"]; -_unit = _this select 0; - -_weight = loadAbs _unit * 0.1; +private _weight = loadAbs _unit * 0.1; if (GVAR(useImperial)) then { _weight = format ["%1lb", (round (_weight * 100)) / 100]; diff --git a/addons/movement/functions/fnc_handleClimb.sqf b/addons/movement/functions/fnc_handleClimb.sqf index 39ca9b1e92d..e6d8fed12ca 100644 --- a/addons/movement/functions/fnc_handleClimb.sqf +++ b/addons/movement/functions/fnc_handleClimb.sqf @@ -16,12 +16,10 @@ */ #include "script_component.hpp" -private ["_unit", "_anim", "_pos"]; +params ["_unit", "_anim"]; -_unit = _this select 0; -_anim = _this select 1; +private _pos = _unit modelToWorldVisual (_unit selectionPosition "camera"); -_pos = _unit modelToWorldVisual (_unit selectionPosition "camera"); [_unit, "AmovPknlMstpSnonWnonDnon", 2] call EFUNC(common,doAnimation); _pos = _pos vectorDiff (_unit selectionPosition "camera"); diff --git a/addons/recoil/functions/fnc_camshake.sqf b/addons/recoil/functions/fnc_camshake.sqf index 806d48760b5..a8e1af75d96 100644 --- a/addons/recoil/functions/fnc_camshake.sqf +++ b/addons/recoil/functions/fnc_camshake.sqf @@ -1,7 +1,21 @@ -// TMR: Small Arms - Recoil initialization and functions -// (C) 2013 Ryan Schultz. See LICENSE. -// Edited prefixes for compatability in AGM_Realism by KoffeinFlummi -// Edited by commy2 +/* + * Author: Orginal by Ryan Schultz, edited by KoffeinFlummi, commy2 + * Adds camera shake when firing + * From TMR: Small Arms + * + * Arguments: + * 0: Unit + * 1: Weapon + * 3: Muzzle + * + * Return Value: + * Nothing + * + * Example: + * [player, (currentWeapon player), (currentMuzzle player)] call ace_recoil_fnc_camShake; + * + * Public: No + */ #include "script_component.hpp" #define BASE_POWER 0.40 @@ -9,59 +23,53 @@ #define BASE_FREQ 13 #define RECOIL_COEF 40 -private ["_unit", "_weapon", "_muzzle"]; - -_unit = _this select 0; -_weapon = _this select 1; -_muzzle = _this select 2; +params ["_unit", "_weapon", "_muzzle"]; if (toLower _weapon in ["throw", "put"]) exitWith {}; -private ["_powerMod", "_timeMod", "_freqMod"]; - -_powerMod = ([0, -0.1, -0.1, 0, -0.2] select (["STAND", "CROUCH", "PRONE", "UNDEFINED", ""] find stance _unit)) + ([0, -1, 0, -1] select (["INTERNAL", "EXTERNAL", "GUNNER", "GROUP"] find cameraView)); -_timeMod = 0; -_freqMod = 0; +private _powerMod = ([0, -0.1, -0.1, 0, -0.2] select (["STAND", "CROUCH", "PRONE", "UNDEFINED", ""] find stance _unit)) + ([0, -1, 0, -1] select (["INTERNAL", "EXTERNAL", "GUNNER", "GROUP"] find cameraView)); // to get camshake read kickback -private ["_config", "_recoil"]; +private _recoil = missionNamespace getVariable format [QGVAR(%1-%2), _weapon, _muzzle]; -_config = configFile >> "CfgWeapons" >> _weapon; -_recoil = if (_muzzle == _weapon) then { - getText (_config >> "recoil") -} else { - getText (_config >> _muzzle >> "recoil") -}; +if (isNil "_recoil") then { + private _config = configFile >> "CfgWeapons" >> _weapon; + + if (_muzzle == _weapon) then { + _recoil = getText (_config >> "recoil") + } else { + _recoil = getText (_config >> _muzzle >> "recoil") + }; -if (isClass (configFile >> "CfgRecoils" >> _recoil)) then { - _recoil = getArray (configFile >> "CfgRecoils" >> _recoil >> "kickBack"); - if (count _recoil < 2) then { + if (isClass (configFile >> "CfgRecoils" >> _recoil)) then { + _recoil = getArray (configFile >> "CfgRecoils" >> _recoil >> "kickBack"); + if (count _recoil < 2) then { + _recoil = [0, 0]; + }; + } else { _recoil = [0, 0]; }; -} else { - _recoil = [0, 0]; -}; -// parse numbers -_recoil set [0, call compile format ["%1", _recoil select 0]]; -_recoil set [1, call compile format ["%1", _recoil select 1]]; + TRACE_3("Caching Recoil config",_weapon,_muzzle,_recoil); + + // parse numbers + _recoil set [0, call compile format ["%1", _recoil select 0]]; + _recoil set [1, call compile format ["%1", _recoil select 1]]; -private "_powerCoef"; -_powerCoef = RECOIL_COEF * linearConversion [0, 1, random 1, _recoil select 0, _recoil select 1, false]; + missionNamespace setVariable [format [QGVAR(%1-%2), _weapon, _muzzle], _recoil]; +}; + +private _powerCoef = RECOIL_COEF * linearConversion [0, 1, random 1, _recoil select 0, _recoil select 1, false]; if (isWeaponRested _unit) then {_powerMod = _powerMod - 0.07}; if (isWeaponDeployed _unit) then {_powerMod = _powerMod - 0.11}; -private "_camshake"; -_camshake = [ +private _camshake = [ _powerCoef * (BASE_POWER + _powerMod) max 0, - BASE_TIME + _timeMod max 0, - BASE_FREQ + _freqMod max 0 + BASE_TIME, + BASE_FREQ ]; -/* - systemChat str _camshake; - copyToClipboard format ["addCamShake %1;", _camshake]; -*/ +TRACE_4("addCamShake",_recoil,_powerCoef,_powerMod,_camshake);\ addCamShake _camshake; diff --git a/addons/reload/XEH_postInit.sqf b/addons/reload/XEH_postInit.sqf index bd265836688..8667d9815e4 100644 --- a/addons/reload/XEH_postInit.sqf +++ b/addons/reload/XEH_postInit.sqf @@ -7,9 +7,9 @@ if (!hasInterface) exitWith {}; ["ACE3 Weapons", QGVAR(checkAmmo), localize LSTRING(checkAmmo), { // Conditions: canInteract - if !([ACE_player, (vehicle ACE_player), ["isNotInside", "isNotSitting"]] call EFUNC(common,canInteractWith)) exitWith {false}; + if !([ACE_player, vehicle ACE_player, ["isNotInside", "isNotSitting"]] call EFUNC(common,canInteractWith)) exitWith {false}; // Conditions: specific - if !([ACE_player] call EFUNC(common,canUseWeapon) || {(vehicle ACE_player) isKindOf "StaticWeapon"}) exitWith {false}; + if !(ACE_player call EFUNC(common,canUseWeapon) || {(vehicle ACE_player) isKindOf "StaticWeapon"}) exitWith {false}; // Statement [ACE_player] call FUNC(checkAmmo); @@ -20,26 +20,26 @@ if (!hasInterface) exitWith {}; ["setAmmoSync", { //To propagate the setAmmo change, do it on all clients - PARAMS_3(_unit,_weapon,_ammo); + params ["_unit", "_weapon", "_ammo"]; + TRACE_3("setAmmoSync EH",_unit,_weapon,_ammo); + _unit setAmmo [_weapon, _ammo]; }] call EFUNC(common,addEventhandler); // Listen for attempts to link ammo ["linkedAmmo", { - EXPLODE_3_PVT(_this,_receiver,_giver,_magazine); + params ["_receiver", "_giver", "_magazine"]; - private ["_magazineCfg","_magazineType"]; - _magazineType = currentMagazine _receiver; - _magazineCfg = configFile >> "CfgMagazines" >> _magazineType; + private _magazineType = currentMagazine _receiver; + private _magazineCfg = configFile >> "CfgMagazines" >> _magazineType; // Return the magazine if it's the wrong type if (_magazineType != (_magazine select 0)) exitWith { ["returnedAmmo", [_giver], [_giver,_receiver,_magazine]] call EFUNC(common,targetEvent); }; - private ["_ammoCount","_ammoMissing","_ammoAdded","_ammoRemaining"]; - _ammoCount = _receiver ammo currentWeapon _receiver; - _ammoMissing = getNumber (_magazineCfg >> "count") - _ammoCount; + private _ammoCount = _receiver ammo currentWeapon _receiver; + private _ammoMissing = getNumber (_magazineCfg >> "count") - _ammoCount; // Return the magazine if the belt is full or empty if ((_ammoCount == 0) || _ammoMissing == 0) exitWith { @@ -47,19 +47,18 @@ if (!hasInterface) exitWith {}; }; // Add the ammo - _ammoAdded = _ammoMissing min (_magazine select 1); - ["setAmmoSync", [_receiver, (currentWeapon _receiver), (_ammoCount + _ammoAdded)]] call EFUNC(common,globalEvent); + private _ammoAdded = _ammoMissing min (_magazine select 1); + ["setAmmoSync", [_receiver, currentWeapon _receiver, _ammoCount + _ammoAdded]] call EFUNC(common,globalEvent); if ((_magazine select 1) - _ammoAdded > 0) then { - ["returnedAmmo", [_giver], [_giver,_receiver,[_magazineType,(_magazine select 1) - _ammoAdded]]] call EFUNC(common,targetEvent); + ["returnedAmmo", [_giver], [_giver, _receiver, [_magazineType, (_magazine select 1) - _ammoAdded]]] call EFUNC(common,targetEvent); }; - }] call EFUNC(common,addEventhandler); - // Listen for returned magazines ["returnedAmmo", { - EXPLODE_3_PVT(_this,_receiver,_giver,_magazine); + params ["_receiver", "", "_magazine"]; + TRACE_2("returnedAmmo EH",_receiver,_magazine); _receiver addMagazine _magazine; }] call EFUNC(common,addEventhandler); diff --git a/addons/reload/functions/fnc_canLinkBelt.sqf b/addons/reload/functions/fnc_canLinkBelt.sqf index 4461b4f3e31..b36959e4e1a 100644 --- a/addons/reload/functions/fnc_canLinkBelt.sqf +++ b/addons/reload/functions/fnc_canLinkBelt.sqf @@ -11,26 +11,24 @@ */ #include "script_component.hpp" -EXPLODE_2_PVT(_this,_player,_target); +params ["_player", "_target"]; if (vehicle _target != _target) exitWith {false}; -private ["_magazineCfg","_magazineType"]; -_magazineType = currentMagazine _target; -_magazineCfg = configFile >> "CfgMagazines" >> _magazineType; +private _magazineType = currentMagazine _target; +private _magazineCfg = configFile >> "CfgMagazines" >> _magazineType; + if (getNumber (_magazineCfg >> "ACE_isBelt") == 0) exitWith {false}; // Check if the ammo is not empty or full -private "_ammoCount"; -_ammoCount = _target ammo currentWeapon _target; +private _ammoCount = _target ammo currentWeapon _target; // Exit if the belt is full or empty -if ((_ammoCount == 0) || (getNumber (_magazineCfg >> "count") - _ammoCount) == 0) exitWith {false}; +if (_ammoCount == 0 || getNumber (_magazineCfg >> "count") - _ammoCount == 0) exitWith {false}; // Check if the player has any of the same magazines // Calculate max ammo -private "_maxAmmo"; -_maxAmmo = 0; +private _maxAmmo = 0; { _maxAmmo = _maxAmmo max (_x select 1); diff --git a/addons/reload/functions/fnc_checkAmmo.sqf b/addons/reload/functions/fnc_checkAmmo.sqf index 2499a9a8934..b0581a143a6 100644 --- a/addons/reload/functions/fnc_checkAmmo.sqf +++ b/addons/reload/functions/fnc_checkAmmo.sqf @@ -13,10 +13,9 @@ #define COUNT_BARS 12 -EXPLODE_1_PVT(_this,_unit); +params ["_unit"]; -private ["_target"]; -_target = vehicle _unit; +private _target = vehicle _unit; if (count _this > 1) then { _target = _this select 1; diff --git a/addons/reload/functions/fnc_displayAmmo.sqf b/addons/reload/functions/fnc_displayAmmo.sqf index 993283ca56c..d4143e57d12 100644 --- a/addons/reload/functions/fnc_displayAmmo.sqf +++ b/addons/reload/functions/fnc_displayAmmo.sqf @@ -14,11 +14,9 @@ EXPLODE_1_PVT(_this,_target); -private ["_weapon","_muzzle","_magazine","_showNumber","_ammo","_maxRounds","_count","_text","_color","_picture","_ammoBarsStructuredText", "_a", "_loadedName", "_string"]; - -_weapon = currentWeapon _target; -_muzzle = currentMuzzle _target; -_magazine = currentMagazine _target; +private _weapon = currentWeapon _target; +private _muzzle = currentMuzzle _target; +private _magazine = currentMagazine _target; // currentWeapon returns "" for static weapons before they are shot once if (_target isKindOf "StaticWeapon") then { @@ -31,8 +29,8 @@ if (_target isKindOf "StaticWeapon") then { if (_magazine == "") then { // Try to get magazine using magazinesAmmoFull - private ["_magazines"]; - _magazines = magazinesAmmoFull _target; + private _magazines = magazinesAmmoFull _target; + { if (_x select 2) exitWith { _magazine = _x select 0; @@ -45,10 +43,10 @@ if (_magazine == "") exitWith {}; if (_weapon == "") exitWith {}; if (!( _muzzle isEqualType "")) then {_muzzle = _weapon}; -_showNumber = false; -_ammo = 0; -_maxRounds = 1; -_count = 0; +private _showNumber = false; +private _ammo = 0; +private _maxRounds = 1; +private _count = 0; // not grenade launcher if (_muzzle == _weapon) then { @@ -75,16 +73,16 @@ if (_muzzle == _weapon) then { }; }; -_ammoBarsStructuredText = if (_showNumber) then { +private _ammoBarsStructuredText = if (_showNumber) then { parseText format ["%1x", _count] } else { - _color = [((2 * (1 - _ammo / _maxRounds)) min 1), ((2 * _ammo / _maxRounds) min 1), 0]; + private _color = [((2 * (1 - _ammo / _maxRounds)) min 1), ((2 * _ammo / _maxRounds) min 1), 0]; - _string = ""; + private _string = ""; for "_a" from 1 to _count do { _string = _string + "|"; }; - _text = [_string, _color] call EFUNC(common,stringToColoredText); + private _text = [_string, _color] call EFUNC(common,stringToColoredText); _string = ""; for "_a" from (_count + 1) to (_maxRounds min COUNT_BARS) do { @@ -97,11 +95,11 @@ _ammoBarsStructuredText = if (_showNumber) then { if (_target isKindOf "StaticWeapon") then { //Vehicle mags (usualy) don't have pictures, so just show the text above ammo count - _loadedName = getText (configFile >> "CfgMagazines" >> _magazine >> "displaynameshort"); + private _loadedName = getText (configFile >> "CfgMagazines" >> _magazine >> "displaynameshort"); _loadedName = parseText format ["%1", _loadedName]; - _text = composeText [_loadedName, linebreak, _ammoBarsStructuredText]; + private _text = composeText [_loadedName, linebreak, _ammoBarsStructuredText]; [_text] call EFUNC(common,displayTextStructured); } else { - _picture = getText (configFile >> "CfgMagazines" >> _magazine >> "picture"); + private _picture = getText (configFile >> "CfgMagazines" >> _magazine >> "picture"); [_ammoBarsStructuredText, _picture] call EFUNC(common,displayTextPicture); }; diff --git a/addons/reload/functions/fnc_startLinkingBelt.sqf b/addons/reload/functions/fnc_startLinkingBelt.sqf index 4bed7f700a1..ebee6fd3501 100644 --- a/addons/reload/functions/fnc_startLinkingBelt.sqf +++ b/addons/reload/functions/fnc_startLinkingBelt.sqf @@ -11,26 +11,24 @@ */ #include "script_component.hpp" -EXPLODE_2_PVT(_this,_player,_target); +params ["_player", "_target"]; if (vehicle _target != _target) exitWith {false}; -private ["_magazineCfg","_magazineType", "_condition", "_onFailure", "_onFinish"]; -_magazineType = currentMagazine _target; -_magazineCfg = configFile >> "CfgMagazines" >> _magazineType; +private _magazineType = currentMagazine _target; +private _magazineCfg = configFile >> "CfgMagazines" >> _magazineType; + if (getNumber (_magazineCfg >> "ACE_isBelt") == 0) exitWith {false}; // Check if the ammo is not empty or full -private "_ammoCount"; -_ammoCount = _target ammo currentWeapon _target; +private _ammoCount = _target ammo currentWeapon _target; // Exit if the belt is full or empty if ((_ammoCount == 0) || (getNumber (_magazineCfg >> "count") - _ammoCount) == 0) exitWith {false}; // Check if the player has any of the same same magazines // Calculate max ammo it can link -private "_maxAmmo"; -_maxAmmo = 0; +private _maxAmmo = 0; { _maxAmmo = _maxAmmo max (_x select 1); @@ -38,21 +36,20 @@ _maxAmmo = 0; if (_maxAmmo == 0) exitWith {}; - // Condition to call each frame -_condition = { - EXPLODE_2_PVT((_this select 0),_player,_target); +private _condition = { + (_this select 0) params ["_player", "_target"]; ([_player, _target, []] call EFUNC(common,canInteractWith)) && ((_player distance _target) < 3) && ((speed _target) < 1) }; -_onFinish = { - EXPLODE_3_PVT((_this select 0),_player,_target,_magazine); +private _onFinish = { + (_this select 0) params ["_player", "_target", "_magazine"]; // Raise event on remote unit ["linkedAmmo", [_target], [_target, _player, _magazine]] call EFUNC(common,targetEvent); }; -_onFailure = { +private _onFailure = { EXPLODE_3_PVT((_this select 0),_player,_target,_magazine); [_player, "AmovPknlMstpSrasWrflDnon", 1] call EFUNC(common,doAnimation); diff --git a/addons/vehicles/functions/fnc_speedLimiter.sqf b/addons/vehicles/functions/fnc_speedLimiter.sqf index 5f5d8a29140..2d445be3c81 100644 --- a/addons/vehicles/functions/fnc_speedLimiter.sqf +++ b/addons/vehicles/functions/fnc_speedLimiter.sqf @@ -16,8 +16,6 @@ */ #include "script_component.hpp" -private "_maxSpeed"; - params ["_driver", "_vehicle"]; if (GVAR(isSpeedLimiter)) exitWith { @@ -30,7 +28,7 @@ if (GVAR(isSpeedLimiter)) exitWith { playSound "ACE_Sound_Click"; GVAR(isSpeedLimiter) = true; -_maxSpeed = speed _vehicle max 10; +private _maxSpeed = speed _vehicle max 10; [{ params ["_args", "_idPFH"]; @@ -51,8 +49,7 @@ _maxSpeed = speed _vehicle max 10; [_idPFH] call CBA_fnc_removePerFrameHandler; }; - private "_speed"; - _speed = speed _vehicle; + private _speed = speed _vehicle; if (_speed > _maxSpeed) then { _vehicle setVelocity ((velocity _vehicle) vectorMultiply ((_maxSpeed / _speed) - 0.00001)); // fix 1.42-hotfix PhysX libraries applying force in previous direction when turning diff --git a/addons/weaponselect/XEH_postInit.sqf b/addons/weaponselect/XEH_postInit.sqf index 491a86f39d1..450086aa910 100644 --- a/addons/weaponselect/XEH_postInit.sqf +++ b/addons/weaponselect/XEH_postInit.sqf @@ -105,8 +105,7 @@ if (!hasInterface) exitWith {}; if ((currentWeapon ACE_player) != "") then { [ACE_player] call FUNC(putWeaponAway); } else { - private ["_weapon"]; - _weapon = switch (true) do { + private _weapon = switch (true) do { case ((primaryWeapon ACE_player) != ""): {primaryWeapon ACE_player}; case ((handgunWeapon ACE_player) != ""): {handgunWeapon ACE_player}; case ((secondaryWeapon ACE_player) != ""): {secondaryWeapon ACE_player}; diff --git a/addons/weaponselect/XEH_preInit.sqf b/addons/weaponselect/XEH_preInit.sqf index fe40d33523b..26347fc2799 100644 --- a/addons/weaponselect/XEH_preInit.sqf +++ b/addons/weaponselect/XEH_preInit.sqf @@ -17,16 +17,14 @@ GVAR(GrenadesAll) = []; GVAR(GrenadesFrag) = []; GVAR(GrenadesNonFrag) = []; -private ["_magazines", "_ammo", "_explosive"]; - { - _magazines = getArray (configFile >> "CfgWeapons" >> "Throw" >> _x >> "magazines"); + private _magazines = getArray (configFile >> "CfgWeapons" >> "Throw" >> _x >> "magazines"); GVAR(GrenadesAll) append _magazines; { - _ammo = getText (configFile >> "CfgMagazines" >> _x >> "ammo"); - _explosive = getNumber (configFile >> "CfgAmmo" >> _ammo >> "explosive"); + private _ammo = getText (configFile >> "CfgMagazines" >> _x >> "ammo"); + private _explosive = getNumber (configFile >> "CfgAmmo" >> _ammo >> "explosive"); ([GVAR(GrenadesFrag), GVAR(GrenadesNonFrag)] select (_explosive == 0)) pushBack _x; false diff --git a/addons/weaponselect/functions/fnc_displayGrenadeTypeAndNumber.sqf b/addons/weaponselect/functions/fnc_displayGrenadeTypeAndNumber.sqf index 4ab09a105f7..ef9397ba575 100644 --- a/addons/weaponselect/functions/fnc_displayGrenadeTypeAndNumber.sqf +++ b/addons/weaponselect/functions/fnc_displayGrenadeTypeAndNumber.sqf @@ -20,12 +20,10 @@ if !(GVAR(DisplayText)) exitWith {}; params ["_magazine", "_numberofGrenades"]; -private ["_color", "_name", "_text", "_picture"]; +private _color = [[1, 0, 0], [1, 1, 1]] select (_numberofGrenades > 0); +private _name = getText (configFile >> "CfgMagazines" >> _magazine >> "displayNameShort"); -_color = [[1, 0, 0], [1, 1, 1]] select (_numberofGrenades > 0); -_name = getText (configFile >> "CfgMagazines" >> _magazine >> "displayNameShort"); - -_text = [format ["%1 x%2", _name, _numberofGrenades], _color] call EFUNC(common,stringToColoredText); -_picture = getText (configFile >> "CfgMagazines" >> _magazine >> "picture"); +private _text = [format ["%1 x%2", _name, _numberofGrenades], _color] call EFUNC(common,stringToColoredText); +private _picture = getText (configFile >> "CfgMagazines" >> _magazine >> "picture"); ["displayTextPicture", [_text, _picture]] call EFUNC(common,localEvent); diff --git a/addons/weaponselect/functions/fnc_fireSmokeLauncher.sqf b/addons/weaponselect/functions/fnc_fireSmokeLauncher.sqf index 71ef89ecf62..bb877ea3cd2 100644 --- a/addons/weaponselect/functions/fnc_fireSmokeLauncher.sqf +++ b/addons/weaponselect/functions/fnc_fireSmokeLauncher.sqf @@ -17,11 +17,8 @@ params ["_vehicle"]; -private ["_turret", "_weapons"]; - -_turret = [_vehicle] call EFUNC(common,getTurretCommander); - -_weapons = _vehicle weaponsTurret _turret; +private _turret = _vehicle call EFUNC(common,getTurretCommander); +private _weapons = _vehicle weaponsTurret _turret; if ( count _weapons > 1 @@ -32,8 +29,8 @@ if ( // avoid infinite loop if !("SmokeLauncher" in _weapons) exitWith {}; - private "_index"; - _index = 0; + private _index = 0; + while { _vehicle currentWeaponTurret _turret != "SmokeLauncher" } do { @@ -44,8 +41,7 @@ if ( } else { // fire away! - private "_logic"; - _logic = createGroup sideLogic createUnit ["Logic", [0,0,0], [], 0, "NONE"]; + private _logic = createGroup sideLogic createUnit ["Logic", [0,0,0], [], 0, "NONE"]; _logic action ["useWeapon", _vehicle, commander _vehicle, 0]; diff --git a/addons/weaponselect/functions/fnc_playChangeFiremodeSound.sqf b/addons/weaponselect/functions/fnc_playChangeFiremodeSound.sqf index 28ef5d21e56..a7c3f139367 100644 --- a/addons/weaponselect/functions/fnc_playChangeFiremodeSound.sqf +++ b/addons/weaponselect/functions/fnc_playChangeFiremodeSound.sqf @@ -18,14 +18,12 @@ params ["_unit", "_weapon"]; -private ["_sound", "_position"]; - -_sound = getArray (configFile >> "CfgWeapons" >> _weapon >> "changeFiremodeSound"); +private _sound = getArray (configFile >> "CfgWeapons" >> _weapon >> "changeFiremodeSound"); if (_sound isEqualTo []) exitWith {}; // get position where to play the sound (position of the weapon) -_position = AGLToASL (_unit modelToWorldVisual (_unit selectionPosition "RightHand")); +private _position = AGLToASL (_unit modelToWorldVisual (_unit selectionPosition "RightHand")); _sound params ["_filename", ["_volume", 1], ["_soundPitch", 1], ["_distance", 0]]; diff --git a/addons/weaponselect/functions/fnc_putWeaponAway.sqf b/addons/weaponselect/functions/fnc_putWeaponAway.sqf index fd1e463a4db..d2747bf23f4 100644 --- a/addons/weaponselect/functions/fnc_putWeaponAway.sqf +++ b/addons/weaponselect/functions/fnc_putWeaponAway.sqf @@ -17,6 +17,6 @@ params ["_unit"]; -[_unit] call EFUNC(common,fixLoweredRifleAnimation); +_unit call EFUNC(common,fixLoweredRifleAnimation); _unit action ["SwitchWeapon", _unit, _unit, 99]; diff --git a/addons/weaponselect/functions/fnc_selectNextGrenade.sqf b/addons/weaponselect/functions/fnc_selectNextGrenade.sqf index d4a00b57189..a4e93814a99 100644 --- a/addons/weaponselect/functions/fnc_selectNextGrenade.sqf +++ b/addons/weaponselect/functions/fnc_selectNextGrenade.sqf @@ -18,10 +18,8 @@ params ["_unit", ["_type", 0]]; -private ["_currentGrenade", "_magazines", "_grenades", "_nextGrenadeIndex", "_nextGrenade", "_uniformGrenades", "_vestGrenades", "_backpackGrenades"]; - // get currently selected grenade -_currentGrenade = currentThrowable _unit; +private _currentGrenade = currentThrowable _unit; // get correct array format if no grenade is selected if (_currentGrenade isEqualTo []) then { @@ -31,9 +29,9 @@ if (_currentGrenade isEqualTo []) then { _currentGrenade = _currentGrenade select 0; // get available magazines for that unit -_magazines = magazines _unit; +private _magazines = magazines _unit; -_grenades = []; +private _grenades = []; { if (_x in _magazines) then { @@ -46,22 +44,22 @@ _grenades = []; if (_grenades isEqualTo []) exitWith {false}; // get next grenade muzzle -_nextGrenadeIndex = (_grenades find _currentGrenade) + 1; +private _nextGrenadeIndex = (_grenades find _currentGrenade) + 1; // roll over if the last grenade was selected if (_nextGrenadeIndex >= count _grenades) then { _nextGrenadeIndex = 0; }; -_nextGrenade = _grenades select _nextGrenadeIndex; +private _nextGrenade = _grenades select _nextGrenadeIndex; // abort if the same grenade would be selected if (_currentGrenade == _nextGrenade) exitWith {false}; // current best method to select a grenade: remove all grenades except the one you want to select, then add them back -_uniformGrenades = [uniformItems _unit, {_x in GVAR(GrenadesAll) && {_x != _nextGrenade}}] call EFUNC(common,filter); -_vestGrenades = [vestItems _unit, {_x in GVAR(GrenadesAll) && {_x != _nextGrenade}}] call EFUNC(common,filter); -_backpackGrenades = [backpackItems _unit, {_x in GVAR(GrenadesAll) && {_x != _nextGrenade}}] call EFUNC(common,filter); +private _uniformGrenades = [uniformItems _unit, {_x in GVAR(GrenadesAll) && {_x != _nextGrenade}}] call EFUNC(common,filter); +private _vestGrenades = [vestItems _unit, {_x in GVAR(GrenadesAll) && {_x != _nextGrenade}}] call EFUNC(common,filter); +private _backpackGrenades = [backpackItems _unit, {_x in GVAR(GrenadesAll) && {_x != _nextGrenade}}] call EFUNC(common,filter); // remove all grenades except those we are switching to --> this breaks the selector {_unit removeItemFromUniform _x; false} count _uniformGrenades; diff --git a/addons/weaponselect/functions/fnc_selectWeaponMode.sqf b/addons/weaponselect/functions/fnc_selectWeaponMode.sqf index 815b8d28cf8..80784778de6 100644 --- a/addons/weaponselect/functions/fnc_selectWeaponMode.sqf +++ b/addons/weaponselect/functions/fnc_selectWeaponMode.sqf @@ -29,20 +29,18 @@ if (_weapon in (_unit getVariable [QEGVAR(safemode,safedWeapons), []])) exitWith [_unit, _weapon, _weapon] call EFUNC(safemode,unlockSafety); }; -private ["_muzzles", "_modes"]; +private _muzzles = [_weapon] call EFUNC(common,getWeaponMuzzles); +private _modes = [_weapon] call EFUNC(common,getWeaponModes); -_muzzles = [_weapon] call EFUNC(common,getWeaponMuzzles); -_modes = [_weapon] call EFUNC(common,getWeaponModes); +private _index = (_modes find currentWeaponMode _unit) + 1; -private ["_index", "_muzzle", "_mode"]; - -_index = (_modes find currentWeaponMode _unit) + 1; if (_index > count _modes - 1) then {_index = 0}; -_muzzle = _muzzles select 0; -_mode = _modes select _index; +private _muzzle = _muzzles select 0; +private _mode = _modes select _index; _index = 0; + while { _index < 100 && {currentMuzzle _unit != _muzzle || {currentWeaponMode _unit != _mode}} } do { diff --git a/addons/weaponselect/functions/fnc_selectWeaponMuzzle.sqf b/addons/weaponselect/functions/fnc_selectWeaponMuzzle.sqf index 71c9cfc7b48..973d34f7c83 100644 --- a/addons/weaponselect/functions/fnc_selectWeaponMuzzle.sqf +++ b/addons/weaponselect/functions/fnc_selectWeaponMuzzle.sqf @@ -20,8 +20,7 @@ params ["_unit", "_weapon"]; if (_weapon == "") exitWith {}; -private "_muzzles"; -_muzzles = [_weapon] call EFUNC(common,getWeaponMuzzles); +private _muzzles = _weapon call EFUNC(common,getWeaponMuzzles); if (currentWeapon _unit != _weapon) exitWith { if (count _muzzles > 1) then { @@ -35,12 +34,11 @@ if (currentWeapon _unit != _weapon) exitWith { }; }; -private ["_index", "_muzzle"]; +private _index = (_muzzles find currentMuzzle _unit) + 1; -_index = (_muzzles find currentMuzzle _unit) + 1; if (_index > count _muzzles - 1) then {_index = 1}; -_muzzle = _muzzles select _index; +private _muzzle = _muzzles select _index; _index = 0; while { diff --git a/addons/weaponselect/functions/fnc_selectWeaponVehicle.sqf b/addons/weaponselect/functions/fnc_selectWeaponVehicle.sqf index 9695079da57..7435dd30d8e 100644 --- a/addons/weaponselect/functions/fnc_selectWeaponVehicle.sqf +++ b/addons/weaponselect/functions/fnc_selectWeaponVehicle.sqf @@ -19,39 +19,36 @@ params ["_unit", "_vehicle", "_index"]; -private "_turret"; -_turret = [_unit] call EFUNC(common,getTurretIndex); +private _turret = _unit call EFUNC(common,getTurretIndex); if (_turret isEqualTo [] && {_unit == driver _vehicle}) then { - private ["_weapons", "_weapon"]; + private _weapons = weapons _vehicle; - _weapons = weapons _vehicle; if (_index > count _weapons - 1) exitWith {}; - _weapon = _weapons select _index; + private _weapon = _weapons select _index; _index = 0; + while { _index < 100 && {currentWeapon _vehicle != _weapon} } do { _unit action ["SwitchWeapon", _vehicle, _unit, _index]; _index = _index + 1; }; - } else { - private ["_weapons", "_weapon"]; + private _weapons = _vehicle weaponsTurret _turret; - _weapons = _vehicle weaponsTurret _turret; if (_index > count _weapons - 1) exitWith {}; - _weapon = _weapons select _index; + private _weapon = _weapons select _index; _index = 0; + while { _index < 100 && {_vehicle currentWeaponTurret _turret != _weapon} } do { _unit action ["SwitchWeapon", _vehicle, _unit, _index]; _index = _index + 1; }; - }; diff --git a/addons/weaponselect/functions/fnc_throwGrenade.sqf b/addons/weaponselect/functions/fnc_throwGrenade.sqf index 2cdc8e63dcf..a99b06879b0 100644 --- a/addons/weaponselect/functions/fnc_throwGrenade.sqf +++ b/addons/weaponselect/functions/fnc_throwGrenade.sqf @@ -25,8 +25,7 @@ params ["_unit", "_weapon", "", "", "", "_magazine"]; if (_weapon != "Throw") exitWith {}; -private "_count"; -_count = {_x == _magazine} count magazines _unit; +private _count = {_x == _magazine} count magazines _unit; [_magazine, _count] call FUNC(displayGrenadeTypeAndNumber); From de135181778506c65b7bbc311fdeef0821c6cb17 Mon Sep 17 00:00:00 2001 From: commy2 Date: Wed, 6 Jan 2016 22:49:22 +0100 Subject: [PATCH 2/2] explode macro to params --- addons/reload/functions/fnc_displayAmmo.sqf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/addons/reload/functions/fnc_displayAmmo.sqf b/addons/reload/functions/fnc_displayAmmo.sqf index d4143e57d12..7fff5564c01 100644 --- a/addons/reload/functions/fnc_displayAmmo.sqf +++ b/addons/reload/functions/fnc_displayAmmo.sqf @@ -12,7 +12,7 @@ #define COUNT_BARS 12 -EXPLODE_1_PVT(_this,_target); +params ["_target"]; private _weapon = currentWeapon _target; private _muzzle = currentMuzzle _target;