generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripting Helpers
Home Search
 

Re: Map gen script

Previous Thread :: Next Thread 
Subete is not online. Subete
Joined: 10 Jul 2011
Total Posts: 917
03 Oct 2014 03:11 PM
Mkay so my current project is a map generating script, it places 50x50 tiles in a square currently.

The tiles that are placed are selected randomly from my storage model, and some of them have limits on how often they can be used.

The issue i'm currently having with this script is the fact that since the way i'm placing the tiles is just 1 row at a time, the limited tiles are usually all located in the first couple rows of the generated map.

Is there an easy way to make a table to put them in more random locations within a pre-set square so to speak?

The current script (no errors with it, just for reference):

local storage = game:GetService("ServerStorage").MapParts
local maxmapsize = 10
local startposX = 0
local startposY = 0
local startposZ = 0
local mapholder = Instance.new("Model",workspace)
mapholder.Name = "MapContainer"

local pieces = {}
for i,v in pairs(storage:GetChildren()) do
table.insert(pieces,tostring(v))
end

local rownumb = 0
local nextpos = Vector3.new(startposX,startposY,startposZ)
local piecemade = false

function makepiece()
local piece = storage:findFirstChild(pieces[math.random(1,#pieces)])
if piece:findFirstChild("Limiter") and piece:findFirstChild("Limiter").Value ~= 0 then
piece:findFirstChild("Limiter").Value = piece:findFirstChild("Limiter").Value - 1
local piece2 = piece:clone()
piece2.Parent = mapholder
piece2:MoveTo(nextpos)
nextpos = nextpos + Vector3.new(0,0,50)
wait(0.1)
piecemade = true
elseif piece:findFirstChild("Limiter") and piece:findFirstChild("Limiter").Value == 0 then
piecemade = false
else
local piece3 = piece:clone()
piece3.Parent = mapholder
piece3:MoveTo(nextpos)
nextpos = nextpos + Vector3.new(0,0,50)
wait(0.1)
piecemade = true
end
end

repeat
for i = 1,maxmapsize do
repeat
makepiece()
until piecemade == true
piecemade = false
end
rownumb = rownumb + 1
nextpos = Vector3.new(startposX + (50 * rownumb),startposY,startposZ)
until rownumb == maxmapsize

local sidelength = maxmapsize * 50
local c = Instance.new("Part",mapholder)
c.Anchored = true
c.FormFactor = "Custom"
c.CanCollide = true
c.Size = Vector3.new(sidelength, 20, 5)
c.CFrame = CFrame.new((-1 + maxmapsize)*25,startposY + 15,startposZ - 22.5)

x2 = c:clone()
x2.Parent = mapholder
x2.CFrame = CFrame.new(c.Position.x,c.Position.y,c.Position.z + sidelength - 5)

local c2 = Instance.new("Part",mapholder)
c2.Anchored = true
c2.FormFactor = "Custom"
c2.CanCollide = true
c2.Size = Vector3.new(5, 20, sidelength)
c2.CFrame = CFrame.new(startposX - 22.5,startposY + 15,(-1 + maxmapsize)*25)

local x3 = c2:clone()
x3.Parent = mapholder
x3.CFrame = CFrame.new(c2.Position.x + sidelength - 5,c2.Position.y,c2.Position.z)

Report Abuse
Subete is not online. Subete
Joined: 10 Jul 2011
Total Posts: 917
03 Oct 2014 03:34 PM
bump -- any improvement suggestions are kindof welcome tbh..
Report Abuse
Subete is not online. Subete
Joined: 10 Jul 2011
Total Posts: 917
03 Oct 2014 04:10 PM
bumpin moar
Report Abuse
Subete is not online. Subete
Joined: 10 Jul 2011
Total Posts: 917
03 Oct 2014 06:23 PM
bump
Report Abuse
eLunate is not online. eLunate
Joined: 29 Jul 2014
Total Posts: 13268
03 Oct 2014 06:33 PM
Take a look at perlin noise, and also the diamond square algorithm.
Report Abuse
Subete is not online. Subete
Joined: 10 Jul 2011
Total Posts: 917
03 Oct 2014 06:44 PM
I'm not good enough at math to know how to implement something like perlin noise, and the diamond square algorithm seems pointless since it's meant to be a flat landscape

:s ty for showing me those things though
Report Abuse
eLunate is not online. eLunate
Joined: 29 Jul 2014
Total Posts: 13268
03 Oct 2014 06:48 PM
Ehh. I used them for my terrain generation script (And then had to implement my own mix of the two because the math was too much for the Roblox servers ^^')
Use the diamond square anyway, since that'll force your generation to not do it row by row. You'll just need to reimplement the part that makes a heightmap and just replace it with a math.random for your tiles or something. Maybe even use it for weighted distrobution.
Report Abuse
Subete is not online. Subete
Joined: 10 Jul 2011
Total Posts: 917
03 Oct 2014 06:50 PM
Hmm okay, i'll look into making that happen. Thanks for the help. :)
Report Abuse
eLunate is not online. eLunate
Joined: 29 Jul 2014
Total Posts: 13268
03 Oct 2014 06:55 PM
Just like, make a new table with an x and y(z) to start. Has to be a power of 2

t = {}
for i=0,16 do
t[i] = {}
end

Then start filling them with that diamond square

Then to upack the table do

for x=0, #t do
for y=0, #t do
-- do something with t[x][y], which is your int value or whatever from your randoms
end
end
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripting Helpers
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image