Advertisement
DeTrix

remove.sqf

Apr 20th, 2014
32
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.46 KB | None | 0 0
  1. /*
  2. delete object from db with extra waiting by [VB]AWOL
  3. parameters: _obj
  4. */
  5. private ["_playerUid","_found","_activatingPlayer","_obj","_objectID","_objectUID","_started","_finished","_animState","_isMedic","_isOk","_proceed","_counter","_limit","_objType","_sfx","_dis","_itemOut","_countOut","_selectedRemoveOutput","_friendlies","_nearestPole","_ownerID","_refundpart","_isWreck","_findNearestPoles","_findNearestPole","_IsNearPlot","_brokenTool","_removeTool","_isDestructable","_isRemovable","_objOwnerID","_isOwnerOfObj","_preventRefund","_ipos","_item","_radius","_isWreckBuilding","_nameVehicle","_isModular"];
  6.  
  7. if(DZE_ActionInProgress) exitWith { cutText [(localize "str_epoch_player_88") , "PLAIN DOWN"]; };
  8. DZE_ActionInProgress = true;
  9.  
  10. player removeAction s_player_deleteBuild;
  11. s_player_deleteBuild = 1;
  12.  
  13. _obj = _this select 3;
  14.  
  15. _activatingPlayer = player;
  16.  
  17. _playerUid = getPlayerUID _activatingPlayer;
  18. _found=[_playerUID,"AX"] call KRON_StrInStr;
  19. if (_found) then {
  20. _playerUID=[_playerUID] call KRON_convertPlayerUID;
  21. };
  22.  
  23. _objOwnerID = _obj getVariable["CharacterID","0"];
  24. _isOwnerOfObj = (_objOwnerID == _playerUid);
  25.  
  26. if (_obj in DZE_DoorsLocked) exitWith { DZE_ActionInProgress = false; cutText [(localize "STR_EPOCH_ACTIONS_20"), "PLAIN DOWN"];};
  27. if(_obj getVariable ["GeneratorRunning", false]) exitWith {DZE_ActionInProgress = false; cutText [(localize "str_epoch_player_89"), "PLAIN DOWN"];};
  28.  
  29. _objectID = _obj getVariable ["ObjectID","0"];
  30. _objectUID = _obj getVariable ["ObjectUID","0"];
  31.  
  32. _isOk = true;
  33. _proceed = false;
  34. _objType = typeOf _obj;
  35.  
  36. // Chance to break tools
  37. _isDestructable = _obj isKindOf "BuiltItems";
  38. _isWreck = _objType in DZE_isWreck;
  39. _isRemovable = _objType in DZE_isRemovable;
  40. _isWreckBuilding = _objType in DZE_isWreckBuilding;
  41. _isMine = _objType in ["Land_iron_vein_wreck","Land_silver_vein_wreck","Land_gold_vein_wreck"];
  42. _isModular = _obj isKindOf "ModularItems";
  43.  
  44. _limit = 3;
  45. if (DZE_StaticConstructionCount > 0) then {
  46. _limit = DZE_StaticConstructionCount;
  47. }
  48. else {
  49. if (isNumber (configFile >> "CfgVehicles" >> _objType >> "constructioncount")) then {
  50. _limit = getNumber(configFile >> "CfgVehicles" >> _objType >> "constructioncount");
  51. };
  52. };
  53.  
  54. _findNearestPoles = nearestObjects[player, ["Plastic_Pole_EP1_DZ"], 30];
  55. _findNearestPole = [];
  56. {if (alive _x) then {_findNearestPole set [(count _findNearestPole),_x];};} foreach _findNearestPoles;
  57.  
  58. _IsNearPlot = count (_findNearestPole);
  59.  
  60. if(_IsNearPlot >= 1) then {
  61.  
  62. _nearestPole = _findNearestPole select 0;
  63.  
  64. // Find owner
  65. _ownerID = _nearestPole getVariable["CharacterID","0"];
  66.  
  67. // check if friendly to owner
  68. if(_playerUid != _ownerID) then {
  69.  
  70. _friendlies = player getVariable ["friendlyTo",[]];
  71. // check if friendly to owner
  72. if(!(_ownerID in _friendlies)) then {
  73. _limit = round(_limit*2);
  74. };
  75. };
  76. };
  77.  
  78. _nameVehicle = getText(configFile >> "CfgVehicles" >> _objType >> "displayName");
  79.  
  80. cutText [format[(localize "str_epoch_player_162"),_nameVehicle], "PLAIN DOWN"];
  81.  
  82. if (_isModular) then {
  83. //allow previous cutText to show, then show this if modular.
  84. cutText [(localize "STR_EPOCH_ACTIONS_21"), "PLAIN DOWN"];
  85. };
  86.  
  87. // Alert zombies once.
  88. [player,50,true,(getPosATL player)] spawn player_alertZombies;
  89.  
  90. _brokenTool = false;
  91.  
  92. // Start de-construction loop
  93. _counter = 0;
  94. while {_isOk} do {
  95.  
  96. // if object no longer exits this should return true.
  97. if(isNull(_obj)) exitWith {
  98. _isOk = false;
  99. _proceed = false;
  100. };
  101. [1,1] call dayz_HungerThirst;
  102. player playActionNow "Medic";
  103. _dis=20;
  104. [player,_dis,true,(getPosATL player)] spawn player_alertZombies;
  105.  
  106. r_interrupt = false;
  107. _animState = animationState player;
  108. r_doLoop = true;
  109. _started = false;
  110. _finished = false;
  111.  
  112. while {r_doLoop} do {
  113. _animState = animationState player;
  114. _isMedic = ["medic",_animState] call fnc_inString;
  115. if (_isMedic) then {
  116. _started = true;
  117. };
  118. if (_started and !_isMedic) then {
  119. r_doLoop = false;
  120. _finished = true;
  121. _sfx = "repair";
  122. [player,_sfx,0,false,_dis] call dayz_zombieSpeak;
  123. };
  124. if (r_interrupt) then {
  125. r_doLoop = false;
  126. };
  127.  
  128. sleep 0.1;
  129.  
  130. };
  131.  
  132. if(!_finished) exitWith {
  133. _isOk = false;
  134. _proceed = false;
  135. };
  136.  
  137. if(_finished) then {
  138. _counter = _counter + 1;
  139. // 10% chance to break a required tool each pass
  140. if((_isDestructable or _isRemovable) and !_isOwnerOfObj) then {
  141. if((random 10) <= 1) then {
  142. _brokenTool = true;
  143. };
  144. };
  145. };
  146. if(_brokenTool) exitWith {
  147. _isOk = false;
  148. _proceed = false;
  149. };
  150.  
  151. cutText [format[(localize "str_epoch_player_163"), _nameVehicle, _counter,_limit], "PLAIN DOWN"];
  152.  
  153. if(_counter == _limit) exitWith {
  154. _isOk = false;
  155. _proceed = true;
  156. };
  157.  
  158. };
  159.  
  160.  
  161.  
  162. if(_brokenTool) then {
  163. if(_isWreck) then {
  164. _removeTool = "ItemToolbox";
  165. } else {
  166. _removeTool = ["ItemCrowbar","ItemToolbox"] call BIS_fnc_selectRandom;
  167. };
  168. if(([player,_removeTool,1] call BIS_fnc_invRemove) > 0) then {
  169. cutText [format[(localize "str_epoch_player_164"),getText(configFile >> "CfgWeapons" >> _removeTool >> "displayName"),_nameVehicle], "PLAIN DOWN"];
  170. };
  171. };
  172.  
  173. // Remove only if player waited
  174. if (_proceed) then {
  175.  
  176. // Double check that object is not null
  177. if(!isNull(_obj)) then {
  178.  
  179. _ipos = getPosATL _obj;
  180.  
  181. deleteVehicle _obj;
  182.  
  183. if(!_isWreck) then {
  184. PVDZE_obj_Delete = [_objectID,_objectUID,_activatingPlayer];
  185. publicVariableServer "PVDZE_obj_Delete";
  186. };
  187.  
  188. cutText [format[(localize "str_epoch_player_165"),_nameVehicle], "PLAIN DOWN"];
  189.  
  190. _preventRefund = false;
  191.  
  192. _selectedRemoveOutput = [];
  193. if(_isWreck) then {
  194. // Find one random part to give back
  195. _refundpart = ["PartEngine","PartGeneric","PartFueltank","PartWheel","PartGlass","ItemJerrycan"] call BIS_fnc_selectRandom;
  196. _selectedRemoveOutput set [count _selectedRemoveOutput,[_refundpart,1]];
  197. } else {
  198. if(_isWreckBuilding) then {
  199. _selectedRemoveOutput = getArray (configFile >> "CfgVehicles" >> _objType >> "removeoutput");
  200. } else {
  201. _selectedRemoveOutput = getArray (configFile >> "CfgVehicles" >> _objType >> "removeoutput");
  202. _preventRefund = (_objectID == "0" && _objectUID == "0");
  203.  
  204. };
  205. };
  206.  
  207. if((count _selectedRemoveOutput) <= 0) then {
  208. cutText [(localize "str_epoch_player_90"), "PLAIN DOWN"];
  209. };
  210.  
  211. if (_ipos select 2 < 0) then {
  212. _ipos set [2,0];
  213. };
  214.  
  215. _radius = 1;
  216.  
  217. if (_isMine) then {
  218. if((random 10) <= 4) then {
  219. _gems = ["ItemTopaz","ItemObsidian","ItemSapphire","ItemAmethyst","ItemEmerald","ItemCitrine","ItemRuby"];
  220. _gem = _gems select (floor(random (count _gems)));
  221. _selectedRemoveOutput set [(count _selectedRemoveOutput),[_gem,1]];
  222. };
  223. };
  224.  
  225. // give refund items
  226. if((count _selectedRemoveOutput) > 0 and !_preventRefund) then {
  227. _item = createVehicle ["WeaponHolder", _iPos, [], _radius, "CAN_COLLIDE"];
  228. {
  229. _itemOut = _x select 0;
  230. _countOut = _x select 1;
  231. if (typeName _countOut == "ARRAY") then {
  232. _countOut = round((random (_countOut select 1)) + (_countOut select 0));
  233. };
  234. _item addMagazineCargoGlobal [_itemOut,_countOut];
  235. } forEach _selectedRemoveOutput;
  236.  
  237. _item setposATL _iPos;
  238.  
  239. player reveal _item;
  240.  
  241. player action ["Gear", _item];
  242. };
  243. } else {
  244. cutText [(localize "str_epoch_player_91"), "PLAIN DOWN"];
  245. };
  246.  
  247. } else {
  248. r_interrupt = false;
  249. if (vehicle player == player) then {
  250. [objNull, player, rSwitchMove,""] call RE;
  251. player playActionNow "stop";
  252. };
  253. };
  254. DZE_ActionInProgress = false;
  255. s_player_deleteBuild = -1;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement