Advertisement
Guest User

Untitled

a guest
Jun 27th, 2015
257
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.99 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 ["_location","_dir","_classname","_text","_object","_objectID","_objectUID","_newclassname","_refund","_obj","_upgrade","_objectCharacterID","_canBuildOnPlot","_friendlies","_nearestPole","_ownerID","_distance","_needText","_findNearestPoles","_findNearestPole","_IsNearPlot","_i","_invResult","_itemOut","_countOut","_abortInvAdd","_addedItems","_vector"];
  6.  
  7. if(DZE_ActionInProgress) exitWith { cutText [(localize "str_epoch_player_48") , "PLAIN DOWN"]; };
  8. DZE_ActionInProgress = true;
  9.  
  10. player removeAction s_player_downgrade_build;
  11. s_player_downgrade_build = 1;
  12.  
  13. _distance = 30;
  14. _needText = localize "str_epoch_player_246";
  15.  
  16. // check for near plot
  17. _findNearestPoles = nearestObjects [(vehicle player), ["Plastic_Pole_EP1_DZ"], _distance];
  18. _findNearestPole = [];
  19.  
  20. {
  21. if (alive _x) then {
  22. _findNearestPole set [(count _findNearestPole),_x];
  23. };
  24. } count _findNearestPoles;
  25.  
  26. _IsNearPlot = count (_findNearestPole);
  27.  
  28. _canBuildOnPlot = false;
  29.  
  30. if(_IsNearPlot == 0) then {
  31. _canBuildOnPlot = true;
  32. } else {
  33.  
  34. // check nearby plots ownership && then for friend status
  35. _nearestPole = _findNearestPole select 0;
  36.  
  37. // Find owner
  38. _ownerID = _nearestPole getVariable["CharacterID","0"];
  39.  
  40. // diag_log format["DEBUG BUILDING: %1 = %2", dayz_characterID, _ownerID];
  41.  
  42. // check if friendly to owner
  43. if(dayz_characterID == _ownerID) then {
  44. _canBuildOnPlot = true;
  45. } else {
  46. _friendlies = _nearestPole getVariable ["plotfriends",[]];
  47. _fuid = [];
  48. {
  49. _friendUID = _x select 0;
  50. _fuid = _fuid + [_friendUID];
  51. } forEach _friendlies;
  52. _builder = getPlayerUID player;
  53. // check if friendly to owner
  54. if(_builder in _fuid) then {
  55. _canBuildOnPlot = true;
  56. };
  57. };
  58. };
  59.  
  60. // exit if not allowed due to plot pole
  61. if(!_canBuildOnPlot) exitWith { DZE_ActionInProgress = false; cutText [format[(localize "str_epoch_player_141"),_needText,_distance] , "PLAIN DOWN"]; };
  62.  
  63. // get cursortarget from addaction
  64. _obj = _this select 3;
  65.  
  66. // Current charID
  67. _objectCharacterID = _obj getVariable ["CharacterID","0"];
  68.  
  69. if(DZE_Lock_Door != _objectCharacterID) exitWith { DZE_ActionInProgress = false; cutText [(localize "str_epoch_player_49") , "PLAIN DOWN"]; };
  70.  
  71. // Find objectID
  72. _objectID = _obj getVariable ["ObjectID","0"];
  73.  
  74. // Find objectUID
  75. _objectUID = _obj getVariable ["ObjectUID","0"];
  76.  
  77. if(_objectID == "0" && _objectUID == "0") exitWith {DZE_ActionInProgress = false; s_player_upgrade_build = -1; cutText [(localize "str_epoch_player_50"), "PLAIN DOWN"];};
  78.  
  79. // Get classname
  80. _classname = typeOf _obj;
  81.  
  82. // Find display name
  83. _text = getText (configFile >> "CfgVehicles" >> _classname >> "displayName");
  84.  
  85. // Find next upgrade
  86. _upgrade = getArray (configFile >> "CfgVehicles" >> _classname >> "downgradeBuilding");
  87.  
  88. if ((count _upgrade) > 0) then {
  89.  
  90. _newclassname = _upgrade select 0;
  91.  
  92. _refund = _upgrade select 1;
  93. [1,1] call dayz_HungerThirst;
  94. player playActionNow "Medic";
  95. [player,20,true,(getPosATL player)] spawn player_alertZombies;
  96.  
  97. _invResult = false;
  98. _abortInvAdd = false;
  99. _i = 0;
  100. _addedItems = [];
  101.  
  102. {
  103. _itemOut = _x select 0;
  104. _countOut = _x select 1;
  105.  
  106. for "_x" from 1 to _countOut do {
  107. _invResult = [player,_itemOut] call BIS_fnc_invAdd;
  108. if(!_invResult) exitWith {
  109. _abortInvAdd = true;
  110. };
  111. if(_invResult) then {
  112. _i = _i + 1;
  113. _addedItems set [(count _addedItems),[_itemOut,1]];
  114. };
  115. };
  116.  
  117. if (_abortInvAdd) exitWith {};
  118.  
  119. } count _refund;
  120.  
  121. // all parts added proceed
  122. if(_i != 0) then {
  123.  
  124. // Get position
  125. _location = _obj getVariable["OEMPos",(getposATL _obj)];
  126.  
  127. // Get direction
  128. _dir = getDir _obj;
  129.  
  130. // Get vector
  131. _vector = [(vectorDir _obj),(vectorUp _obj)];
  132.  
  133. // Reset the character ID on locked doors before they inherit the newclassname
  134. if (_classname in DZE_DoorsLocked) then {
  135. _obj setVariable ["CharacterID",dayz_characterID,true];
  136. _objectCharacterID = dayz_characterID;
  137. };
  138.  
  139. _classname = _newclassname;
  140.  
  141. // Create new object
  142. _object = createVehicle [_classname, [0,0,0], [], 0, "CAN_COLLIDE"];
  143.  
  144. // Set direction
  145. _object setDir _dir;
  146. _object setVariable["memDir",_dir,true];
  147.  
  148. // Set vector
  149. _object setVectorDirAndUp _vector;
  150.  
  151. // Set location
  152. _object setPosATL _location;
  153.  
  154.  
  155. cutText [format[(localize "str_epoch_player_142"),_text], "PLAIN DOWN", 5];
  156.  
  157. PVDZE_obj_Swap = [_objectCharacterID,_object,[_dir,_location,_vector],_classname,_obj,player];
  158. publicVariableServer "PVDZE_obj_Swap";
  159.  
  160. player reveal _object;
  161.  
  162. } else {
  163. cutText [format[(localize "str_epoch_player_143"), _i,(getText(configFile >> "CfgMagazines" >> _itemOut >> "displayName"))], "PLAIN DOWN"];
  164. {
  165. [player,(_x select 0),(_x select 1)] call BIS_fnc_invRemove;
  166. } count _addedItems;
  167.  
  168. };
  169.  
  170. } else {
  171. cutText [(localize "str_epoch_player_51"), "PLAIN DOWN"];
  172. };
  173.  
  174. DZE_ActionInProgress = false;
  175. s_player_downgrade_build = -1;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement