player2_dz

p2_randomMags - Any Mod & OverPoch

May 5th, 2016
193
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
SQF 7.05 KB | None | 0 0
  1. /*---------------------------------------------------------------------------
  2. Variable Init
  3. ---------------------------------------------------------------------------*/
  4. private ["_w","_m","_r","_r1","_r2","_isSD","_isMagSD","_m2c","_isDone","_d","_launcherResult","_launcherMagazineRandomiser","_checkIfSD_Weapon","_checkIfSD_Ammo"];
  5. _w =        "";
  6. _m =        [];
  7. _r =        [];
  8. _r1 =       false;
  9. _r2 =       false;
  10. _isSD =     false;
  11. _isMagSD =  false;
  12. _m2c =      "";
  13. _isDone =   false;
  14. _d =        false;          //enable/disable debugging
  15.  
  16. /*---------------------------------------------------------------------------
  17.     Inputs
  18. ---------------------------------------------------------------------------*/
  19.  
  20. _w = _this select 0;
  21. _m = _this select 1;
  22. _r = _this select 2;
  23. _r1 =   _r select 0;
  24. _r2 =   _r select 1;
  25.  
  26. /*---------------------------------------------------------------------------
  27. Private Functions
  28. ---------------------------------------------------------------------------*/
  29.  
  30. _checkIfSD_Weapon = {
  31.     private ["_isInConfig","_isInWepName","_isInMag0Name","_result"];
  32.     _result = false;
  33.     //get audible value from ammo, check if less than 0.1
  34.     _isInConfig =   (getNumber (configFile >> "CfgAmmo" >> (getText (configFile >> "cfgMagazines" >> (_m select 0) >> "ammo")) >> "audibleFire")) < 0.1;
  35.     //check if SD is in weapon name
  36.     _isInWepName =  [_w,"SD"] call KRON_StrInStr;
  37.     //check if SD is in the default magazine name
  38.     _isInMag0Name = [_m select 0, "SD"] call KRON_StrInStr;
  39.  
  40.     //if any of above are true, result is true
  41.     if (_isInWepName || _isInMag0Name || _isInConfig) then {
  42.         _result = true;
  43.     };
  44.    
  45.     if (_d) then { diag_log (format["_checkIfSD_Weapon: Input: (%1) Result(Config,WepName,Mag0name): (%2)",[_w,_m],[_isInConfig,_isInWepName,_isInMag0Name]]); };
  46.  
  47.     _result
  48. };
  49.  
  50. _checkIfSD_Ammo = {
  51.     private ["_isInConfig","_isInMag0Name","_result"];
  52.     _result =       false;
  53.     _isInConfig =   (getNumber (configFile >> "CfgAmmo" >> (getText (configFile >> "cfgMagazines" >> (_this) >> "ammo")) >> "audibleFire")) < 1;
  54.     _isInMag0Name = [_this, "SD"] call KRON_StrInStr;
  55.  
  56.     if (_isInMag0Name || _isInConfig) then {
  57.         _result =   true;
  58.     };
  59.  
  60.     if (_d) then {  diag_log (format["_checkIfSD_Ammo: Input: (%1) Result(Config/MagName): (%2)",[_this],[_isInConfig,_isInMag0Name]]); };
  61.  
  62.     _result
  63. };
  64.  
  65. _launcherMagazineRandomiser = {
  66.     private ["_magOutput","_wepName","_isLauncher","_isM203Muzzle","_muzzleName","_isM32","_isM203","_isGP25","_isGP25Muzzle"];
  67.     _magOutput =    _this select 0;
  68.     _wepName =      _this select 1;
  69.     _isLauncher =   false;
  70.     _isM203Muzzle = false;
  71.     _muzzleName =   [];
  72.    
  73.     _isM32 =        [_wepName, "M32_EP1"] call KRON_StrInStr;
  74.     if (_isM32) then {
  75.         _isLauncher =   true;
  76.         _magOutput =    ["6Rnd_HE_M203", "6Rnd_HE_M203", "6Rnd_HE_M203", "6Rnd_HE_M203", "1Rnd_HE_M203", "6Rnd_Smoke_M203", "6Rnd_SmokeRed_M203", "6Rnd_SmokeGreen_M203", "6Rnd_SmokeYellow_M203"] call BIS_fnc_selectRandom;
  77.     };
  78.    
  79.     _isM203 =       [_magOutput, "M203"] call KRON_StrInStr;
  80.     if (_isM203) then {
  81.         _isLauncher =   true;
  82.         _magOutput =    ["1Rnd_HE_M203", "1Rnd_HE_M203", "1Rnd_HE_M203", "1Rnd_HE_M203", "1Rnd_HE_M203", "1Rnd_Smoke_M203", "1Rnd_SmokeRed_M203", "1Rnd_SmokeGreen_M203", "1Rnd_SmokeYellow_M203"] call BIS_fnc_selectRandom;
  83.     };
  84.    
  85.     _isGP25 =       [_magOutput, "GP25"] call KRON_StrInStr;
  86.     if (_isGP25) then {
  87.         _isLauncher =   true;
  88.         _magOutput =    ["1Rnd_HE_GP25", "1Rnd_HE_GP25", "1Rnd_HE_GP25", "1Rnd_HE_GP25", "1Rnd_HE_GP25", "1Rnd_SMOKE_GP25", "1Rnd_SmokeRed_GP25", "1Rnd_SmokeGreen_GP25", "1Rnd_SmokeYellow_GP25"] call BIS_fnc_selectRandom;
  89.     };
  90.  
  91.     if (!_isLauncher) then {
  92.         _muzzleName = (getArray (configFile >> "cfgWeapons" >> _wepName >> "muzzles"));
  93.         if (count _muzzleName > 1) then {
  94.             if ((random 10) > 7.75) then {
  95.                 _isM203Muzzle = [_muzzleName select 1, "M203"] call KRON_StrInStr;
  96.                 if (_isM203Muzzle) then {
  97.                     _isLauncher = true;
  98.                     _magOutput = ["1Rnd_HE_M203", "1Rnd_HE_M203", "1Rnd_HE_M203", "1Rnd_HE_M203", "1Rnd_HE_M203", "1Rnd_Smoke_M203", "1Rnd_SmokeRed_M203", "1Rnd_SmokeGreen_M203", "1Rnd_SmokeYellow_M203"] call BIS_fnc_selectRandom;
  99.                 };
  100.                 _isGP25Muzzle = [_muzzleName select 1, "GP25"] call KRON_StrInStr;
  101.                 if (_isGP25Muzzle) then {
  102.                     _isLauncher = true;
  103.                     _magOutput = ["1Rnd_HE_GP25", "1Rnd_HE_GP25", "1Rnd_HE_GP25", "1Rnd_HE_GP25", "1Rnd_HE_GP25", "1Rnd_SMOKE_GP25", "1Rnd_SmokeRed_GP25", "1Rnd_SmokeGreen_GP25", "1Rnd_SmokeYellow_GP25"] call BIS_fnc_selectRandom;
  104.                 };
  105.             };
  106.         };
  107.     };
  108.  
  109.     if (_d) then { diag_log (format["_launcherMagazineRandomiser: Input: (%1) Output: (%3)  Result(_isM32,_isM203,_isGP25): (%2)",[_magOutput,_wepName],[_isM32,_isM203,_isGP25],[_isLauncher,_magOutput]]); };
  110.  
  111.     [_isLauncher,_magOutput]
  112. };
  113.  
  114.  
  115. /*---------------------------------------------------------------------------
  116. Instructions
  117. ---------------------------------------------------------------------------*/
  118. if (_d && !_r1) then { diag_log (format["P2DEBUG: p2_randomMags: Input: %1",[_w,_m,[_r1,_r2]]]); };
  119.  
  120. //if mag count not > 0
  121. if !(count _m > 0) then {
  122.     _m2c =      _m select 0;
  123.     _isDone =   true;
  124. };
  125.  
  126. //if not a re-run and not done, check if sd.
  127. if (!_r1 && !_isDone) then {   
  128.     if (_d) then { diag_log ("p2_randomMags: Not ReRun"); };
  129.  
  130.     //if is grenade launcher weapon this will randomise the nades, if not proceed as normal
  131.     _launcherResult =   [_m2c,_w] call _launcherMagazineRandomiser;
  132.     if (_launcherResult select 0) then {
  133.         _m2c =          _launcherResult select 1;
  134.         _isSD =         false;
  135.         _isDone =       true;
  136.     } else {
  137.         _isSD =         call _checkIfSD_Weapon;
  138.     };
  139. } else {
  140.     //if a rerun, sd val is parsed from last time in r2
  141.     if (_d) then { diag_log (format["p2_randomMags: reRun, _r2: %1 _m: %2",_r2,_m]); };
  142.     _isSD =             _r2;
  143. };
  144.    
  145. if (_isSD && !_isDone) then {
  146.         _m2c = _m call BIS_fnc_selectRandom;
  147.         _isMagSD = _m2c call _checkIfSD_Ammo;
  148.  
  149.         //ReRun if non-SD mag returned
  150.         if !(_isMagSD) then {
  151.             if (_d) then { diag_log (format["p2_randomMags: !isMagSD reRun, _m2c: %1, _m: %2",_m2c,_m]); };
  152.             _m = _m - [_m2c];
  153.             if (_d) then { diag_log (format["p2_randomMags: !isMagSD reRun ResizeArray, _m: %1",_m]); };
  154.             _m2c = [_this select 0, _m,[true,true]] call p2_randomMags;
  155.         };
  156.  
  157. } else {
  158.  
  159.     if (!_isDone) then {
  160.         _m2c =      _m call BIS_fnc_selectRandom;
  161.         _isMagSD =  _m2c call _checkIfSD_Ammo;
  162.  
  163.         //ReRun if SD mag returned
  164.         if (_isMagSD) then {
  165.             if (_d) then { diag_log (format["p2_randomMags: !isMagSD reRun, _m2c: %1, _m: %2",_m2c,_m]); };
  166.             _m = _m - [_m2c];
  167.             if (_d) then { diag_log (format["p2_randomMags: !isMagSD reRun ResizeArray, _m: %1",_m]); };
  168.             _m2c = [_this select 0, _m,[true,false]] call p2_randomMags;
  169.         };
  170.     };
  171.  
  172. };
  173.  
  174. //Select default if _m2c is Nil or ""
  175. if (isNil "_m2c" || isNil "_m" || {_m2c == ""} || {str _m == str[]}) then {
  176.     if (_d) then { diag_log ("p2_randomMags: isNil reRun"); };
  177.     _m2c = [] + getArray (configFile >> "cfgWeapons" >> _w >> "magazines");
  178.     _m2c = _m2c select 0;
  179. };
  180.  
  181. if (_d && !_r1) then { diag_log (format["P2DEBUG: p2_randomMags: Output: %1",_m2c]); };
  182. /*---------------------------------------------------------------------------
  183. Output
  184. ---------------------------------------------------------------------------*/
  185. _m2c
Advertisement
Add Comment
Please, Sign In to add comment