Advertisement
TheGamingChief

pistolControl.sqf

Jul 7th, 2015
357
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.13 KB | None | 0 0
  1. Private["_passedArray","_waitUntil","_gun","_unknownWeaponClass","_unknownConfig","_weaponsArray","_numWeapon","_prevention"];
  2.  
  3.  
  4. _passedArray = _this;
  5. _waitUntil = 0;
  6. _gun = "";
  7.  
  8. // Function for pistol data - by Spooner
  9. isPistol =
  10. {
  11. _unknownWeaponClass = _this select 0;
  12.  
  13. _unknownConfig = configFile >> "CfgWeapons" >> _unknownWeaponClass;
  14. _pistolConfig = configFile >> "CfgWeapons" >> "PistolCore";
  15.  
  16. _isPistol = false;
  17. while {isClass _unknownConfig} do
  18. {
  19. if (_unknownConfig == _pistolConfig) exitWith
  20. {
  21. _isPistol = true;
  22. };
  23.  
  24. _unknownConfig = inheritsFrom _unknownConfig;
  25. };
  26.  
  27. _isPistol; // Return.
  28. };
  29.  
  30. // Moderate array when script is ran 1st time
  31. if (count _this == 0) then
  32. {
  33. // Modify array when first ran (make it similar to addAction)
  34. _passedArray = [0,0,0,[false]];
  35.  
  36. // Activate parallel script to check weapon conditions, first run
  37. [] spawn
  38. {
  39. // Syntax: ["pistolclass",holstered?,dropped pistol?];
  40. saveWeaponPistol = ["",false,false];
  41.  
  42. while { true } do
  43. {
  44. _weaponsArray = weapons player - nonlethalweapons;
  45. _numWeapon = count _weaponsArray;
  46.  
  47. // Get pistol classname
  48. _prevention = true;
  49. for [{_p = 0},{_p < _numWeapon},{_p = _p + 1}] do
  50. {
  51. _gun = (_weaponsArray select _p);
  52. if ([_gun] call isPistol) exitWith
  53. {
  54. _prevention = false;
  55. if ((_gun != saveWeaponPistol select 0) && saveWeaponPistol select 1) then { _prevention = true; saveWeaponPistol set [1,false]; };
  56. saveWeaponPistol set [0,_gun];
  57. };
  58. };
  59.  
  60. // Determine if holster/unholster can be used
  61. if (_prevention && !(saveWeaponPistol select 1)) then { saveWeaponPistol set [2,true]; player removeAction holsterPistol; player removeAction unholsterPistol; }
  62. else
  63. { if (saveWeaponPistol select 2) then { holsterPistol = player addAction ["Holster Pistol","pistolControl.sqf",[true]]; saveWeaponPistol set [2,false]; }; };
  64.  
  65. sleep 0.5;
  66. };
  67.  
  68. // End of spawn
  69. };
  70. };
  71.  
  72. // Prepare value if holster or unholstered
  73. _holster = (_passedArray select 3 select 0);
  74.  
  75. // Activate the correct action
  76. if (!_holster) then
  77. {
  78. player removeAction unholsterPistol;
  79. saveWeaponPistol set [1,false];
  80. holsterPistol = player addAction ["Holster Pistol","pistolControl.sqf",[true]];
  81.  
  82. // Upon first activation, prevent addWeapon
  83. if (count _this > 0) then
  84. {
  85. player addWeapon (saveWeaponPistol select 0);
  86. player selectWeapon (saveWeaponPistol select 0);
  87. ['pistole', 0] call INV_SetItemAmount;
  88. INV_InventarPistole = (saveWeaponPistol select 0);
  89. };
  90. }
  91. else
  92. {
  93. player removeAction holsterPistol;
  94. saveWeaponPistol set [1,true];
  95. unholsterPistol = player addAction ["Unholster Pistol","pistolControl.sqf",[false]];
  96. player removeWeapon (saveWeaponPistol select 0);
  97. ['pistole', 1] call INV_SetItemAmount;
  98. INV_InventarPistole = (saveWeaponPistol select 0);
  99. };
  100.  
  101. // Calculate next ID
  102. _waitUntil = (_passedArray select 2) + 1;
  103.  
  104. // Wait with termination until action is used or pistol is dropped
  105. if (isNull unholsterPistol) exitWith {};
  106. unholsterPistol = 100; //Setting this to prevent the null value looping an error
  107. waitUntil { holsterPistol == _waitUntil || unholsterPistol == _waitUntil || (saveWeaponPistol select 2) };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement