Advertisement
Guest User

remove.sqf

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