Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- if game:GetService("RunService"):IsClient() then error("Script must be server-side in order to work; use h/ and not hl/") end
- local Player,game,owner = owner,game
- local RealPlayer = Player
- do
- print("FE Compatibility code V2 by Mokiros")
- local RealPlayer = RealPlayer
- script.Parent = RealPlayer.Character
- --Fake event to make stuff like Mouse.KeyDown work
- local Disconnect_Function = function(this)
- this[1].Functions[this[2]] = nil
- end
- local Disconnect_Metatable = {__index={disconnect=Disconnect_Function,Disconnect=Disconnect_Function}}
- local FakeEvent_Metatable = {__index={
- Connect = function(this,f)
- local i = tostring(math.random(0,10000))
- while this.Functions[i] do
- i = tostring(math.random(0,10000))
- end
- this.Functions[i] = f
- return setmetatable({this,i},Disconnect_Metatable)
- end
- }}
- FakeEvent_Metatable.__index.connect = FakeEvent_Metatable.__index.Connect
- local function fakeEvent()
- return setmetatable({Functions={}},FakeEvent_Metatable)
- end
- --Creating fake input objects with fake variables
- local FakeMouse = {Hit=CFrame.new(),KeyUp=fakeEvent(),KeyDown=fakeEvent(),Button1Up=fakeEvent(),Button1Down=fakeEvent(),Button2Up=fakeEvent(),Button2Down=fakeEvent()}
- FakeMouse.keyUp = FakeMouse.KeyUp
- FakeMouse.keyDown = FakeMouse.KeyDown
- local UIS = {InputBegan=fakeEvent(),InputEnded=fakeEvent()}
- local CAS = {Actions={},BindAction=function(self,name,fun,touch,...)
- CAS.Actions[name] = fun and {Name=name,Function=fun,Keys={...}} or nil
- end}
- --Merged 2 functions into one by checking amount of arguments
- CAS.UnbindAction = CAS.BindAction
- --This function will trigger the events that have been :Connect()'ed
- local function TriggerEvent(self,ev,...)
- for _,f in pairs(self[ev].Functions) do
- f(...)
- end
- end
- FakeMouse.TriggerEvent = TriggerEvent
- UIS.TriggerEvent = TriggerEvent
- --Client communication
- local Event = Instance.new("RemoteEvent")
- Event.Name = "UserInput_Event"
- Event.OnServerEvent:Connect(function(plr,io)
- if plr~=RealPlayer then return end
- FakeMouse.Target = io.Target
- FakeMouse.Hit = io.Hit
- if not io.isMouse then
- local b = io.UserInputState == Enum.UserInputState.Begin
- if io.UserInputType == Enum.UserInputType.MouseButton1 then
- return FakeMouse:TriggerEvent(b and "Button1Down" or "Button1Up")
- end
- if io.UserInputType == Enum.UserInputType.MouseButton2 then
- return FakeMouse:TriggerEvent(b and "Button2Down" or "Button2Up")
- end
- for _,t in pairs(CAS.Actions) do
- for _,k in pairs(t.Keys) do
- if k==io.KeyCode then
- t.Function(t.Name,io.UserInputState,io)
- end
- end
- end
- FakeMouse:TriggerEvent(b and "KeyDown" or "KeyUp",io.KeyCode.Name:lower())
- UIS:TriggerEvent(b and "InputBegan" or "InputEnded",io,false)
- end
- end)
- Event.Parent = NLS([==[local Event = script:WaitForChild("UserInput_Event")
- local Mouse = owner:GetMouse()
- local UIS = game:GetService("UserInputService")
- local input = function(io,RobloxHandled)
- if RobloxHandled then return end
- --Since InputObject is a client-side instance, we create and pass table instead
- Event:FireServer({KeyCode=io.KeyCode,UserInputType=io.UserInputType,UserInputState=io.UserInputState,Hit=Mouse.Hit,Target=Mouse.Target})
- end
- UIS.InputBegan:Connect(input)
- UIS.InputEnded:Connect(input)
- local h,t
- --Give the server mouse data every second frame, but only if the values changed
- --If player is not moving their mouse, client won't fire events
- local HB = game:GetService("RunService").Heartbeat
- while true do
- if h~=Mouse.Hit or t~=Mouse.Target then
- h,t=Mouse.Hit,Mouse.Target
- Event:FireServer({isMouse=true,Target=t,Hit=h})
- end
- --Wait 2 frames
- for i=1,2 do
- HB:Wait()
- end
- end]==],script)
- ----Sandboxed game object that allows the usage of client-side methods and services
- --Real game object
- local RealGame = game
- --Metatable for fake service
- local FakeService_Metatable = {
- __index = function(self,k)
- local s = rawget(self,"_RealService")
- if s then
- return typeof(s[k])=="function"
- and function(_,...)return s[k](s,...)end or s[k]
- end
- end,
- __newindex = function(self,k,v)
- local s = rawget(self,"_RealService")
- if s then s[k]=v end
- end
- }
- local function FakeService(t,RealService)
- t._RealService = typeof(RealService)=="string" and RealGame:GetService(RealService) or RealService
- return setmetatable(t,FakeService_Metatable)
- end
- --Fake game object
- local FakeGame = {
- GetService = function(self,s)
- return rawget(self,s) or RealGame:GetService(s)
- end,
- Players = FakeService({
- LocalPlayer = FakeService({GetMouse=function(self)return FakeMouse end},Player)
- },"Players"),
- UserInputService = FakeService(UIS,"UserInputService"),
- ContextActionService = FakeService(CAS,"ContextActionService"),
- RunService = FakeService({
- _btrs = {},
- RenderStepped = RealGame:GetService("RunService").Heartbeat,
- BindToRenderStep = function(self,name,_,fun)
- self._btrs[name] = self.Heartbeat:Connect(fun)
- end,
- UnbindFromRenderStep = function(self,name)
- self._btrs[name]:Disconnect()
- end,
- },"RunService")
- }
- rawset(FakeGame.Players,"localPlayer",FakeGame.Players.LocalPlayer)
- FakeGame.service = FakeGame.GetService
- FakeService(FakeGame,game)
- --Changing owner to fake player object to support owner:GetMouse()
- game,owner = FakeGame,FakeGame.Players.LocalPlayer
- end
- local LastPosition = CFrame.new(-70, 0, -40)
- local x, y, z = -3, -9, -3
- local x1, y1, z1 = 3, -7, 3
- local x2, y2, z2 = x, y, z
- local t1 = true
- while t1 do
- for i = 1, 10 do
- if y2 > y1 then t1 = false break end
- if z2 > z1 then z2 = z y2 = y2 + 1 end
- local part = Instance.new("Part", workspace)
- part.CanCollide = false
- part.Size = Vector3.new(2000, 5, 2000)
- part.CFrame = CFrame.new(x2*part.Size.X, y2*-part.Size.Y+1.5, z2*part.Size.Z)
- part.Anchored = true
- part.Transparency = 0.2
- part.Reflectance = 0.6
- part.BrickColor = BrickColor.new("Deep blue")
- part.BackSurface = "SmoothNoOutlines"
- part.FrontSurface = "SmoothNoOutlines"
- part.BottomSurface = "SmoothNoOutlines"
- part.TopSurface = "SmoothNoOutlines"
- part.RightSurface = "SmoothNoOutlines"
- part.LeftSurface = "SmoothNoOutlines"
- part.Material = "SmoothPlastic"
- if x2 > x1 then x2 = x z2 = z2 + 1 end
- x2 = x2 + 1
- end
- wait()
- end
- local Hills = {
- --Hill1 = {
- -- Position = CFrame.new(-200, 0, -100);
- -- Range = 100;
- -- Height = 10;
- -- Color = BrickColor.new("Medium stone gray");
- -- TreeSpawn = false
- --};
- --[[
- Hill2 = {
- Position = Vector3.new(-200, 0, 200);
- Range = 250;
- Height = 10;
- Color = BrickColor.new("Forest green");
- };
- Hill3 = {
- Position = Vector3.new(-200, 0, -200);
- Range = 200;
- Height = 10;
- Color = BrickColor.new("Forest green");
- };
- Hill4 = {
- Position = Vector3.new(200, 0, -200);
- Range = 150;
- Height = 10;
- Color = BrickColor.new("Forest green");
- }]]
- }
- local treemodel = Instance.new("Model", game.Lighting)
- local p = Instance.new("Part", treemodel)
- local treethickness = math.random(2, 6)
- p.BrickColor = BrickColor.new("Dark orange")
- p.Size = Vector3.new(treethickness, math.random(4, 20), treethickness)
- p.CFrame = CFrame.new(0, 0, 0)
- p.Anchored = true
- p.Name = "stump"
- local p1 = Instance.new("Part", treemodel)
- local leavesize = math.random(4, 30)
- p1.BrickColor = BrickColor.new("Bright green")
- p1.Size = Vector3.new(treethickness + leavesize, leavesize/8, treethickness + leavesize)
- p1.CFrame = CFrame.new(0, p.Size.Y/2 + p1.Size.Y/2, 0)
- p1.Anchored = true
- p1.Name = "bottom_leave"
- local p2 = Instance.new("Part", treemodel)
- p2.BrickColor = BrickColor.new("Bright green")
- p2.Size = Vector3.new(treethickness + leavesize/2, leavesize/8, treethickness + leavesize/2)
- p2.CFrame = CFrame.new(0, p.Size.Y/2 + p1.Size.Y + p2.Size.Y/2, 0)
- p2.Anchored = true
- p2.Name = "top_leave"
- local totaltreeheight = p.Size.Y + p1.Size.Y + p2.Size.Y
- function minimedrandom(n1min, n1, n2min, n2)
- local t = true
- local r = 0
- while t do
- r = math.random(n1, n2)
- if r < n1min and r < 0 then
- t = false
- end
- if r > n2min and r > 0 then
- t = false
- end
- end
- return r
- end
- function block1insideblock2(s1, v1, s2, v2) --idk how to call this pff
- local block1 = {
- Size = s1;
- Position = v1
- }
- local block2 = {
- Size = s2;
- Position = v2
- }
- --check if block1 is inside block2
- if block1.Position == nil then error("Position at argument #1 is nil") end
- if block2.Position == nil then error("Position at argument #3 is nil") end
- if block1.Size == nil then error("Size at argument #2 is nil") end
- if block2.Size == nil then error("Size at argument #4 is nil") end
- if block1.Position.X >= block2.Position.X - block2.Size.X and
- block1.Position.X <= block2.Position.X + block2.Size.X and
- block1.Position.Z >= block2.Position.Z - block2.Size.Z and
- block1.Position.Z <= block2.Position.Z + block2.Size.Z
- then
- return true
- end
- return false
- end
- local tp = true
- local parts = {}
- for i = 1, math.random(50, 100) do
- local newhill = {
- Position = CFrame.new(math.random(-3000, 3000), 0, math.random(-3000, 3000));
- Range = math.random(100, 300);
- Height = math.random(1, 6);
- Color = BrickColor.new("Dark green");
- DirtColor = BrickColor.new("Rust");
- StoneColor = BrickColor.new("Dark stone grey");
- TreeSpawn = true;
- StoneLand = false
- }
- if math.random(1, newhill.Height + 1) == 1 then
- newhill.StoneLand = true
- newhill.TreeSpawn = false
- newhill.Color = newhill.StoneColor
- newhill.DirtColor = newhill.StoneColor
- end
- table.insert(Hills, 0, newhill)
- end
- local max = 1000
- local chunks = 0
- function MagXZ(x, z)
- return x + z
- end
- while wait() do
- function generateblock()
- local P
- if tp == true then
- P = Instance.new("SpawnLocation", workspace)
- else
- P = Instance.new("Part", workspace)
- end
- P.Size = Vector3.new(minimedrandom(-80, -30, 30, 80), 1, minimedrandom(-80, -30, 30, 80))
- P.CFrame = CFrame.new(math.random(-1, 1)*P.Size.X + LastPosition.X, 50, math.random(-1, 1)*P.Size.Z + LastPosition.Z)
- P.Name = "GPart"
- --[[for _,p in pairs(parts) do
- print(p.Position.X .. ", " .. p.Position.Y .. ", " .. p.Position.Z)
- local check = true
- if p.Position == nil and p.Size == nil then print("nope nil") check = false end
- if check then
- if block1insideblock2(p.Size, p.Position, P.Size, P.Position) then
- print("A block was way too much inside another block and was deleted.")
- P:Destroy()
- return
- end
- end
- end]]
- --if P:GetConnectedParts() then
- -- if P:GetConnectedParts()[1].Name ~= "GPart" then
- -- P:Destroy()
- -- return
- -- end
- --end
- if math.abs(MagXZ(P.Position.X, P.Position.Z) - MagXZ(LastPosition.X, LastPosition.Z)) >= (P.Size.X + P.Size.Z) then
- P:Destroy()
- return
- end
- local oldpos = P.CFrame
- local height = 1
- local treescanspawn = true
- local dirtcolor = BrickColor.new("Rust")
- P.BrickColor = BrickColor.new("Dark green")
- for _,h in pairs(Hills) do
- local closeness = -(P.CFrame.p - h.Position.p).magnitude + h.Range
- --local height2 = (Vector3.new(h.Position.X - P.Position.X, 0, h.Position.Z - P.Position.Z).Magnitude/15) - 20
- --if height2 < 0 then height2 = 0 end
- if h.Range > closeness and closeness > 0 then
- height = math.min(h.Height, height) + closeness
- P.BrickColor = h.Color
- dirtcolor = h.DirtColor
- if h.TreeSpawn == false then
- treescanspawn = false
- end
- --print("SUCCESS closeness:" .. closeness)
- else
- --warn("FAIL closeness:" .. closeness)
- end
- end
- height = height + 100-math.noise(P.CFrame.p.X/10, 6421.1761, P.CFrame.p.Z/10)*30
- print(height)
- --print(height)
- --Add dirt
- local PD = Instance.new("Part", workspace)
- PD.Size = Vector3.new(P.Size.X - (math.random(1, 50)/100), height - 4, P.Size.Z - (math.random(1, 50)/100))
- PD.CFrame = CFrame.new(P.Position.X, 50, P.Position.Z)
- PD.BrickColor = dirtcolor
- PD.Anchored = true
- PD.Name = "Dirt"
- --Add grass on top
- P.Size = Vector3.new(P.Size.X, 3, P.Size.Z)
- P.CFrame = CFrame.new(oldpos.X, oldpos.Y + ((height-4)/2), oldpos.Z)
- P.Anchored = true
- P.Name = "Grass"
- --Add sand
- local PS = Instance.new("Part", workspace)
- PS.Size = Vector3.new(P.Size.X + 4, 100, P.Size.Z + 4)
- PS.CFrame = CFrame.new(P.Position.X, -0.5, P.Position.Z)
- PS.BrickColor = BrickColor.new("Cool yellow")
- PS.Anchored = true
- PS.Name = "Sand"
- --Add underbase
- local PB = Instance.new("Part", workspace)
- PB.Size = Vector3.new(PS.Size.X + 4, PS.Size.Y - 2, PS.Size.Z + 4)
- PB.CFrame = CFrame.new(PS.Position.X, -0.5, PS.Position.Z)
- PB.BrickColor = BrickColor.new("Dark stone grey")
- PB.Anchored = true
- PB.Name = "UnderBase"
- if tp == true then
- tp = false
- for _,p in pairs(workspace:GetChildren()) do
- if game.Players:FindFirstChild(p.Name) then
- p:MoveTo(Vector3.new(P.Position.X + math.random(-P.Size.X/2, P.Size.X/2), P.Position.Y + 5, P.Position.Z + math.random(-P.Size.Z/2, P.Size.Z/2)))
- end
- end
- end
- if treescanspawn == true and math.random(1, 6) == 6 then
- for i = 1, math.random(1, 4) do
- local tree = treemodel:Clone()
- tree.Parent = workspace
- tree.stump.CFrame = CFrame.new(P.Position.X + math.random(-P.Size.X/2, P.Size.X/2), P.Position.Y + P.Size.Y/2 + tree.stump.Size.Y/2, P.Position.Z + math.random(-P.Size.Z/2, P.Size.Z/2))
- tree.bottom_leave.CFrame = CFrame.new(tree.stump.Position.X, tree.stump.Position.Y + tree.stump.Size.Y/2 + tree.bottom_leave.Size.Y/2, tree.stump.Position.Z)
- tree.top_leave.CFrame = CFrame.new(tree.stump.Position.X, tree.bottom_leave.Position.Y + tree.bottom_leave.Size.Y/2 + tree.top_leave.Size.Y/2, tree.stump.Position.Z)
- tree.stump.Parent = workspace
- tree.bottom_leave.Parent = workspace
- tree.top_leave.Parent = workspace
- tree:Destroy()
- end
- end
- table.insert(parts, 0, {
- P.Size;
- P.Position
- })
- --print(P.Position.Z .. ", " .. P.Position.Y .. ", " .. P.Position.Z)
- LastPosition = P.Position
- print(math.noise(LastPosition.X - P.Position.X/100, LastPosition.Y - P.Position.Y/100, LastPosition.Z - P.Position.Z/100))
- end
- generateblock()
- if chunks >= max then break end
- chunks = chunks + 1
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement