Advertisement
Roque_THE_GAMER

Shotgun Tactical Reload

Jun 27th, 2019
927
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
SQF 3.54 KB | None | 0 0
  1. //Paste the code below inside of a gamelogic or inside the initplayer.sqf, avoid copy this comment or you will get errors.
  2.  
  3.  
  4. if (isdedicated) exitWith {};
  5.  
  6. RTG_Shotgun_TacReloadInProgress = 0;
  7. RTG_Shotgun_TacReload = {
  8. if (RTG_Shotgun_TacReloadInProgress == 1) exitWith {};
  9. RTG_Shotgun_TacReloadInProgress = 1;
  10. private _shotgun = currentMuzzle player;
  11. private _oldmagazine = currentMagazine player;
  12. private _MyMags = magazinesAmmo player;
  13. private _MyMags = _MyMags select {(currentMagazine player) in _x};
  14. private _fullMagNum = getNumber (configFile >> "CfgMagazines" >> _oldmagazine >> "count");
  15. private _AmmoInWeapon = player ammo currentMuzzle player;
  16. private _AmoutOfMags = count _MyMags;
  17. private _MyMagsAllAmmo = 0;
  18. {_MyMagsAllAmmo = _MyMagsAllAmmo + (_x select 1)} foreach _MyMags;
  19. sleep 0.1;
  20.  
  21.  
  22. if (_AmmoInWeapon == _fullMagNum) exitWith {systemChat "Weapon already Full"; RTG_Shotgun_TacReloadInProgress = 0;};
  23. if (_AmoutOfMags == 0) exitWith {systemChat "No mags to reload"; RTG_Shotgun_TacReloadInProgress = 0;};
  24. player playactionNow "GestureEmpty" ;
  25. player playactionNow "GestureReloadM4SSAS";
  26.  
  27. sleep 1.4;
  28.  
  29.         if (_AmmoInWeapon < _fullMagNum) then {
  30.             player setAmmo [_shotgun, (_AmmoInWeapon + 1)];
  31.             _MyMagsAllAmmo = _MyMagsAllAmmo - 1;
  32.             _AmmoInWeapon = player ammo currentMuzzle player;
  33.             sleep 0.7;
  34.         };
  35.  
  36. while {((inputAction "User12") > 0 or ((inputAction "LeanLeft" > 0  and inputAction "LeanRight" > 0 ))) and _AmmoInWeapon < _fullMagNum and _MyMagsAllAmmo > 0} do {
  37.  
  38.     _AmmoInWeapon = player ammo currentMuzzle player;
  39.         if (_AmmoInWeapon < _fullMagNum) then {
  40.             _MyMagsAllAmmo = _MyMagsAllAmmo - 1;
  41.             player setAmmo [_shotgun, (_AmmoInWeapon + 1)];
  42.             sleep 0.7;
  43.         };
  44.  
  45. };
  46.  
  47. player removeMagazines _oldmagazine;
  48.  
  49.  
  50.  
  51. {
  52.     if (_MyMagsAllAmmo > _fullMagNum) then {
  53.         player addMagazine _oldmagazine;
  54.         _MyMagsAllAmmo = abs (_MyMagsAllAmmo - _fullMagNum);
  55.     };
  56.     if (_MyMagsAllAmmo <= _fullMagNum and _MyMagsAllAmmo > 0) then {
  57.         player addMagazine [_oldmagazine, _MyMagsAllAmmo];
  58.         _MyMagsAllAmmo = 0;
  59.     };
  60. } foreach _MyMags;
  61.  
  62. player playactionNow "gestureNod" ;
  63. RTG_Shotgun_TacReloadInProgress = 0;
  64. };
  65.  
  66.  
  67.  
  68. ["ShotgunTacReload", "onEachFrame"] call BIS_fnc_removeStackedEventHandler;
  69. ["ShotgunTacReload", "onEachFrame", {
  70.     private _MyMags = magazinesAmmo player;
  71.     private _MyMags = _MyMags select {(currentMagazine player) in _x};
  72.     private _AmoutOfMags = count _MyMags;
  73.     private _oldmagazine = currentMagazine player;
  74.     private _fullMagNum = getNumber (configFile >> 'CfgMagazines' >> _oldmagazine >> 'count');
  75.     private _AmmoInWeapon = player ammo (currentMuzzle player);
  76. if (
  77.     vehicle player == player and
  78.     _AmoutOfMags > 0 and
  79.     _fullMagNum != _AmmoInWeapon and
  80.     _fullMagNum < 9 and
  81.     _fullMagNum > 4 and
  82.     (['buck','slug','HE','frag','PPA','Stun','Pellets'] findIf {[_x, _oldmagazine] call BIS_fnc_inString} != -1) and
  83.     ((inputAction "LeanLeft" > 0  and inputAction "LeanRight" > 0) or (inputAction "User12") > 0) and
  84.     RTG_Shotgun_TacReloadInProgress == 0
  85.     ) then {
  86.     [] spawn RTG_Shotgun_TacReload;
  87.     };
  88.  
  89. }] call BIS_fnc_addStackedEventHandler;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement