Advertisement
Guest User

Foliage script

a guest
Mar 22nd, 2018
297
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.19 KB | None | 0 0
  1. planet.getnearbynodes = function(maxnum)
  2. local cfr = cam.CFrame;
  3. local l = cfr.lookVector;
  4. local pos = cfr.p+(v3(1,1,1)*l*50);
  5. local r = r3(pos-v3(400,400,400),pos+v3(400,400,400));
  6. 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.
  7. local t = {};
  8. for n,v in pairs(parts) do
  9. ins(t,tonumber(v.Name),v);
  10. end;
  11. return t;
  12. end;
  13.  
  14. spawn(function()
  15. local occt = {}; --Occupied table
  16. local prevcfr;
  17. local Info = info(.2,style.Linear);
  18. while wait(.1) do
  19. if (prevcfr==nil) or (prevcfr~=cam.CFrame) then --Camera has moved
  20. if (planet.cons.condedobounce) then break; end;
  21. local pt = planet.getnearbynodes(400); --Get positions closest to camera to place foliage
  22. local wn = 0;
  23. for i,v in pairs(occt) do --Loop through all the visible trees first
  24. wn = wn + 1;
  25. if not pt[i] then --Visible tree is no longer in camera range, time to delete it.
  26. local occupied = wfc(v,'occupied');
  27. local obj = wfc(v,'obj');
  28. occupied.Value = false;
  29. if obj.Value then
  30. local val = obj.Value;
  31. destroy(val);
  32. end;
  33. obj.Value = nil;
  34. occt[i]=nil;
  35. end;
  36. if (wn/300)==floor(wn/300) then wait() end;
  37. end;
  38. for i,v in pairs(pt) do --Makes new agriculture on every node.
  39. wn = wn + 1;
  40. local occupied =(v['occupied']);
  41. local nature = (v['nature']);
  42. local obj = (v['obj']);
  43. if (not occupied.Value) then --If there isn't already agriculture on that node then
  44. occupied.Value = true;
  45. local na = clone(nature.Value);
  46. for i,im in pairs(desc(na)) do
  47. if isa(im,'ImageLabel') then
  48. im.ImageTransparency = 1;
  49. local g = {ImageTransparency = .5};
  50. local t = tservice:Create(im,Info,g);
  51. t:Play(); --Tweens the transparency of the tree.
  52. end;
  53. end;
  54. na.Parent = naturef;
  55. obj.Value = na;
  56. na:SetPrimaryPartCFrame(v.CFrame);
  57. ins(occt,tonumber(v.Name),v); --Added to the occupied table.
  58. end;
  59. if (wn/300)==floor(wn/300) then wait() end;
  60. end;
  61. prevcfr = cam.CFrame;
  62. end;
  63. end;
  64. end);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement