Advertisement
Halvhjearne

weedfarms.sqf

Jun 4th, 2014
3,352
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 6.27 KB | None | 0 0
  1. /*
  2.     Script by HALV
  3.     Create Weed fields (or other objects) in random locations, amount and "random preset" amount of objects,
  4.     objects are placed "Labyrinth Style" around the middle object
  5. */
  6.  
  7. _useLocalMarkers = false;
  8.  
  9. if (isServer)then{
  10.     private["_blacklistedAreas"];
  11.     diag_log "[Random_Weed_Farm]: waiting for BIS_fnc_findSafePos";
  12.     waitUntil {(!isNil "BIS_fnc_findSafePos")};
  13.     if(isNil "dayz_MapArea")then{dayz_MapArea = 7000};
  14.     _WorldName = toLower format ["%1", worldName];
  15.  
  16. //settings
  17.     //how many will spawn farms, note that farms can spawn "on top" of eachother (min 1, default 6)
  18.     _farms = 6;
  19.     //min farms (min 1, default 2)
  20.     _farmsmin = 2;
  21.     //how many plants per farm (min 1, default 9)
  22.     _plants = 9;
  23.     //min plants (min 1, default 4)
  24.     _plantsmin = 4;
  25.     //min dist (in meters) from roads to build farms (default 200m)
  26.     _mindist2roads = 200;
  27.     //the object to spawn, default "Fiberplant"
  28.     _fiberplant = "Fiberplant";
  29.     _spawnarea = (dayz_MapArea/2);
  30.     switch(_WorldName)do{
  31.         case "napf":{
  32.         _blacklistedAreas = [
  33.         [[8246.3184,15485.867,0],   500],
  34.         [[15506.952,13229.368,0],   500],
  35.         [[12399.751,5074.5273,0],   500],
  36.         [[10398.626,8279.4619,0],   500],
  37.         [[5149.9814,4864.1191,0],   500],
  38.         [[6633.1538,7254.916,0],    500],
  39.         [[13288.313,19590.338,0],   800]
  40.         ];
  41.         };
  42.         case "chernarus":{
  43.         _blacklistedAreas = [
  44.         [[23999.742,2.4571743,0],   500],
  45.         [[6325.6772,7807.7412,0],   500],
  46.         [[4063.4226,11664.19,0],    500],
  47.         [[11447.472,11364.504,0],   500],
  48.         [[1606.6443,7803.5156,0],   500],
  49.         [[12944.227,12766.889,0],   500],
  50.         [[8122.35,13464.5,0],       500] // <-- no comma for last entry
  51.         ];
  52.         };
  53.         default{
  54.         _blacklistedAreas = [
  55.             [[0,0,0],   0]
  56.         ];
  57.         };
  58.     };
  59. //function to find x amount of positions around a position (on ground, z axis not included) in a size you define - "labyrinth style"
  60. //[start position, amount of positions to return (ex start pos), distance between positions,include startposition (optional, default true)] call _fnc_positions_array
  61.     _fnc_positions_array = {
  62.         private ["_posi"];
  63.         _pos = _this select 0;
  64.         _amnt = _this select 1;
  65.         _adjust = _this select 2;
  66.         _include = if(count _this > 3)then{_this select 3}else{true};
  67.         _positions = [];
  68.         _buildDir = 0;
  69.         _buildRow = 0;
  70.         _Row = 0;
  71.         _build = 0;
  72.         if(_include)then{_positions set [count _positions,[_pos select 0,_pos select 1,0]];_amnt = _amnt - 1;};
  73.         for "_i" from 0 to (_amnt-1) do {
  74.             if(_Row > 1)then{_buildRow = _buildRow + 1;_Row = 0;};
  75.             if(_buildDir > 3)then{_buildDir = 0;};
  76.             for "_i" from 0 to _buildRow do {
  77.                 switch (_buildDir) do{
  78.                     case 0:{
  79.                         _posi = [(_pos select 0),(_pos select 1) + _adjust]; //up
  80.                         _positions set [count _positions,[_posi select 0,_posi select 1,0]];
  81.                     };
  82.                     case 1:{
  83.                         _posi = [(_pos select 0) + _adjust,(_pos select 1)]; //left
  84.                         _positions set [count _positions,[_posi select 0,_posi select 1,0]];
  85.                     };
  86.                     case 2:{
  87.                         _posi = [(_pos select 0),(_pos select 1) - _adjust]; //down
  88.                         _positions set [count _positions,[_posi select 0,_posi select 1,0]];
  89.                     };
  90.                     case 3:{
  91.                         _posi = [(_pos select 0) - _adjust,(_pos select 1)]; //right
  92.                         _positions set [count _positions,[_posi select 0,_posi select 1,0]];
  93.                     };
  94.                 };
  95.                 _pos = _posi;
  96.                 _build = _build + 1;
  97.                 if(_build >= _amnt)exitWith{};
  98.             };
  99.             _buildDir = _buildDir + 1;
  100.             _Row = _Row + 1;
  101.             if(_build >= _amnt)exitWith{};
  102.         };
  103. //      diag_log format["[Random_Weed_Farm]: Debug - _build: '%1' _amnt: '%2' _positions: '%3' %4",_build,_amnt,(count _positions),_positions];
  104.         _positions
  105.     };
  106.  
  107.     _amnt = round(random _farms);
  108.     if(_amnt < _farmsmin)then{_amnt = _farmsmin};
  109.     if(_amnt < 1)then{_amnt = 1};
  110.  
  111.     diag_log format["[Random_Weed_Farm]: Function loaded ... Server Building %1 Weed Farm(s)",_amnt];
  112.  
  113.     _locations = [];
  114.     for "_i" from 0 to (_amnt-1) do {
  115.         private ["_coords"];
  116.         while{true}do{
  117.             scopeName "posiscope";
  118.             _coords = [getMarkerPos 'Center',0,_spawnarea,25,0,2000,0] call BIS_fnc_findSafePos;
  119.             _roadlist = _coords nearRoads _mindist2roads;
  120.             _IsBlacklisted = false;
  121.             {if(_coords distance (_x select 0) < (_x select 1))exitWith{_IsBlacklisted = true};}forEach _blacklistedAreas;
  122.             if((count _roadlist < 1) and !_IsBlacklisted)then{breakOut "posiscope"};
  123.         };
  124.         _locations set [count _locations,[_coords select 0,_coords select 1,0]];
  125.         _amnt = round(random _plants);
  126.         if(_amnt < _plantsmin)then{_amnt = _plantsmin};
  127.         if(_amnt < 1)then{_amnt = 1};
  128.         diag_log format["[Random_Weed_Farm]: Found Location for a farm (%1) %2 with %3 plants",mapGridPosition _coords,_coords,_amnt];
  129.         //aparently sizeOf has problems sometimes, so we iput this manually - else perhaps use [position, amount, sizeOf "object"]
  130.         _plantpositions = [[(_coords select 0),(_coords select 1),0],_amnt,5] call _fnc_positions_array;
  131.         {
  132.             _plant = createVehicle [_fiberplant, _x, [], 0, "CAN_COLLIDE"];
  133.             _plant setPos _x;
  134.             _uID = str(round(random 999999));
  135.             _plant setVariable ["ObjectID", _uID, true];
  136.             _plant setVariable ["ObjectUID", _uID, true];
  137.             _plant setVariable ["lastUpdate",time,true];
  138.         }forEach _plantpositions;
  139.     };
  140.     diag_log "[Random_Weed_Farm]: Weed Farm(s) Done ... Broadcasting locations for clients";
  141.     PV_HALV_Broadcast_weedlocations = _locations;
  142.     publicVariable "PV_HALV_Broadcast_weedlocations";
  143. };
  144.  
  145. //comment out for no markers
  146. if(!isDedicated)then{
  147.     diag_log "[Random_Weed_Farm]: Client awaiting markers ...";
  148.     waitUntil{(!isNil "PV_HALV_Broadcast_weedlocations")};
  149.     //create markers
  150.     _nr = 1;
  151.     for "_i" from 0 to ((count PV_HALV_Broadcast_weedlocations)-1) do {
  152.         _markername = format["WeedFarm_%1",_nr];
  153.         _markertext = format["Weed Farm %1",_nr];
  154.         if(_useLocalMarkers)then{
  155.             _marker = createMarkerLocal [_markername, (PV_HALV_Broadcast_weedlocations select _i)];
  156.             _marker setMarkerTypeLocal "Warning";
  157.             _marker setMarkerTextLocal _markertext;
  158.             _marker setMarkerColorLocal "ColorGreen";
  159.         }else{
  160.             if (getMarkerColor _markername == "") then {
  161.                 _marker = createMarker [_markername, (PV_HALV_Broadcast_weedlocations select _i)];
  162.                 _marker setMarkerType "Warning";
  163.                 _marker setMarkerText _markertext;
  164.                 _marker setMarkerColor "ColorGreen";
  165.             };
  166.         };
  167.         diag_log format["[Random_Weed_Farm]: Client created marker %1 ...",_nr];
  168.         _nr = _nr + 1;
  169.     };
  170.     PV_HALV_Broadcast_weedlocations = nil;
  171. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement