Advertisement
Guest User

player_build.sqf

a guest
Sep 1st, 2014
191
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 14.44 KB | None | 0 0
  1. /*
  2.     DayZ Base Building
  3.     Made for DayZ Epoch please ask permission to use/edit/distrubute email vbawol@veteranbastards.com.
  4. */
  5. /*
  6. Build Snapping - Extended v1.6
  7.  
  8. Idea and first code:
  9. Maca
  10.  
  11. Reworked by: OtterNas3
  12.  
  13. 01/11/2014
  14. Last update 02/20/2014
  15. */
  16.  
  17. private ["_location","_dir","_classname","_item","_hasrequireditem","_missing","_hastoolweapon","_cancel","_reason","_started","_finished","_animState","_isMedic","_dis","_sfx","_hasbuilditem","_tmpbuilt","_onLadder","_isWater","_require","_text","_offset","_IsNearPlot","_isOk","_location1","_location2","_counter","_limit","_proceed","_num_removed","_position","_object","_canBuildOnPlot","_friendlies","_nearestPole","_ownerID","_findNearestPoles","_findNearestPole","_distance","_classnametmp","_ghost","_isPole","_needText","_lockable","_zheightchanged","_rotate","_combination_1","_combination_2","_combination_3","_combination_4","_combination","_combination_1_Display","_combinationDisplay","_zheightdirection","_abort","_isNear","_need","_objHupDiff","_needNear","_vehicle","_inVehicle","_requireplot","_objHDiff","_isLandFireDZ","_isTankTrap","_ownerPUID", "_playerUID"];
  18.  
  19. if(DZE_ActionInProgress) exitWith { cutText [(localize "str_epoch_player_40") , "PLAIN DOWN"]; };
  20. DZE_ActionInProgress = true;
  21.  
  22. // disallow building if too many objects are found within 30m
  23. if((count ((getPosATL player) nearObjects ["All",30])) >= DZE_BuildingLimit) exitWith {DZE_ActionInProgress = false; cutText [(localize "str_epoch_player_41"), "PLAIN DOWN"];};
  24.  
  25. _onLadder =     (getNumber (configFile >> "CfgMovesMaleSdr" >> "States" >> (animationState player) >> "onLadder")) == 1;
  26. _isWater =      dayz_isSwimming;
  27. _cancel = false;
  28. _reason = "";
  29. _canBuildOnPlot = false;
  30.  
  31. _vehicle = vehicle player;
  32. _inVehicle = (_vehicle != player);
  33. _playerUID = getPlayerUID player;
  34.  
  35. DZE_Q = false;
  36. DZE_Z = false;
  37.  
  38. DZE_Q_alt = false;
  39. DZE_Z_alt = false;
  40.  
  41. DZE_Q_ctrl = false;
  42. DZE_Z_ctrl = false;
  43.  
  44. DZE_5 = false;
  45. DZE_4 = false;
  46. DZE_6 = false;
  47.  
  48. DZE_cancelBuilding = false;
  49.  
  50. call gear_ui_init;
  51. closeDialog 1;
  52.  
  53. if (_isWater) exitWith {DZE_ActionInProgress = false; cutText [localize "str_player_26", "PLAIN DOWN"];};
  54. if (_inVehicle) exitWith {DZE_ActionInProgress = false; cutText [(localize "str_epoch_player_42"), "PLAIN DOWN"];};
  55. if (_onLadder) exitWith {DZE_ActionInProgress = false; cutText [localize "str_player_21", "PLAIN DOWN"];};
  56. if (player getVariable["combattimeout", 0] >= time) exitWith {DZE_ActionInProgress = false; cutText [(localize "str_epoch_player_43"), "PLAIN DOWN"];};
  57.  
  58. _item = _this;
  59.  
  60. // Need Near Requirements
  61. _abort = false;
  62. _distance = 3;
  63. _reason = "";
  64.  
  65. _needNear =     getArray (configFile >> "CfgMagazines" >> _item >> "ItemActions" >> "Build" >> "neednearby");
  66.  
  67. {
  68.     switch(_x) do{
  69.         case "fire":
  70.         {
  71.             _isNear = {inflamed _x} count (getPosATL player nearObjects _distance);
  72.             if(_isNear == 0) then {  
  73.                 _abort = true;
  74.                 _reason = "fire";
  75.             };
  76.         };
  77.         case "workshop":
  78.         {
  79.             _isNear = count (nearestObjects [player, ["Wooden_shed_DZ","WoodShack_DZ","WorkBench_DZ"], _distance]);
  80.             if(_isNear == 0) then {  
  81.                 _abort = true;
  82.                 _reason = "workshop";
  83.             };
  84.         };
  85.         case "fueltank":
  86.         {
  87.             _isNear = count (nearestObjects [player, dayz_fuelsources, _distance]);
  88.             if(_isNear == 0) then {  
  89.                 _abort = true;
  90.                 _reason = "fuel tank";
  91.                 _distance = 30;
  92.             };
  93.         };
  94.     };
  95. } forEach _needNear;
  96.  
  97.  
  98. if(_abort) exitWith {
  99.     cutText [format[(localize "str_epoch_player_135"),_reason,_distance], "PLAIN DOWN"];
  100.     DZE_ActionInProgress = false;
  101. };
  102.  
  103. _classname =    getText (configFile >> "CfgMagazines" >> _item >> "ItemActions" >> "Build" >> "create");
  104. _classnametmp = _classname;
  105. _require =  getArray (configFile >> "cfgMagazines" >> _this >> "ItemActions" >> "Build" >> "require");
  106. _text =         getText (configFile >> "CfgVehicles" >> _classname >> "displayName");
  107. _ghost = getText (configFile >> "CfgVehicles" >> _classname >> "ghostpreview");
  108.  
  109. _lockable = 0;
  110. if(isNumber (configFile >> "CfgVehicles" >> _classname >> "lockable")) then {
  111.     _lockable = getNumber(configFile >> "CfgVehicles" >> _classname >> "lockable");
  112. };
  113.  
  114. _requireplot = DZE_requireplot;
  115. if(isNumber (configFile >> "CfgVehicles" >> _classname >> "requireplot")) then {
  116.     _requireplot = getNumber(configFile >> "CfgVehicles" >> _classname >> "requireplot");
  117. };
  118.  
  119. _isAllowedUnderGround = 1;
  120. if(isNumber (configFile >> "CfgVehicles" >> _classname >> "nounderground")) then {
  121.     _isAllowedUnderGround = getNumber(configFile >> "CfgVehicles" >> _classname >> "nounderground");
  122. };
  123.  
  124. _offset =   getArray (configFile >> "CfgVehicles" >> _classname >> "offset");
  125. if((count _offset) <= 0) then {
  126.     _offset = [0,1.5,0];
  127. };
  128.  
  129. _isPole = (_classname == "Plastic_Pole_EP1_DZ");
  130. _isLandFireDZ = (_classname == "Land_Fire_DZ");
  131.  
  132. _distance = DZE_PlotPole select 0;
  133. _needText = localize "str_epoch_player_246";
  134.  
  135. if(_isPole) then {
  136.     _distance = DZE_PlotPole select 1;
  137. };
  138.  
  139. // check for near plot
  140. _findNearestPoles = nearestObjects [(vehicle player), ["Plastic_Pole_EP1_DZ"], _distance];
  141. _findNearestPole = [];
  142.  
  143. {
  144.     if (alive _x) then {
  145.         _findNearestPole set [(count _findNearestPole),_x];
  146.     };
  147. } foreach _findNearestPoles;
  148.  
  149. _IsNearPlot = count (_findNearestPole);
  150.  
  151. // If item is plot pole and another one exists within 45m
  152. if(_isPole and _IsNearPlot > 0) exitWith {  DZE_ActionInProgress = false; cutText [(localize "str_epoch_player_44") , "PLAIN DOWN"]; };
  153.  
  154. if(_IsNearPlot == 0) then {
  155.  
  156.     // Allow building of plot
  157.     if(_requireplot == 0 or _isLandFireDZ) then {
  158.         _canBuildOnPlot = true;
  159.     };
  160.  
  161. } else {
  162.     // Since there are plots nearby we check for ownership and then for friend status
  163.    
  164.     // check nearby plots ownership and then for friend status
  165.     _nearestPole = _findNearestPole select 0;
  166.  
  167.     // Find owner
  168. _ownerID = _nearestPole getVariable ["ownerPUID","0"];
  169.  
  170. diag_log format["Player_build start: [PlayerUID = %1]  [OwnerID = %2]", _playerUID, _ownerID];
  171.  
  172.     // check if friendly to owner
  173.     if(_playerUID == _ownerID) then {  //Keep ownership
  174.         // owner can build anything within his plot except other plots
  175.         diag_log text "Player is owner";
  176.         if(!_isPole) then {
  177.             _canBuildOnPlot = true;    
  178.         };
  179.  
  180.     } else {
  181.         // disallow building plot
  182.         if(!_isPole) then {
  183.             _friendlies     = player getVariable ["friendlyTo",[]];
  184.             // check if friendly to owner
  185.             if(_ownerID in _friendlies) then {
  186.                 _canBuildOnPlot = true;
  187.             };
  188.         };
  189.     };
  190. };
  191.  
  192. // _message
  193. if(!_canBuildOnPlot) exitWith {  DZE_ActionInProgress = false; cutText [format[(localize "STR_EPOCH_PLAYER_135"),_needText,_distance] , "PLAIN DOWN"]; };
  194.  
  195. _missing = "";
  196. _hasrequireditem = true;
  197. {
  198.     _hastoolweapon = _x in weapons player;
  199.     if(!_hastoolweapon) exitWith { _hasrequireditem = false; _missing = getText (configFile >> "cfgWeapons" >> _x >> "displayName"); }
  200. } forEach _require;
  201.  
  202. _hasbuilditem = _this in magazines player;
  203. if (!_hasbuilditem) exitWith {DZE_ActionInProgress = false; cutText [format[(localize "str_player_31"),_text,"build"] , "PLAIN DOWN"]; };
  204.  
  205. if (!_hasrequireditem) exitWith {DZE_ActionInProgress = false; cutText [format[(localize "str_epoch_player_137"),_missing] , "PLAIN DOWN"]; };
  206. if (_hasrequireditem) then {
  207.  
  208.     _location = [0,0,0];
  209.     _isOk = true;
  210.  
  211.     // get inital players position
  212.     _location1 = getPosATL player;
  213.     _dir = getDir player;
  214.  
  215.     /* Commented out cause GHOST preview does not work with snapping!
  216.     // if ghost preview available use that instead
  217.     if (_ghost != "") then {
  218.         _classname = _ghost;
  219.     };
  220.     */
  221.  
  222.     _object = createVehicle [_classname, _location, [], 0, "CAN_COLLIDE"];
  223.     _object setDir _dir;
  224.     _object attachTo [player,_offset];
  225.    
  226.     _position = getPosATL _object;
  227.  
  228.     cutText [(localize "str_epoch_player_45"), "PLAIN DOWN"];
  229.  
  230.  
  231.     player allowDamage false;
  232.     SnappingOffset = _offset;
  233.     SnappingDir = 0;
  234.     SnappingSpotMarkers = [];
  235.     SnappingEnabled = false;
  236.     SnappedOffsetZ = 0;
  237.     SnappingResetPos = false;
  238.  
  239.     if (isClass (missionConfigFile >> "SnapPoints" >> _classname)) then {
  240.         s_building_snapping = player addAction ["<t color=""#0000ff"">Toggle Snapping</t>", "custom\snap_build\player_toggleSnapping.sqf",_classname, 3, true, false, "",""];
  241.     };
  242.    
  243.     _snapper = [_object, _classname] spawn snap_object;
  244.     _key_monitor = [_isAllowedUnderGround] spawn player_buildControls ;
  245.  
  246.     while {_isOk} do {
  247.         sleep 1;
  248.         _location2 = getPosATL player;
  249.  
  250.         if(DZE_5) exitWith {
  251.             _isOk = false;
  252.             detach _object;
  253.             _dir = getDir _object;
  254.             _position = getPosATL _object;
  255.         };
  256.  
  257.         if(_location1 distance _location2 > 5) exitWith {
  258.             _isOk = false;
  259.             _cancel = true;
  260.             _reason = "You've moved to far away from where you started building (within 5 meters)";
  261.             detach _object;
  262.         };
  263.        
  264.         if(((SnappingOffset select 2) > 5) or ((SnappingOffset select 2) < -5)) exitWith {
  265.             _isOk = false;
  266.             _cancel = true;
  267.             _reason = "Cannot move up or down more than 5 meters";
  268.             detach _object;
  269.         };
  270.  
  271.         if (player getVariable["combattimeout", 0] >= time) exitWith {
  272.             _isOk = false;
  273.             _cancel = true;
  274.             _reason = (localize "str_epoch_player_43");
  275.             detach _object;
  276.         };
  277.  
  278.         if (DZE_cancelBuilding) exitWith {
  279.             _isOk = false;
  280.             _cancel = true;
  281.             _reason = "Cancelled building.";
  282.             detach _object;
  283.         };
  284.     };
  285.  
  286.     terminate _snapper;
  287.     terminate _key_monitor;
  288.     player removeAction s_building_snapping;
  289.     player allowDamage true;
  290.    
  291.     //No building on roads unless toggled
  292.     if (!DZE_BuildOnRoads) then {
  293.         if (isOnRoad _position) then { _cancel = true; _reason = "Cannot build on a road."; };
  294.     };
  295.     // No building in trader zones
  296.     if(!canbuild) then { _cancel = true; _reason = "Cannot build in a city."; };
  297.  
  298.  
  299.     if(!_cancel) then {
  300.  
  301.         _classname = _classnametmp;
  302.  
  303.         _location = _position;
  304.  
  305.         if((_isAllowedUnderGround == 0) and ((_location select 2) < 0)) then {
  306.             _location set [2,0];
  307.         };
  308.    
  309.         _object setPosATL _location;
  310.         cutText [format[(localize "str_epoch_player_138"),_text], "PLAIN DOWN"];
  311.        
  312.         _limit = 3;
  313.  
  314.         if (DZE_StaticConstructionCount > 0) then {
  315.             _limit = DZE_StaticConstructionCount;
  316.         }
  317.         else {
  318.             if (isNumber (configFile >> "CfgVehicles" >> _classname >> "constructioncount")) then {
  319.                 _limit = getNumber(configFile >> "CfgVehicles" >> _classname >> "constructioncount");
  320.             };
  321.         };
  322.  
  323.         _isOk = true;
  324.         _proceed = false;
  325.         _counter = 0;
  326.        
  327.         while {_isOk} do {
  328.  
  329.             [10,10] call dayz_HungerThirst;
  330.             player playActionNow "Medic";
  331.            
  332.             _dis=20;
  333.             _sfx = "repair";
  334.             [player,_sfx,0,false,_dis] call dayz_zombieSpeak;  
  335.             [player,_dis,true,(getPosATL player)] spawn player_alertZombies;
  336.    
  337.             r_interrupt = false;
  338.             _animState = animationState player;
  339.             r_doLoop = true;
  340.             _started = false;
  341.             _finished = false;
  342.    
  343.             while {r_doLoop} do {
  344.                 _animState = animationState player;
  345.                 _isMedic = ["medic",_animState] call fnc_inString;
  346.                 if (_isMedic) then {
  347.                     _started = true;
  348.                 };
  349.                 if (_started and !_isMedic) then {
  350.                     r_doLoop = false;
  351.                     _finished = true;
  352.                 };
  353.                 if (r_interrupt or (player getVariable["combattimeout", 0] >= time)) then {
  354.                     r_doLoop = false;
  355.                 };
  356.                 if (DZE_cancelBuilding) exitWith {
  357.                     r_doLoop = false;
  358.                 };
  359.                 sleep 0.1;
  360.             };
  361.             r_doLoop = false;
  362.  
  363.  
  364.             if(!_finished) exitWith {
  365.                 _isOk = false;
  366.                 _proceed = false;
  367.             };
  368.  
  369.             if(_finished) then {
  370.                 _counter = _counter + 1;
  371.             };
  372.  
  373.             cutText [format[(localize "str_epoch_player_139"),_text, _counter,_limit], "PLAIN DOWN"];
  374.  
  375.             if(_counter == _limit) exitWith {
  376.                 _isOk = false;
  377.                 _proceed = true;
  378.             };
  379.    
  380.         };
  381.  
  382.         if (_proceed) then {
  383.    
  384.             _num_removed = ([player,_item] call BIS_fnc_invRemove);
  385.             if(_num_removed == 1) then {
  386.  
  387.                 cutText [format[localize "str_build_01",_text], "PLAIN DOWN"];
  388.  
  389.                 if (_isPole) then {
  390.                     [] spawn player_plotPreview;
  391.                 };
  392.  
  393.                 _object setVariable ["OEMPos",_location,true];
  394.  
  395.                 if(_lockable > 1) then {
  396.                    
  397.                     _combinationDisplay = "";
  398.  
  399.                     switch (_lockable) do {
  400.                        
  401.                         case 2: { // 2 lockbox
  402.                             _combination_1 = (floor(random 3)) + 100; // 100=red,101=green,102=blue
  403.                             _combination_2 = floor(random 10);
  404.                             _combination_3 = floor(random 10);
  405.                             _combination = format["%1%2%3",_combination_1,_combination_2,_combination_3];
  406.                             dayz_combination = _combination;
  407.                             if (_combination_1 == 100) then {
  408.                                 _combination_1_Display = "Red";
  409.                             };
  410.                             if (_combination_1 == 101) then {
  411.                                 _combination_1_Display = "Green";
  412.                             };
  413.                             if (_combination_1 == 102) then {
  414.                                 _combination_1_Display = "Blue";
  415.                             };
  416.                             _combinationDisplay = format["%1%2%3",_combination_1_Display,_combination_2,_combination_3];
  417.                         };
  418.                        
  419.                         case 3: { // 3 combolock
  420.                             _combination_1 = floor(random 10);
  421.                             _combination_2 = floor(random 10);
  422.                             _combination_3 = floor(random 10);
  423.                             _combination = format["%1%2%3",_combination_1,_combination_2,_combination_3];
  424.                             dayz_combination = _combination;
  425.                             _combinationDisplay = _combination;
  426.                         };
  427.                        
  428.                         case 4: { // 4 safe
  429.                             _combination_1 = floor(random 10);
  430.                             _combination_2 = floor(random 10);
  431.                             _combination_3 = floor(random 10);
  432.                             _combination_4 = floor(random 10);
  433.                             _combination = format["%1%2%3%4",_combination_1,_combination_2,_combination_3,_combination_4];
  434.                             dayz_combination = _combination;
  435.                             _combinationDisplay = _combination;
  436.                         };
  437.                     };
  438.  
  439.                     _object setVariable ["CharacterID",_combination,true];
  440.                    
  441.  
  442.                     PVDZE_obj_Publish = [_combination,_object,[_dir,_location],_classname];
  443.                     publicVariableServer "PVDZE_obj_Publish";
  444.  
  445.                     cutText [format[(localize "str_epoch_player_140"),_combinationDisplay,_text], "PLAIN DOWN", 5];
  446.                    
  447.  
  448.                 } else {
  449.                     _object setVariable ["CharacterID",dayz_characterID,true];
  450.                    
  451.                     // fire?
  452.                     if(_object isKindOf "Land_Fire_DZ") then {
  453.                         _object spawn player_fireMonitor;
  454.                     } else {
  455.                         PVDZE_obj_Publish = [dayz_characterID,_object,[_dir,_location],_classname];
  456.                         publicVariableServer "PVDZE_obj_Publish";
  457.                     };
  458.                 };
  459.             } else {
  460.                 deleteVehicle _object;
  461.                 cutText [(localize "str_epoch_player_46") , "PLAIN DOWN"];
  462.             };
  463.  
  464.         } else {
  465.             r_interrupt = false;
  466.             if (vehicle player == player) then {
  467.                 [objNull, player, rSwitchMove,""] call RE;
  468.                 player playActionNow "stop";
  469.             };
  470.  
  471.             deleteVehicle _object;
  472.  
  473.             cutText [(localize "str_epoch_player_46") , "PLAIN DOWN"];
  474.         };
  475.  
  476.     } else {
  477.         deleteVehicle _object;
  478.         cutText [format[(localize "str_epoch_player_47"),_text,_reason], "PLAIN DOWN"];
  479.     };
  480. };
  481.  
  482. DZE_ActionInProgress = false;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement