Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- planet.getnearbynodes = function(maxnum)
- local cfr = cam.CFrame;
- local l = cfr.lookVector;
- local pos = cfr.p+(v3(1,1,1)*l*50);
- local r = r3(pos-v3(400,400,400),pos+v3(400,400,400));
- local parts = workspace:FindPartsInRegion3WithWhiteList(r,{foliaget},huge); --foliaget is a folder that consists of 5,000+ baseparts that are pre-calculated nodes for where the foliage should go, and what type.
- local t = {};
- for n,v in pairs(parts) do
- ins(t,tonumber(v.Name),v);
- end;
- return t;
- end;
- spawn(function()
- local occt = {}; --Occupied table
- local prevcfr;
- local Info = info(.2,style.Linear);
- while wait(.1) do
- if (prevcfr==nil) or (prevcfr~=cam.CFrame) then --Camera has moved
- if (planet.cons.condedobounce) then break; end;
- local pt = planet.getnearbynodes(400); --Get positions closest to camera to place foliage
- local wn = 0;
- for i,v in pairs(occt) do --Loop through all the visible trees first
- wn = wn + 1;
- if not pt[i] then --Visible tree is no longer in camera range, time to delete it.
- local occupied = wfc(v,'occupied');
- local obj = wfc(v,'obj');
- occupied.Value = false;
- if obj.Value then
- local val = obj.Value;
- destroy(val);
- end;
- obj.Value = nil;
- occt[i]=nil;
- end;
- if (wn/300)==floor(wn/300) then wait() end;
- end;
- for i,v in pairs(pt) do --Makes new agriculture on every node.
- wn = wn + 1;
- local occupied =(v['occupied']);
- local nature = (v['nature']);
- local obj = (v['obj']);
- if (not occupied.Value) then --If there isn't already agriculture on that node then
- occupied.Value = true;
- local na = clone(nature.Value);
- for i,im in pairs(desc(na)) do
- if isa(im,'ImageLabel') then
- im.ImageTransparency = 1;
- local g = {ImageTransparency = .5};
- local t = tservice:Create(im,Info,g);
- t:Play(); --Tweens the transparency of the tree.
- end;
- end;
- na.Parent = naturef;
- obj.Value = na;
- na:SetPrimaryPartCFrame(v.CFrame);
- ins(occt,tonumber(v.Name),v); --Added to the occupied table.
- end;
- if (wn/300)==floor(wn/300) then wait() end;
- end;
- prevcfr = cam.CFrame;
- end;
- end;
- end);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement