Advertisement
Guest User

Untitled

a guest
Apr 20th, 2019
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.40 KB | None | 0 0
  1. #include "..\..\script_macros.hpp"
  2. /*
  3. File: fn_mine.sqf
  4. Author: Devilfloh
  5. Editor: Dardo
  6.  
  7. Description:
  8. Same as fn_gather,but it allows use of probabilities for mining.
  9. */
  10. private ["_maxGather", "_resource", "_amount", "_requiredItem", "_mined"];
  11. if (life_action_inUse) exitWith {};
  12. if !(isNull objectParent player) exitWith {};
  13. if (player getVariable "restrained") exitWith {
  14. hint localize "STR_NOTF_isrestrained";
  15. };
  16. _exit = false;
  17. if (player getVariable "playerSurrender") exitWith {
  18. hint localize "STR_NOTF_surrender";
  19. };
  20. life_action_inUse = true;
  21. _zone = "";
  22. _requiredItem = "";
  23.  
  24. _resourceCfg = missionConfigFile >> "CfgGather" >> "Minerals";
  25. _percent = (floor random 100) + 1; //Make sure it's not 0
  26.  
  27. for "_i" from 0 to count(_resourceCfg)-1 do {
  28. _curConfig = _resourceCfg select _i;
  29. _resources = getArray(_curConfig >> "mined");
  30. _maxGather = getNumber(_curConfig >> "amount");
  31. _zoneSize = getNumber(_curConfig >> "zoneSize");
  32. _resourceZones = getArray(_curConfig >> "zones");
  33. _requiredItem = getText(_curConfig >> "item");
  34. _mined = "";
  35.  
  36. if (_resources isEqualTo []) exitWith {}; //Smart guy :O
  37. for "_i" from 0 to count (_resources) do {
  38. if (count _resources isEqualTo 1) exitWith {
  39. if (!((_resources select 0) isEqualType [])) then {
  40. _mined = _resources select 0;
  41. } else {
  42. _mined = (_resources select 0) select 0;
  43. };
  44. };
  45. _resource = (_resources select _i) select 0;
  46. _prob = (_resources select _i) select 1;
  47. _probdiff = (_resources select _i) select 2;
  48. if ((_percent >= _prob) && (_percent <= _probdiff)) exitWith {
  49. _mined = _resource;
  50. };
  51. };
  52.  
  53. {
  54. if ((player distance(getMarkerPos _x)) < _zoneSize) exitWith {
  55. _zone = _x;
  56. };
  57. } forEach _resourceZones;
  58.  
  59. if (_zone != "") exitWith {};
  60. };
  61.  
  62. if (_zone isEqualTo "") exitWith {
  63. life_action_inUse = false;
  64. };
  65.  
  66. if (_requiredItem != "") then {
  67. _valItem = missionNamespace getVariable "life_inv_" + _requiredItem;
  68.  
  69. if (_valItem < 1) exitWith {
  70. switch (_requiredItem) do {
  71. case "pickaxe": {
  72. titleText[(localize "STR_NOTF_Pickaxe"), "PLAIN"];
  73. };
  74. };
  75. life_action_inUse = false;
  76. _exit = true;
  77. };
  78. };
  79.  
  80. if (_exit) exitWith {
  81. life_action_inUse = false;
  82. };
  83.  
  84. while {true} do {
  85. _amount = round(random(_maxGather)) + 1;
  86. _diff = [_mined, _amount, life_carryWeight, life_maxWeight] call life_fnc_calWeightDiff;
  87. if (_diff isEqualTo 0) exitWith {
  88. hint localize "STR_NOTF_InvFull";
  89. life_action_inUse = false;
  90. };
  91.  
  92. [player,"mining",35,1] remoteExecCall ["life_fnc_say3D",RCLIENT];
  93.  
  94. for "_i" from 0 to 4 do {
  95. player playMoveNow "AinvPercMstpSnonWnonDnon_Putdown_AmovPercMstpSnonWnonDnon";
  96. waitUntil {
  97. animationState player != "AinvPercMstpSnonWnonDnon_Putdown_AmovPercMstpSnonWnonDnon";
  98. };
  99. sleep 0.5;
  100. };
  101.  
  102. if (([true, _mined, _diff] call life_fnc_handleInv)) then {
  103. _itemName = M_CONFIG(getText, "VirtualItems", _mined, "displayName");
  104. titleText[format [localize "STR_NOTF_Mine_Success", (localize _itemName), _diff], "PLAIN"];
  105. };
  106. sleep 3;
  107. };
  108.  
  109. sleep 2.5;
  110. life_action_inUse = false;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement