Advertisement
DeTrix

player_upgrade.sqf

Apr 20th, 2014
41
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.12 KB | None | 0 0
  1. /*
  2. DayZ Base Building Upgrades
  3. Made for DayZ Epoch please ask permission to use/edit/distrubute email vbawol@veteranbastards.com.
  4. */
  5. private ["_playerUID","_found","_location","_dir","_classname","_missing","_text","_proceed","_num_removed","_object","_missingQty","_itemIn","_countIn","_qty","_removed","_removed_total","_tobe_removed_total","_objectID","_objectUID","_temp_removed_array","_textMissing","_newclassname","_requirements","_obj","_upgrade","_lockable","_combination_1","_combination_2","_combination_3","_combination","_objectCharacterID","_canBuildOnPlot","_friendlies","_nearestPole","_ownerID","_distance","_needText","_findNearestPoles","_findNearestPole","_IsNearPlot"];
  6.  
  7. if(DZE_ActionInProgress) exitWith { cutText [(localize "str_epoch_player_52") , "PLAIN DOWN"]; };
  8. DZE_ActionInProgress = true;
  9.  
  10. player removeAction s_player_upgrade_build;
  11. s_player_upgrade_build = 1;
  12.  
  13.  
  14. _distance = 30;
  15. _needText = localize "str_epoch_player_246";
  16.  
  17. _playerUID = getPlayerUID player;
  18. _found=[_playerUID,"AX"] call KRON_StrInStr;
  19. if (_found) then {
  20. _playerUID=[_playerUID] call KRON_convertPlayerUID;
  21. };
  22.  
  23. // check for near plot
  24. _findNearestPoles = nearestObjects [(vehicle player), ["Plastic_Pole_EP1_DZ"], _distance];
  25. _findNearestPole = [];
  26.  
  27. {
  28. if (alive _x) then {
  29. _findNearestPole set [(count _findNearestPole),_x];
  30. };
  31. } foreach _findNearestPoles;
  32.  
  33. _IsNearPlot = count (_findNearestPole);
  34.  
  35. _canBuildOnPlot = false;
  36.  
  37. if(_IsNearPlot == 0) then {
  38. _canBuildOnPlot = true;
  39. } else {
  40.  
  41. // check nearby plots ownership and then for friend status
  42. _nearestPole = _findNearestPole select 0;
  43.  
  44. // Find owner
  45. _ownerID = _nearestPole getVariable["CharacterID","0"];
  46.  
  47. // diag_log format["DEBUG BUILDING: %1 = %2", dayz_characterID, _ownerID];
  48.  
  49. // check if friendly to owner
  50. if(_playerUID == _ownerID) then {
  51. _canBuildOnPlot = true;
  52. } else {
  53. _friendlies = player getVariable ["friendlyTo",[]];
  54. // check if friendly to owner
  55. if(_ownerID in _friendlies) then {
  56. _canBuildOnPlot = true;
  57. };
  58. };
  59. };
  60.  
  61. // exit if not allowed due to plot pole
  62. if(!_canBuildOnPlot) exitWith { DZE_ActionInProgress = false; cutText [format[(localize "str_epoch_player_157"),_needText,_distance] , "PLAIN DOWN"]; };
  63.  
  64. // get cursortarget from addaction
  65. _obj = _this select 3;
  66.  
  67. // Find objectID
  68. _objectID = _obj getVariable ["ObjectID","0"];
  69.  
  70. // Find objectUID
  71. _objectUID = _obj getVariable ["ObjectUID","0"];
  72.  
  73. if(_objectID == "0" && _objectUID == "0") exitWith {DZE_ActionInProgress = false; s_player_upgrade_build = -1; cutText [(localize "str_epoch_player_50"), "PLAIN DOWN"];};
  74.  
  75. // Get classname
  76. _classname = typeOf _obj;
  77.  
  78. // Find display name
  79. _text = getText (configFile >> "CfgVehicles" >> _classname >> "displayName");
  80.  
  81. // Find next upgrade
  82. _upgrade = getArray (configFile >> "CfgVehicles" >> _classname >> "upgradeBuilding");
  83.  
  84. if ((count _upgrade) > 0) then {
  85.  
  86. _newclassname = _upgrade select 0;
  87.  
  88. _lockable = 0;
  89. if(isNumber (configFile >> "CfgVehicles" >> _newclassname >> "lockable")) then {
  90. _lockable = getNumber(configFile >> "CfgVehicles" >> _newclassname >> "lockable");
  91. };
  92.  
  93. _requirements = _upgrade select 1;
  94.  
  95. _missingQty = 0;
  96. _missing = "";
  97.  
  98. _proceed = true;
  99. {
  100. _itemIn = _x select 0;
  101. _countIn = _x select 1;
  102. _qty = { (_x == _itemIn) || (configName(inheritsFrom(configFile >> "cfgMagazines" >> _x)) == _itemIn) } count magazines player;
  103. if(_qty < _countIn) exitWith { _missing = _itemIn; _missingQty = (_countIn - _qty); _proceed = false; };
  104. } forEach _requirements;
  105.  
  106. if (_proceed) then {
  107. [1,1] call dayz_HungerThirst;
  108. player playActionNow "Medic";
  109. [player,20,true,(getPosATL player)] spawn player_alertZombies;
  110.  
  111. _temp_removed_array = [];
  112. _removed_total = 0;
  113. _tobe_removed_total = 0;
  114.  
  115. {
  116. _removed = 0;
  117. _itemIn = _x select 0;
  118. _countIn = _x select 1;
  119. // diag_log format["Recipe Finish: %1 %2", _itemIn,_countIn];
  120. _tobe_removed_total = _tobe_removed_total + _countIn;
  121.  
  122. {
  123. if( (_removed < _countIn) && ((_x == _itemIn) || configName(inheritsFrom(configFile >> "cfgMagazines" >> _x)) == _itemIn)) then {
  124. _num_removed = ([player,_x] call BIS_fnc_invRemove);
  125. _removed = _removed + _num_removed;
  126. _removed_total = _removed_total + _num_removed;
  127. if(_num_removed >= 1) then {
  128. _temp_removed_array set [count _temp_removed_array,_x];
  129. };
  130. };
  131.  
  132. } forEach magazines player;
  133.  
  134. } forEach _requirements;
  135.  
  136. // all parts removed proceed
  137. if (_tobe_removed_total == _removed_total) then {
  138.  
  139. // Get position
  140. _location = _obj getVariable["OEMPos",(getposATL _obj)];
  141.  
  142. // Get direction
  143. _dir = getDir _obj;
  144.  
  145. // Current charID
  146. _objectCharacterID = _obj getVariable ["CharacterID","0"];
  147.  
  148. _classname = _newclassname;
  149.  
  150. // Create new object
  151. _object = createVehicle [_classname, [0,0,0], [], 0, "CAN_COLLIDE"];
  152.  
  153. // Set direction
  154. _object setDir _dir;
  155.  
  156. // Set location
  157. _object setPosATL _location;
  158.  
  159. if (_lockable == 3) then {
  160.  
  161. _combination_1 = floor(random 10);
  162. _combination_2 = floor(random 10);
  163. _combination_3 = floor(random 10);
  164. _combination = format["%1%2%3",_combination_1,_combination_2,_combination_3];
  165.  
  166. _objectCharacterID = _combination;
  167.  
  168. cutText [format[(localize "str_epoch_player_158"),_combination,_text], "PLAIN DOWN", 5];
  169. } else {
  170. cutText [format[(localize "str_epoch_player_159"),_text], "PLAIN DOWN", 5];
  171. };
  172.  
  173. PVDZE_obj_Swap = [_objectCharacterID,_object,[_dir,_location],_classname,_obj,player];
  174. publicVariableServer "PVDZE_obj_Swap";
  175.  
  176. player reveal _object;
  177.  
  178. } else {
  179.  
  180. {player addMagazine _x;} forEach _temp_removed_array;
  181. cutText [format[(localize "str_epoch_player_145"),_removed_total,_tobe_removed_total], "PLAIN DOWN"];
  182.  
  183. };
  184. } else {
  185. _textMissing = getText(configFile >> "CfgMagazines" >> _missing >> "displayName");
  186. cutText [format[(localize "str_epoch_player_146"),_missingQty, _textMissing], "PLAIN DOWN"];
  187. };
  188.  
  189. } else {
  190. cutText [(localize "str_epoch_player_82"), "PLAIN DOWN"];
  191. };
  192.  
  193. DZE_ActionInProgress = false;
  194. s_player_upgrade_build = -1;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement