I have code to generate spawns for items with a seed, so if a player encounters a impossible situation, I can easily recreate it. But it cannot generate median numbers. Here is the code:
for _i, item:Model in pairs(chapter.traverseCritItems[traverseroom.Name]:GetChildren()) do
local index = 0
local previousindex = 0
local indexcap = #chapdata.traversecrititemspawns[traverseroom.Name]
local itemspawn = nil
local fakecount = 0
for count = 1,traverseseed,1 do
fakecount += 1
index = math.clamp(fakecount,1,indexcap)
print("index: "..index.." ".."previousindex: "..previousindex.." ".."indexcap: "..indexcap.." ".."origcount: ".." "..count)
if index > indexcap or previousindex == indexcap then
previousindex = 0
index = 1
fakecount = 0
print("resettedindex: "..index.." ".."resettedpreviousindex: "..previousindex.." ".."indexcap: "..indexcap.." ".."origcount: ".." "..count)
end
task.wait()
previousindex = index
itemspawn = chapdata.traversecrititemspawns[traverseroom.Name][index]
end
if not table.find(crittakenspawns,itemspawn) then
print("Spawn Open!")
table.insert(crittakenspawns,itemspawn)
item:PivotTo(itemspawn)
item.Parent = traverseroom
else
print("Spawn taken, getting new one")
fakecount = 0
local attempts = 10
repeat
fakecount += 1
attempts -= 1
index = math.clamp(fakecount,1,indexcap)
print("index: "..index.." ".."previousindex: "..previousindex.." ".."indexcap: "..indexcap.." ".."origcount: ".." "..fakecount)
if index > indexcap or previousindex == indexcap then
previousindex = 0
index = 1
fakecount = 0
print("resettedindex: "..index.." ".."resettedpreviousindex: "..previousindex.." ".."indexcap: "..indexcap.." ".."origcount: ".." "..fakecount)
end
task.wait()
previousindex = index
itemspawn = chapdata.traverseExtraItemspawns[traverseroom.Name][index]
until not table.find(crittakenspawns,itemspawn) or attempts == 0
if attempts == 0 then
print("Not enough spawns, deleting item "..item.Name)
item:Destroy()
else
print("Found new Spawn!")
table.insert(crittakenspawns,itemspawn)
item:PivotTo(itemspawn)
item.Parent = traverseroom
end
end
end
Here is the module that holds the chapter settings:
chapmodule.traversecrititemspawns = {
traversetesting = {
[1] = CFrame.new(109.21, 11.5, 142.37);
[2] = CFrame.new(109.21, 6.86, 142.37);
[3] = CFrame.new(109.21, 2.29, 142.37);
[4] = CFrame.new(109.23, 10.61, 179.08);
[5] = CFrame.new(109.23, 6.49, 179.08);
[6] = CFrame.new(109.23, 2.44, 179.08)
}
}
chapmodule.traverseExtraItemspawns = {
traversetesting = {
[1] = CFrame.new(117.3, 11.02, 144.38);
[2] = CFrame.new(117.3, 7.03, 144.38);
[3] = CFrame.new(117.3, 2.66, 144.38);
[4] = CFrame.new(117.3, 2.66, 181.09);
[5] = CFrame.new(117.3, 6.47, 181.09);
[6] = CFrame.new(117.3, 11.07, 181.09)
}
}
Thanks in advance! This has been bugging me for weeks. Literally pun intended