#random generation keeps doing weird stuff
24 messages · Page 1 of 1 (latest)
hold on i mightve figured it out lol
basically what you said, i put an exit upside down so when the room generated it turned the next rooms upside down too
ill see if this also fixes the other issue
ok it probably fixed issue number 2, let me double check some stuff and then ill get back to this
ok, so it fixed everything else but the first room sometimes generates ontop of itself
im gonna drop the scripts in on a model file because theyre just fucking MASSIVE combined
,wait no thats dumb hold on
first script, Server
local room = require(script.Room)
local randomValue = math.random(10,25)
local prevRoom = workspace.StartRoom
room.Generate(prevRoom)
for i=1, randomValue do
prevRoom = room.Generate(prevRoom)
end
this script is inside the script Server, and is called Room. its a module
local room = {}
room.info = require(script.Roominfo)
room.lastTurnDirection = nil
room.random = Random.new()
function room.GetRandom(prevRoom)
local totalWeight = 0
for i, info in pairs(room.info) do
totalWeight += info.Weight
end
local randomWeight = room.random:NextInteger(1, totalWeight)
local currentWeight = 0
local randomRoom = nil
for i, info in pairs(room.info) do
currentWeight += info.Weight
if randomWeight <= currentWeight then
randomRoom = workspace.Rooms[i]
break
end
end
-- [1] Next room MUST be different from prev
-- [2] if corner then next must turn other way
-- [3] two stairs cant generate in a row
local direction = room.info[randomRoom.Name]["Direction"]
local hasStairs = room.info[randomRoom.Name]["Stairs"]
local prevHadStairs = room.info[prevRoom.Name]["Stairs"]
if prevRoom.Name == randomRoom.Name then
return room.GetRandom(prevRoom)
elseif direction and direction == room.lastTurnDirection then
return room.GetRandom(prevRoom)
elseif hasStairs and prevHadStairs then
return room.GetRandom(prevRoom)
else
if direction then
room.lastTurnDirection = direction
end
return randomRoom
end
end
function room.Generate(prevRoom)
local randomRoom = room.GetRandom(prevRoom)
local newRoom = randomRoom:Clone()
newRoom.PrimaryPart = newRoom.Entrance
newRoom:PivotTo(prevRoom.Exit.CFrame)
newRoom.Entrance.Transparency = 1
newRoom.Exit.Transparency = 1
newRoom.Parent = workspace.GeneratedRooms
return newRoom
end
return room
this is the last one, and is inside of Room. its a module called Roominfo
local roomInfo = {
["StartRoom"] = {
["Weight"] = 0
},
["LeftTurn"] = {
["Direction"] = "Left",
["Weight"] = 3
},
["RightTurn"] = {
["Direction"] = "Right",
["Weight"] = 3
},
["ShortCrawl"] = {
["Weight"] = 7
},
}
return roomInfo
@paper compass this is the script, sorry for the wait
Gnome code frfr
I see no issue
right? thats why im confused
What’s the issue then
it soemtimes spawns 2 rooms at the start
It’s not the modules fault
fyi weight is extremely unreliable usually
gnomecode lol
after that i modify it with help from here and my own trial and error
uh oh
Prev room should be room.Generate(PrevRoom) the first one