Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- delete object from db with extra waiting by [VB]AWOL
- parameters: _obj
- */
- 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"];
- if(TradeInprogress) exitWith { cutText ["Remove already in progress." , "PLAIN DOWN"]; };
- TradeInprogress = true;
- player removeAction s_player_deleteBuild;
- s_player_deleteBuild = 1;
- _obj = _this select 3;
- _activatingPlayer = player;
- if ((getPlayerUID player) in ["######","######","########"]) then { // Allow admins to deconstruct anything
- _isOwnerOfObj = true;
- } else {
- _objOwnerID = _obj getVariable["CharacterID","0"];
- _isOwnerOfObj = (_objOwnerID == dayz_characterID);
- };
- _isModularItem = _obj isKindOf "ModularItems" or _obj isKindOf "Land_DZE_WoodDoor_Base" or _obj isKindOf "CinderWallDoor_DZ_Base";
- _isLockableDoor = _obj isKindOf "Land_DZE_WoodDoorLocked_Base" or _obj isKindOf "CinderWallDoorLocked_DZ_Base";
- if(_isModularItem and !_isOwnerOfObj) exitWith {TradeInprogress = false; cutText ["Cannot remove item: You're not the owner.", "PLAIN DOWN"];};
- if(_obj getVariable ["GeneratorRunning", false]) exitWith {TradeInprogress = false; cutText ["Cannot remove running generator.", "PLAIN DOWN"];};
- _objectID = _obj getVariable ["ObjectID","0"];
- _objectUID = _obj getVariable ["ObjectUID","0"];
- _isOk = true;
- _proceed = false;
- _objType = typeOf _obj;
- // Chance to break tools
- _isDestructable = _obj isKindOf "BuiltItems";
- _isWreck = _objType in DZE_isWreck;
- _isRemovable = _objType in DZE_isRemovable;
- _isWreckBuilding = _objType in DZE_isWreckBuilding;
- _limit = 1;
- if(isNumber (configFile >> "CfgVehicles" >> _objType >> "constructioncount")) then {
- _limit = getNumber(configFile >> "CfgVehicles" >> _objType >> "constructioncount");
- };
- _findNearestPoles = nearestObjects[player, ["Plastic_Pole_EP1_DZ"], 30];
- _findNearestPole = [];
- {if (alive _x) then {_findNearestPole set [(count _findNearestPole),_x];};} foreach _findNearestPoles;
- _IsNearPlot = count (_findNearestPole);
- if(_IsNearPlot >= 1) then {
- _nearestPole = _findNearestPole select 0;
- // Find owner
- _ownerID = _nearestPole getVariable["CharacterID","0"];
- // check if friendly to owner
- if(dayz_characterID != _ownerID) then {
- _friendlies = player getVariable ["friendlyTo",[]];
- // check if friendly to owner
- if(!(_ownerID in _friendlies)) then {
- _limit = round(_limit*2);
- };
- };
- };
- _nameVehicle = getText(configFile >> "CfgVehicles" >> _objType >> "displayName");
- _objKAOS = cursorTarget;
- if (!isNull _objKAOS) then {
- //hint format ["Item is %1",typeOF _objKAOS];
- };
- cutText [format["Starting de-construction of %1.",_nameVehicle], "PLAIN DOWN"];
- // Alert zombies once.
- [player,50,true,(getPosATL player)] spawn player_alertZombies;
- _brokenTool = false;
- // Start de-construction loop
- _counter = 0;
- while {_isOk} do {
- // if object no longer exits this should return true.
- if(isNull(_obj)) exitWith {
- _isOk = false;
- _proceed = false;
- };
- player playActionNow "Medic";
- _dis=20;
- [player,_dis,true,(getPosATL player)] spawn player_alertZombies;
- r_interrupt = false;
- _animState = animationState player;
- r_doLoop = true;
- _started = false;
- _finished = false;
- while {r_doLoop} do {
- _animState = animationState player;
- _isMedic = ["medic",_animState] call fnc_inString;
- if (_isMedic) then {
- _started = true;
- };
- if (_started and !_isMedic) then {
- r_doLoop = false;
- _finished = true;
- _sfx = "repair";
- [player,_sfx,0,false,_dis] call dayz_zombieSpeak;
- };
- if (r_interrupt) then {
- r_doLoop = false;
- };
- sleep 0.1;
- };
- if(!_finished) exitWith {
- _isOk = false;
- _proceed = false;
- };
- if(_finished) then {
- _counter = _counter + 1;
- // 10% chance to break a required tool each pass
- if((_isDestructable or _isRemovable) and !_isOwnerOfObj) then {
- if((random 10) <= 1) then {
- _brokenTool = true;
- };
- };
- };
- if(_brokenTool) exitWith {
- _isOk = false;
- _proceed = false;
- };
- cutText [format["De-constructing %1 stage %2 of %3 walk away at anytime to cancel.", _nameVehicle, _counter,_limit], "PLAIN DOWN"];
- if(_counter == _limit) exitWith {
- _isOk = false;
- _proceed = true;
- };
- };
- if(_brokenTool) then {
- if(_isWreck) then {
- _removeTool = "ItemToolbox";
- } else {
- _removeTool = ["ItemCrowbar","ItemToolbox"] call BIS_fnc_selectRandom;
- };
- if(([player,_removeTool,1] call BIS_fnc_invRemove) > 0) then {
- cutText [format["%1 broke cannot remove %2.",getText(configFile >> "CfgWeapons" >> _removeTool >> "displayName"),_nameVehicle], "PLAIN DOWN"];
- };
- };
- // Remove only if player waited
- if (_proceed) then {
- // Double check that object is not null
- if(!isNull(_obj)) then {
- _ipos = getPosATL _obj;
- if (_isLockableDoor and {_obj animationPhase "Open_hinge" == 0}) exitWith {TradeInprogress = false; cutText ["Cannot remove locked door.", "PLAIN DOWN"];};
- deleteVehicle _obj;
- if(!_isWreck) then {
- PVDZE_obj_Delete = [_objectID,_objectUID,_activatingPlayer];
- publicVariableServer "PVDZE_obj_Delete";
- };
- cutText [format["De-constructing %1.",_nameVehicle], "PLAIN DOWN"];
- _preventRefund = false;
- _selectedRemoveOutput = [];
- if(_isWreck) then {
- // Find one random part to give back
- _refundpart = ["PartEngine","PartGeneric","PartFueltank","PartWheel","PartGlass","ItemJerrycan"] call BIS_fnc_selectRandom;
- _selectedRemoveOutput set [count _selectedRemoveOutput,[_refundpart,1]];
- } else {
- if(_isWreckBuilding) then {
- _selectedRemoveOutput = getArray (configFile >> "CfgVehicles" >> _objType >> "removeoutput");
- } else {
- switch (typeOF _objKAOS) do
- {
- case "CinderWallHalf_DZ":
- {
- //_selectedRemoveOutput = ['CinderBlocks','CinderBlocks','CinderBlocks','MortarBucket'];
- _selectedRemoveOutput = [["CinderBlocks",3],["MortarBucket",1]];
- hint format ["Deconstruction found Cinder Half Wall - %1",typeOF _objKAOS];
- };
- case "CinderWall_DZ":
- {
- //_selectedRemoveOutput = ['CinderBlocks','CinderBlocks','CinderBlocks','CinderBlocks','MortarBucket'];
- _selectedRemoveOutput = [["CinderBlocks",4],["MortarBucket",1]];
- hint format ["Deconstruction found Cinder Wall - %1",typeOF _objKAOS];
- };
- case "CinderWallDoor_DZ":
- {
- //_selectedRemoveOutput = ['CinderBlocks','CinderBlocks','CinderBlocks','CinderBlocks','MortarBucket'];
- _selectedRemoveOutput = [["ItemPole",3],["ItemTankTrap",3],["CinderBlocks",3],["MortarBucket",1]];
- hint format ["Deconstruction found Block Garage Door - %1",typeOF _objKAOS];
- };
- case "CinderWallDoorSmall_DZ":
- {
- //_selectedRemoveOutput = ['CinderBlocks','CinderBlocks','CinderBlocks','CinderBlocks','MortarBucket'];
- _selectedRemoveOutput = [["ItemTankTrap",1],["CinderBlocks",4],["MortarBucket",1]];
- hint format ["Deconstruction found Block Door - %1",typeOF _objKAOS];
- };
- case "MetalFloor_DZ":
- {
- //_selectedRemoveOutput = ['CinderBlocks','CinderBlocks','CinderBlocks','CinderBlocks','MortarBucket'];
- _selectedRemoveOutput = [["metal_panel_kit",4]];
- hint format ["Deconstruction found Metal Floor - %1",typeOF _objKAOS];
- };
- case "WoodFloorQuarter_DZ":
- {
- //_selectedRemoveOutput = ['CinderBlocks','CinderBlocks','CinderBlocks','CinderBlocks','MortarBucket'];
- _selectedRemoveOutput = [["PartWoodLumber",3],["PartWoodPlywood",3]];
- hint format ["Deconstruction found Wood Floor 1/4 - %1",typeOF _objKAOS];
- };
- case "WoodFloorHalf_DZ":
- {
- //_selectedRemoveOutput = ['CinderBlocks','CinderBlocks','CinderBlocks','CinderBlocks','MortarBucket'];
- _selectedRemoveOutput = [["ItemWoodFloorQuarter",2]];
- hint format ["Deconstruction found Wood Floor 1/2 - %1",typeOF _objKAOS];
- };
- case "WoodSmallWallThird_DZ":
- {
- //_selectedRemoveOutput = ['CinderBlocks','CinderBlocks','CinderBlocks','CinderBlocks','MortarBucket'];
- _selectedRemoveOutput = [["PartWoodLumber",3],["PartWoodPlywood",3]];
- hint format ["Deconstruction found Wood Wall 1/3 - %1",typeOF _objKAOS];
- };
- case "WoodLargeWall_DZ":
- {
- //_selectedRemoveOutput = ['CinderBlocks','CinderBlocks','CinderBlocks','CinderBlocks','MortarBucket'];
- _selectedRemoveOutput = [["ItemWoodWall",1],["PartWoodPlywood",1],["PartWoodLumber",1]];
- hint format ["Deconstruction found Wood Large Wall - %1",typeOF _objKAOS];
- };
- case "WoodSmallWall_DZ":
- {
- //_selectedRemoveOutput = ['CinderBlocks','CinderBlocks','CinderBlocks','CinderBlocks','MortarBucket'];
- _selectedRemoveOutput = [["ItemWoodWallThird",3]];
- hint format ["Deconstruction found Wood Small Wall - %1",typeOF _objKAOS];
- };
- case "WoodStairsSans_DZ":
- {
- //_selectedRemoveOutput = ['CinderBlocks','CinderBlocks','CinderBlocks','CinderBlocks','MortarBucket'];
- _selectedRemoveOutput = [["PartWoodLumber",8]];
- hint format ["Deconstruction found Wood Stairs Sans - %1",typeOF _objKAOS];
- };
- case "WoodStairs_DZ":
- {
- //_selectedRemoveOutput = ['CinderBlocks','CinderBlocks','CinderBlocks','CinderBlocks','MortarBucket'];
- _selectedRemoveOutput = [["PartWoodLumber",2],["ItemWoodStairs",1]];
- hint format ["Deconstruction found Wood Stairs - %1",typeOF _objKAOS];
- };
- case "Fort_RazorWire":
- {
- //_selectedRemoveOutput = ['CinderBlocks','CinderBlocks','CinderBlocks','CinderBlocks','MortarBucket'];
- _selectedRemoveOutput = [["ItemWire",1]];
- hint format ["Deconstruction found Razor Wire - %1",typeOF _objKAOS];
- };
- };
- //_selectedRemoveOutput = getArray (configFile >> "CfgVehicles" >> _objType >> "removeoutput");
- //_preventRefund = (_objectID == "0" && _objectUID == "0");
- };
- };
- if((count _selectedRemoveOutput) <= 0) then {
- cutText ["No parts found.", "PLAIN DOWN"];
- };
- if (_ipos select 2 < 0) then {
- _ipos set [2,0];
- };
- _radius = 1;
- // give refund items
- if((count _selectedRemoveOutput) > 0 and !_preventRefund) then {
- _item = createVehicle ["WeaponHolder", _iPos, [], _radius, "CAN_COLLIDE"];
- {
- _itemOut = _x select 0;
- _countOut = _x select 1;
- if (typeName _countOut == "ARRAY") then {
- _countOut = round((random (_countOut select 1)) + (_countOut select 0));
- };
- _item addMagazineCargoGlobal [_itemOut,_countOut];
- } forEach _selectedRemoveOutput;
- player reveal _item;
- player action ["Gear", _item];
- };
- } else {
- cutText ["Failed object not longer exists.", "PLAIN DOWN"];
- };
- } else {
- r_interrupt = false;
- if (vehicle player == player) then {
- [objNull, player, rSwitchMove,""] call RE;
- player playActionNow "stop";
- };
- };
- TradeInprogress = false;
- s_player_deleteBuild = -1;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement