Advertisement
Guest User

epoch deconstruction www.kaosdayz.com

a guest
Dec 8th, 2013
241
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 11.25 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","_isModularItem","_isUnlockedDoor","_objKAOS","_objAdmin"];
  6.  
  7. if(TradeInprogress) exitWith { cutText ["Remove already in progress." , "PLAIN DOWN"]; };
  8. TradeInprogress = 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. if ((getPlayerUID player) in ["######","######","########"]) then { // Allow admins to deconstruct anything
  18.     _isOwnerOfObj = true;
  19. } else {
  20.     _objOwnerID = _obj getVariable["CharacterID","0"];
  21.     _isOwnerOfObj = (_objOwnerID == dayz_characterID);
  22. };
  23.  
  24. _isModularItem = _obj isKindOf "ModularItems" or _obj isKindOf "Land_DZE_WoodDoor_Base" or _obj isKindOf "CinderWallDoor_DZ_Base";
  25. _isLockableDoor = _obj isKindOf "Land_DZE_WoodDoorLocked_Base" or _obj isKindOf "CinderWallDoorLocked_DZ_Base";
  26.  
  27. if(_isModularItem and !_isOwnerOfObj) exitWith {TradeInprogress = false; cutText ["Cannot remove item: You're not the owner.", "PLAIN DOWN"];};
  28.  
  29. if(_obj getVariable ["GeneratorRunning", false]) exitWith {TradeInprogress = false; cutText ["Cannot remove running generator.", "PLAIN DOWN"];};
  30.  
  31. _objectID   = _obj getVariable ["ObjectID","0"];
  32. _objectUID  = _obj getVariable ["ObjectUID","0"];
  33.  
  34. _isOk = true;
  35. _proceed = false;
  36. _objType = typeOf _obj;
  37.  
  38. // Chance to break tools
  39. _isDestructable = _obj isKindOf "BuiltItems";
  40. _isWreck = _objType in DZE_isWreck;
  41. _isRemovable = _objType in DZE_isRemovable;
  42. _isWreckBuilding = _objType in DZE_isWreckBuilding;
  43.  
  44. _limit = 1;
  45. if(isNumber (configFile >> "CfgVehicles" >> _objType >> "constructioncount")) then {
  46.     _limit = getNumber(configFile >> "CfgVehicles" >> _objType >> "constructioncount");
  47. };
  48.  
  49. _findNearestPoles = nearestObjects[player, ["Plastic_Pole_EP1_DZ"], 30];
  50. _findNearestPole = [];
  51. {if (alive _x) then {_findNearestPole set [(count _findNearestPole),_x];};} foreach _findNearestPoles;
  52.  
  53. _IsNearPlot = count (_findNearestPole);
  54.  
  55. if(_IsNearPlot >= 1) then {
  56.  
  57.     _nearestPole = _findNearestPole select 0;
  58.  
  59.     // Find owner
  60.     _ownerID = _nearestPole getVariable["CharacterID","0"];
  61.  
  62.     // check if friendly to owner
  63.     if(dayz_characterID != _ownerID) then {
  64.        
  65.         _friendlies     = player getVariable ["friendlyTo",[]];
  66.         // check if friendly to owner
  67.         if(!(_ownerID in _friendlies)) then {
  68.             _limit = round(_limit*2);
  69.         };
  70.     };
  71. };
  72.  
  73. _nameVehicle = getText(configFile >> "CfgVehicles" >> _objType >> "displayName");
  74.  
  75. _objKAOS = cursorTarget;
  76. if (!isNull _objKAOS) then {
  77.     //hint format ["Item is %1",typeOF _objKAOS];
  78. };
  79.  
  80. cutText [format["Starting de-construction of %1.",_nameVehicle], "PLAIN DOWN"];
  81.  
  82. // Alert zombies once.
  83. [player,50,true,(getPosATL player)] spawn player_alertZombies;
  84. _brokenTool = false;
  85.  
  86. // Start de-construction loop
  87. _counter = 0;
  88. while {_isOk} do {
  89.  
  90.     // if object no longer exits this should return true.
  91.     if(isNull(_obj)) exitWith {
  92.         _isOk = false;
  93.         _proceed = false;
  94.     };
  95.  
  96.     player playActionNow "Medic";
  97.     _dis=20;
  98.     [player,_dis,true,(getPosATL player)] spawn player_alertZombies;
  99.    
  100.     r_interrupt = false;
  101.     _animState = animationState player;
  102.     r_doLoop = true;
  103.     _started = false;
  104.     _finished = false;
  105.  
  106.     while {r_doLoop} do {
  107.         _animState = animationState player;
  108.         _isMedic = ["medic",_animState] call fnc_inString;
  109.         if (_isMedic) then {
  110.             _started = true;
  111.         };
  112.         if (_started and !_isMedic) then {
  113.             r_doLoop = false;
  114.             _finished = true;
  115.             _sfx = "repair";
  116.             [player,_sfx,0,false,_dis] call dayz_zombieSpeak;
  117.         };
  118.         if (r_interrupt) then {
  119.             r_doLoop = false;
  120.         };
  121.        
  122.         sleep 0.1;
  123.        
  124.     };
  125.  
  126.     if(!_finished) exitWith {
  127.         _isOk = false;
  128.         _proceed = false;
  129.     };
  130.  
  131.     if(_finished) then {
  132.         _counter = _counter + 1;
  133.         // 10% chance to break a required tool each pass
  134.         if((_isDestructable or _isRemovable) and !_isOwnerOfObj) then {
  135.             if((random 10) <= 1) then {
  136.                 _brokenTool = true;
  137.             };
  138.         };
  139.     };
  140.     if(_brokenTool) exitWith {
  141.         _isOk = false;
  142.         _proceed = false;
  143.     };
  144.  
  145.     cutText [format["De-constructing %1 stage %2 of %3 walk away at anytime to cancel.", _nameVehicle, _counter,_limit], "PLAIN DOWN"];
  146.  
  147.     if(_counter == _limit) exitWith {
  148.         _isOk = false;
  149.         _proceed = true;
  150.     };
  151.    
  152. };
  153.  
  154.  
  155.  
  156. if(_brokenTool) then {
  157.     if(_isWreck) then {
  158.         _removeTool = "ItemToolbox";
  159.     } else {
  160.         _removeTool = ["ItemCrowbar","ItemToolbox"] call BIS_fnc_selectRandom;
  161.     };
  162.     if(([player,_removeTool,1] call BIS_fnc_invRemove) > 0) then {
  163.         cutText [format["%1 broke cannot remove %2.",getText(configFile >> "CfgWeapons" >> _removeTool >> "displayName"),_nameVehicle], "PLAIN DOWN"];
  164.     };
  165. };
  166.  
  167. // Remove only if player waited
  168. if (_proceed) then {
  169.    
  170.     // Double check that object is not null
  171.     if(!isNull(_obj)) then {
  172.        
  173.         _ipos = getPosATL _obj;
  174.  
  175.         if (_isLockableDoor and {_obj animationPhase "Open_hinge" == 0}) exitWith {TradeInprogress = false; cutText ["Cannot remove locked door.", "PLAIN DOWN"];};
  176.        
  177.         deleteVehicle _obj;
  178.        
  179.         if(!_isWreck) then {
  180.             PVDZE_obj_Delete = [_objectID,_objectUID,_activatingPlayer];
  181.             publicVariableServer "PVDZE_obj_Delete";
  182.         };
  183.  
  184.         cutText [format["De-constructing %1.",_nameVehicle], "PLAIN DOWN"];
  185.        
  186.         _preventRefund = false;
  187.  
  188.         _selectedRemoveOutput = [];
  189.         if(_isWreck) then {
  190.             // Find one random part to give back
  191.             _refundpart = ["PartEngine","PartGeneric","PartFueltank","PartWheel","PartGlass","ItemJerrycan"] call BIS_fnc_selectRandom;
  192.             _selectedRemoveOutput set [count _selectedRemoveOutput,[_refundpart,1]];
  193.         } else {
  194.             if(_isWreckBuilding) then {
  195.                 _selectedRemoveOutput = getArray (configFile >> "CfgVehicles" >> _objType >> "removeoutput");
  196.             } else {
  197.                 switch (typeOF _objKAOS) do
  198.                 {
  199.                     case "CinderWallHalf_DZ":
  200.                     {
  201.                         //_selectedRemoveOutput = ['CinderBlocks','CinderBlocks','CinderBlocks','MortarBucket'];
  202.                         _selectedRemoveOutput = [["CinderBlocks",3],["MortarBucket",1]];
  203.                         hint format ["Deconstruction found Cinder Half Wall - %1",typeOF _objKAOS];
  204.                     };
  205.                     case "CinderWall_DZ":
  206.                     {
  207.                         //_selectedRemoveOutput = ['CinderBlocks','CinderBlocks','CinderBlocks','CinderBlocks','MortarBucket'];
  208.                         _selectedRemoveOutput = [["CinderBlocks",4],["MortarBucket",1]];
  209.                         hint format ["Deconstruction found Cinder Wall - %1",typeOF _objKAOS];
  210.                     };
  211.                     case "CinderWallDoor_DZ":
  212.                     {
  213.                         //_selectedRemoveOutput = ['CinderBlocks','CinderBlocks','CinderBlocks','CinderBlocks','MortarBucket'];
  214.                         _selectedRemoveOutput = [["ItemPole",3],["ItemTankTrap",3],["CinderBlocks",3],["MortarBucket",1]];
  215.                         hint format ["Deconstruction found Block Garage Door - %1",typeOF _objKAOS];
  216.                     };
  217.                     case "CinderWallDoorSmall_DZ":
  218.                     {
  219.                         //_selectedRemoveOutput = ['CinderBlocks','CinderBlocks','CinderBlocks','CinderBlocks','MortarBucket'];
  220.                         _selectedRemoveOutput = [["ItemTankTrap",1],["CinderBlocks",4],["MortarBucket",1]];
  221.                         hint format ["Deconstruction found Block Door - %1",typeOF _objKAOS];
  222.                     };
  223.                     case "MetalFloor_DZ":
  224.                     {
  225.                         //_selectedRemoveOutput = ['CinderBlocks','CinderBlocks','CinderBlocks','CinderBlocks','MortarBucket'];
  226.                         _selectedRemoveOutput = [["metal_panel_kit",4]];
  227.                         hint format ["Deconstruction found Metal Floor - %1",typeOF _objKAOS];
  228.                     };
  229.                     case "WoodFloorQuarter_DZ":
  230.                     {
  231.                         //_selectedRemoveOutput = ['CinderBlocks','CinderBlocks','CinderBlocks','CinderBlocks','MortarBucket'];
  232.                         _selectedRemoveOutput = [["PartWoodLumber",3],["PartWoodPlywood",3]];
  233.                         hint format ["Deconstruction found Wood Floor 1/4 - %1",typeOF _objKAOS];
  234.                     };
  235.                     case "WoodFloorHalf_DZ":
  236.                     {
  237.                         //_selectedRemoveOutput = ['CinderBlocks','CinderBlocks','CinderBlocks','CinderBlocks','MortarBucket'];
  238.                         _selectedRemoveOutput = [["ItemWoodFloorQuarter",2]];
  239.                         hint format ["Deconstruction found Wood Floor 1/2 - %1",typeOF _objKAOS];
  240.                     };
  241.                     case "WoodSmallWallThird_DZ":
  242.                     {
  243.                         //_selectedRemoveOutput = ['CinderBlocks','CinderBlocks','CinderBlocks','CinderBlocks','MortarBucket'];
  244.                         _selectedRemoveOutput = [["PartWoodLumber",3],["PartWoodPlywood",3]];
  245.                         hint format ["Deconstruction found Wood Wall 1/3 - %1",typeOF _objKAOS];
  246.                     };
  247.                     case "WoodLargeWall_DZ":
  248.                     {
  249.                         //_selectedRemoveOutput = ['CinderBlocks','CinderBlocks','CinderBlocks','CinderBlocks','MortarBucket'];
  250.                         _selectedRemoveOutput = [["ItemWoodWall",1],["PartWoodPlywood",1],["PartWoodLumber",1]];
  251.                         hint format ["Deconstruction found Wood Large Wall - %1",typeOF _objKAOS];
  252.                     };
  253.                     case "WoodSmallWall_DZ":
  254.                     {
  255.                         //_selectedRemoveOutput = ['CinderBlocks','CinderBlocks','CinderBlocks','CinderBlocks','MortarBucket'];
  256.                         _selectedRemoveOutput = [["ItemWoodWallThird",3]];
  257.                         hint format ["Deconstruction found Wood Small Wall - %1",typeOF _objKAOS];
  258.                     };
  259.                     case "WoodStairsSans_DZ":
  260.                     {
  261.                         //_selectedRemoveOutput = ['CinderBlocks','CinderBlocks','CinderBlocks','CinderBlocks','MortarBucket'];
  262.                         _selectedRemoveOutput = [["PartWoodLumber",8]];
  263.                         hint format ["Deconstruction found Wood Stairs Sans - %1",typeOF _objKAOS];
  264.                     };
  265.                     case "WoodStairs_DZ":
  266.                     {
  267.                         //_selectedRemoveOutput = ['CinderBlocks','CinderBlocks','CinderBlocks','CinderBlocks','MortarBucket'];
  268.                         _selectedRemoveOutput = [["PartWoodLumber",2],["ItemWoodStairs",1]];
  269.                         hint format ["Deconstruction found Wood Stairs - %1",typeOF _objKAOS];
  270.                     };
  271.                     case "Fort_RazorWire":
  272.                     {
  273.                         //_selectedRemoveOutput = ['CinderBlocks','CinderBlocks','CinderBlocks','CinderBlocks','MortarBucket'];
  274.                         _selectedRemoveOutput = [["ItemWire",1]];
  275.                         hint format ["Deconstruction found Razor Wire - %1",typeOF _objKAOS];
  276.                     };
  277.                 };
  278.                 //_selectedRemoveOutput = getArray (configFile >> "CfgVehicles" >> _objType >> "removeoutput");
  279.                 //_preventRefund = (_objectID == "0" && _objectUID == "0");
  280.            
  281.             };
  282.         };
  283.        
  284.         if((count _selectedRemoveOutput) <= 0) then {
  285.             cutText ["No parts found.", "PLAIN DOWN"];
  286.         };
  287.  
  288.         if (_ipos select 2 < 0) then {
  289.             _ipos set [2,0];
  290.         };
  291.  
  292.         _radius = 1;
  293.  
  294.         // give refund items
  295.         if((count _selectedRemoveOutput) > 0 and !_preventRefund) then {
  296.             _item = createVehicle ["WeaponHolder", _iPos, [], _radius, "CAN_COLLIDE"];
  297.             {
  298.                 _itemOut = _x select 0;
  299.                 _countOut = _x select 1;
  300.                 if (typeName _countOut == "ARRAY") then {
  301.                     _countOut = round((random (_countOut select 1)) + (_countOut select 0));
  302.                 };
  303.                 _item addMagazineCargoGlobal [_itemOut,_countOut];             
  304.             } forEach _selectedRemoveOutput;
  305.             player reveal _item;
  306.  
  307.             player action ["Gear", _item];
  308.         };
  309.     } else {
  310.         cutText ["Failed object not longer exists.", "PLAIN DOWN"];
  311.     };
  312.  
  313. } else {
  314.     r_interrupt = false;
  315.     if (vehicle player == player) then {
  316.         [objNull, player, rSwitchMove,""] call RE;
  317.         player playActionNow "stop";
  318.     };
  319. };
  320. TradeInprogress = false;
  321. s_player_deleteBuild = -1;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement