Advertisement
DeTrix

player_buildingDowngrade.sqf

Apr 20th, 2014
32
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.87 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","_text","_object","_objectID","_objectUID","_newclassname","_refund","_obj","_upgrade","_objectCharacterID","_canBuildOnPlot","_friendlies","_nearestPole","_ownerID","_distance","_needText","_findNearestPoles","_findNearestPole","_IsNearPlot","_i","_invResult","_itemOut","_countOut","_abortInvAdd","_addedItems"];
  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. _playerUID = getPlayerUID player;
  17. _found=[_playerUID,"AX"] call KRON_StrInStr;
  18. if (_found) then {
  19. _playerUID=[_playerUID] call KRON_convertPlayerUID;
  20. };
  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_141"),_needText,_distance] , "PLAIN DOWN"]; };
  63.  
  64. // get cursortarget from addaction
  65. _obj = _this select 3;
  66.  
  67. // Current charID
  68. _objectCharacterID = _obj getVariable ["CharacterID","0"];
  69.  
  70. if(DZE_Lock_Door != _objectCharacterID) exitWith { DZE_ActionInProgress = false; cutText [(localize "str_epoch_player_49") , "PLAIN DOWN"]; };
  71.  
  72. // Find objectID
  73. _objectID = _obj getVariable ["ObjectID","0"];
  74.  
  75. // Find objectUID
  76. _objectUID = _obj getVariable ["ObjectUID","0"];
  77.  
  78. if(_objectID == "0" && _objectUID == "0") exitWith {DZE_ActionInProgress = false; s_player_upgrade_build = -1; cutText [(localize "str_epoch_player_50"), "PLAIN DOWN"];};
  79.  
  80. // Get classname
  81. _classname = typeOf _obj;
  82.  
  83. // Find display name
  84. _text = getText (configFile >> "CfgVehicles" >> _classname >> "displayName");
  85.  
  86. // Find next upgrade
  87. _upgrade = getArray (configFile >> "CfgVehicles" >> _classname >> "downgradeBuilding");
  88.  
  89. if ((count _upgrade) > 0) then {
  90.  
  91. _newclassname = _upgrade select 0;
  92.  
  93. _refund = _upgrade select 1;
  94. [1,1] call dayz_HungerThirst;
  95. player playActionNow "Medic";
  96. [player,20,true,(getPosATL player)] spawn player_alertZombies;
  97.  
  98. _invResult = false;
  99. _abortInvAdd = false;
  100. _i = 0;
  101. _addedItems = [];
  102.  
  103. {
  104. _itemOut = _x select 0;
  105. _countOut = _x select 1;
  106.  
  107. for "_x" from 1 to _countOut do {
  108. _invResult = [player,_itemOut] call BIS_fnc_invAdd;
  109. if(!_invResult) exitWith {
  110. _abortInvAdd = true;
  111. };
  112. if(_invResult) then {
  113. _i = _i + 1;
  114. _addedItems set [(count _addedItems),[_itemOut,1]];
  115. };
  116. };
  117.  
  118. if (_abortInvAdd) exitWith {};
  119.  
  120. } forEach _refund;
  121.  
  122. // all parts added proceed
  123. if(_i != 0) then {
  124.  
  125. // Get position
  126. _location = _obj getVariable["OEMPos",(getposATL _obj)];
  127.  
  128. // Get direction
  129. _dir = getDir _obj;
  130.  
  131. // Reset the character ID on locked doors before they inherit the newclassname
  132. if (_classname in DZE_DoorsLocked) then {
  133. _object setVariable ["CharacterID",_playerUID,true];
  134. _objectCharacterID = _playerUID;
  135. };
  136.  
  137. _classname = _newclassname;
  138.  
  139. // Create new object
  140. _object = createVehicle [_classname, [0,0,0], [], 0, "CAN_COLLIDE"];
  141.  
  142. // Set direction
  143. _object setDir _dir;
  144.  
  145. // Set location
  146. _object setPosATL _location;
  147.  
  148.  
  149. cutText [format[(localize "str_epoch_player_142"),_text], "PLAIN DOWN", 5];
  150.  
  151. PVDZE_obj_Swap = [_objectCharacterID,_object,[_dir,_location],_classname,_obj,player];
  152. publicVariableServer "PVDZE_obj_Swap";
  153.  
  154. player reveal _object;
  155.  
  156. } else {
  157. cutText [format[(localize "str_epoch_player_143"), _i,(getText(configFile >> "CfgMagazines" >> _itemOut >> "displayName"))], "PLAIN DOWN"];
  158. {
  159. [player,(_x select 0),(_x select 1)] call BIS_fnc_invRemove;
  160. } forEach _addedItems;
  161.  
  162. };
  163.  
  164. } else {
  165. cutText [(localize "str_epoch_player_51"), "PLAIN DOWN"];
  166. };
  167.  
  168. DZE_ActionInProgress = false;
  169. s_player_downgrade_build = -1;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement