Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
-1

I found a Noise Generator, and for some reason when water spawns it does not have a bottom? [closed]

Asked by 5 years ago
Edited 5 years ago

I found a Noise Generator, and for some reason when water spawns there is a "Void". And nothing else spawns under the water. Can someone give me the code that would do the same, ** Except There Would be Blocks that would spawn under the map, Until "bedrock" ** , (Kinda like MineCraft) could someone please help?

Here is what you will need to do:

  1. Put a folder in the workspace called: "World"

  2. Put The script that I am about to give you, In the terrain part in the workspace.

I highly advise you be an expert because this has over 100 lines of code, and I don't want you to mess it up even more!

Script:

local size = Vector3.new(
                        100, -- Number of tiles along the width. The higher the more tiles are made in the X axis.
                         math.random(100, 250), -- Number of steps of heightmap. The higher the terrain has lower top altitude but smoother terrain, The lower the more steeper and extreme terrain.
                         100) -- Number of tiles along the length. The higher the more tiles are made in the Z axis.

local noiseScale = Vector3.new(
    45, -- Stretches the terrain along the x-axis. Adjusting this value is like adjusting the 'Zoom' of the noise map. Lower values result in more compact and extreme terrain, and vice versa.
    math.random(100, 250), -- Streches the terrain along the y-axis. There is no major noticable difference...
    45 -- Streches the terrain along thr z-axis. Adjusting this value is like adjusting the 'Zoom' of the noise map. Lower values result in more compact and extreme terrain, and vice versa.
)

local base  = script.Parent -- The part to replace with terrain
local Intensity = 2^7 -- (2^7 = 128) Average terrain height? (Actual average terrain height is Intensity * 1.2) 
local Offset = 0.2 -- (Default 0.2 for reasonable amount of oceans) Offset of the y-axis. Higher values result in higher overall terrain, and vice versa.

local Location = game.Workspace.World -- Where the replicated terrain sectors go.

local NoiseThreshold = 2^16 -- 2^16 = 65536 is the max

local usePrint = true
local useWarn = true
local generateVec3Val = true

local initTime = 3 -- Time before generation warning is fired
local initAfterPause = 0.5 -- Time before generation begins, after generation warning is fired
local generateDelay = 1/50 -- Time between 'generation attempts'.
local generateSplit = 50 -- Amount of blocks generated every 'time'. Recommended values below 200 to reduce lag.

local limitsBoundary = -- Height map the generated sectors
{
    -math.huge;
    0.06;
    10;
    125;
    165;
    200;
    2^9; -- = 512
    2^10; -- = 1024
    2^11 - 1 -- 2047
}

local colorsBasedOnHeight = -- Height map the generated sectors
{
    BrickColor.new('Lapis');
    BrickColor.new('Cashmere');
    BrickColor.new('Bright green');
    BrickColor.new('Earth green');
    BrickColor.new('Dark stone grey');
    BrickColor.new('Pastel light blue');
    BrickColor.new('Lily white');
    BrickColor.new('Cyan');
    BrickColor.new('Really red')
}

local materialsBasedOnHeight = -- Height map the generated sectors
{
    Enum.Material.Foil;
    Enum.Material.Sand;
    Enum.Material.Grass;
    Enum.Material.Grass;
    Enum.Material.Slate;
    Enum.Material.Ice;
    Enum.Material.Ice;
    Enum.Material.Neon;
    Enum.Material.Neon
}

local overridenSeed = nil -- The override to seed, set to nil if seed should be random. Only works for initial generation

---------------------------------------------------------------------------------------------

math.randomseed(tick())
math.random()
math.random()
math.random()
math.random()

if tonumber(overridenSeed) ~= nil then
    math.randomseed(tonumber(overridenSeed))
end

local tilePart = Instance.new("Part")
tilePart.Anchored = true
tilePart.formFactor = "Custom"
tilePart.Size = base.Size / size --The size of one unit or cuboid of the map

local function CP(str,bool) -- Declare a function used to print/warn out the status of the generation and stuff.
    if usePrint then
        if bool == false or bool == nil then
            print(str)
        end
    end
    if useWarn then
        if bool == true then
            warn(str)
        end
    end
end

script.Parent.CanCollide = false
script.Parent.Transparency = 1
local iteratedfor = 0
local totaliteration = 0

function generateTerrain() -- Declare function for generating the terrain itself

    totaliteration = 0
    iteratedfor = 0
    local scale = size.Y
    local seed_offset = Vector3.new(NoiseThreshold * (math.random() - 0.5), NoiseThreshold * (math.random() - 0.5), NoiseThreshold * (math.random() - 0.5))

    if initTime > 0 then
        for i=0, 20 do
            CP('Initiating: '.. i*5 .. '%')
            wait()
        end
    end

    local estGenSpeedPerSec = generateSplit/generateDelay

    CP('Generating at ' .. estGenSpeedPerSec ..'bk/sec' , true)
    CP('Total: ' .. size.X * size.Z .. ' Blocks' , true)
    wait(initAfterPause)

    for x = 1, size.x do
        for z = 1, size.z do
            local y = math.noise(x / noiseScale.X + 0.5 * 1 + seed_offset.X, size.Y / noiseScale.Y + 0.5 * 1 + seed_offset.Y, z / noiseScale.Z + 0.5 * 1 + seed_offset.Z)
            local tile = tilePart:clone()

            if Location:FindFirstChild('x' .. x .. 'z' .. z) then -- If that sector is already found
                Location:FindFirstChild('x' .. x .. 'z' .. z):Destroy() -- Destroy that sector (and replace it with the new one)
            end

            totaliteration = totaliteration + 1
            local position = Vector3.new(x-1, 0, z-1) * tile.Size
            tile.Size = tile.Size * Vector3.new(1, y*Intensity+(Intensity*(Offset)), 1)
            tile.CFrame = CFrame.new(tile.Size/2)     --Shift the part by half it's size, so we can position the corner
            tile.CFrame = tile.CFrame - base.Size / 2 --Shift it into one corner of the base
            tile.CFrame = tile.CFrame + position      --Put it in the right place
            tile.CFrame = base.CFrame * tile.CFrame   --Move it so that it is level with the surface of the base
            tile.Parent = Location
            tile.Locked = true
            tile.BottomSurface = Enum.SurfaceType.SmoothNoOutlines
            tile.TopSurface = Enum.SurfaceType.SmoothNoOutlines
            tile.LeftSurface = Enum.SurfaceType.SmoothNoOutlines
            tile.RightSurface = Enum.SurfaceType.SmoothNoOutlines
            tile.FrontSurface = Enum.SurfaceType.SmoothNoOutlines
            tile.BackSurface = Enum.SurfaceType.SmoothNoOutlines
            tile.Name = 'x' .. x ..'z' .. z -- Rename the block to make the sector easier to find
            if generateVec3Val then
                local vec = Instance.new("Vector3Value",tile)
                vec.Name = 'SectorInVector3'
                vec.Value = Vector3.new(x , y , z)
            end
            CP('Made sector x=' .. tostring(x) .. ', z=' .. tostring(z) .. ' With height y=' .. math.floor(tile.Size.Y*10)/10 .. ' (Block Number: ' .. totaliteration .. '/' ..size.X * size.Z  .. ', ' .. math.floor((totaliteration / (size.X * size.Z)) * 100*100)/100 .. '%)')

            for i,v in ipairs(limitsBoundary) do -- This is the part where the script recolors and rematerializes the sector
                if tile.Size.Y > v then
                    tile.BrickColor = colorsBasedOnHeight[i]
                    tile.Material = materialsBasedOnHeight[i]

                end
            end     
            iteratedfor = iteratedfor + 1

            if generateDelay ~= nil and generateDelay > 0 and iteratedfor >= generateSplit then
                iteratedfor = 0
                wait(generateDelay)
            end
        end
    end -- an end for each for loop
    CP('Finished generating' , true)
end

generateTerrain()


0
Scripting Helpers is not a site to get free code or get help fixing code you did not create. Read the site's guidelines before attempting to post a question like this. xPolarium 1388 — 5y
0
can't you just have it spawn in a single layer under the map after it finishes the main generation? SteamG00B 1633 — 5y
0
@SteamG0D That's a great Idea! DragRacer31 7 — 5y
0
also just putting this out there, but you should probably use this script you found to make your own, just so you have a better understanding of this. Also, if you do plan on making a new script, you should probably make it recursive because for this type of thing, it might decrease the complexity a little bit. SteamG00B 1633 — 5y

Closed as Not Constructive by xPolarium, User#23365, and User#24403

This question has been closed because it is not constructive to others or the asker. Most commonly, questions that are requests with no attempt from the asker to solve their problem will fall into this category.

Why was this question closed?