Chronomad

Flora Generation

Feb 28th, 2018
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.60 KB | None | 0 0
  1. --Flora Generation Client-Side
  2. wait(2)
  3. ReplicatedStorage = game:GetService("ReplicatedStorage")
  4. floraEvent = ReplicatedStorage:WaitForChild("floraEvent") blightEvent = ReplicatedStorage:WaitForChild("blightEvent")
  5. leafEvent = ReplicatedStorage:WaitForChild("leafEvent")
  6. flora = ReplicatedStorage:WaitForChild("Flora")
  7.  
  8.  
  9. function generateFlora(group,targ,node) -- Moves models into the workspace on the client, based on distance from the plants center
  10. local plant = flora:FindFirstChild(targ)
  11. local p2 = plant:Clone()
  12. p2.Parent = group
  13. print("Planted!")
  14. wait(.01)
  15. p2.smallNode.CFrame = CFrame.new(node)p2.smallNode.Anchored = true
  16. fadeIn(p2)
  17. end
  18.  
  19. function fadeOut(targ) -- visual fade effects
  20. for i, v in pairs (targ:GetChildren()) do wait(.001)
  21. for i = 1,10 do
  22. v.Transparency = v.Transparency + .1
  23. end
  24. end
  25. end
  26.  
  27. function fadeIn(targ)
  28. for i, v in pairs (targ:GetChildren()) do wait(.001)
  29. for i = 1,10 do
  30. v.Transparency = v.Transparency - .1
  31. end
  32. end
  33. end
  34.  
  35. floraEvent.OnClientEvent:Connect(function(...) --Server fires remote event when player is within range,generates flora based on strings
  36. local args = {...}
  37. for _, arg in pairs(args) do
  38. end
  39.  
  40. wait(.01) --print (args[23]) print (args[24])
  41. local v = args[3] generateFlora(args[1],v, args[4])
  42. local v = args[5] generateFlora(args[1],v, args[6])
  43. local v = args[7] generateFlora(args[1],v, args[8])
  44. local v = args[9] generateFlora(args[1],v, args[10])
  45. local v = args[11] generateFlora(args[1],v, args[12])
  46. local v = args[13] generateFlora(args[1],v, args[14])
  47. local v = args[15] generateFlora(args[1],v, args[16])
  48.  
  49. end)
  50.  
  51. leafEvent.OnClientEvent:Connect(function(...) --Flora generation for leaves specifically
  52. local args = {...}
  53. for _, arg in pairs(args) do
  54.  
  55. end
  56.  
  57. wait(.01) print (args[1])print (args[2]) print (args[3])print (args[4]) print (args[5])print (args[7])
  58. local v = args[3] generateFlora(args[1],v, args[2])
  59. local v = args[5] generateFlora(args[1],v, args[4])
  60. local v = args[7] generateFlora(args[1],v, args[6])
  61.  
  62. end)
  63.  
  64. blightEvent.OnClientEvent:Connect(function(...) --removes plants when player exits range
  65. local args = {...}
  66. for _, arg in pairs(args) do
  67. --print("Located")
  68. end
  69. local x = args[1]
  70. local g = x:GetChildren()
  71. for i, v in pairs(g) do wait(.001) if v.ClassName == "Model" then fadeOut(v) wait(.001) v:Destroy()
  72. end end end)
  73. ---------------Server-Side--------
  74. plrs = game:GetService("Players") leafEvent = game.ReplicatedStorage:WaitForChild("leafEvent") blightEvent = game.ReplicatedStorage:WaitForChild("blightEvent")
  75. d = 0 local a1 = script.Parent.Parent n1 = a1.smallNode1 n2 = a1.smallNode1.floraType.Value Debounce = true
  76.  
  77. --Nodes = small transparent parts used for prop positioning
  78.  
  79. gen = true
  80.  
  81. while true do wait(.1)
  82. for i , v in ipairs (plrs:GetChildren()) do
  83. local char = v.Character
  84. d = (char.UpperTorso.Position - script.Parent.Position).magnitude -- distance between current player and current props
  85. if d < 200 and gen == true and Debounce == true then gen = false Debounce = false
  86. leafEvent:FireClient(v,a1, -- call client to generate props locally
  87. a1.smallNode1.Position,a1.smallNode1.floraType.Value,
  88. a1.smallNode2.Position,a1.smallNode2.floraType.Value, --1,2
  89. a1.smallNode3.Position,a1.smallNode3.floraType.Value)
  90. wait(.2)
  91.  
  92. Debounce = true
  93. --print("Generating Flora")
  94. elseif d > 200 and gen == false and Debounce == true then gen = true Debounce = false
  95. blightEvent:FireClient(v,a1)
  96. wait(.2) Debounce = true
  97. -- print ("Deleting Flora")
  98. end end end
Advertisement
Add Comment
Please, Sign In to add comment