Okay now can you make the randomly generated map? It would have 5 fodder rooms (rooms with some helpful loot like speed potion, not all rooms would have this loot and this loot spawn location would be set in 3 random places of the room so 3 waypoints that I can place at my will) 2 hallway rooms with spawning items as well (forgot to say for each room it has a 25% chance of spawning an item in one of the 3 waypoints of each room, and all rooms no matter the type will only have 3 available item spawn locations) 3 important rooms (this have the same size as the fodder rooms but spawn in each one of the 3 keycards needed to escape, this means in each room there will be one key card) one nest room (a big room where the monster came from , a exit room where you put the key cards and finally 4 decoration rooms where its pretty much a window to another room where the monster left a disaster. I was thinking just make the layout generarion and then Ill just replace the generated parts with the model of each room being the correct size matching the one of the part that was generated and remember its not infinite
Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
Okay, let's create a system for randomly generating your map with the specified room types and loot/keycard placement. This will involve creating a function to generate the room layout and then placing the appropriate parts.
lua
-- ServerScriptService.MapGenerator
local workspace = workspace
local PathNode = game:GetService("PathfindingService"):CreatePath({
AgentHeight = 5,
AgentRadius = 2,
AgentCanJump = false,
})
local roomSizes = {
fodderRoomSize = Vector3.new(20, 10, 20),
hallwayRoomSize = Vector3.new(30, 5, 30),
importantRoomSize = Vector3.new(20, 10, 20),
nestRoomSize = Vector3.new(40, 20, 40),
decorationRoomSize = Vector3.new(25, 15, 25)
}
local roomTypes = {
"FodderRoom",
"HallwayRoom",
"ImportantRoom",
"NestRoom",
"DecorationRoom"
}
local keycardModel = workspace:WaitForChild("Keycard") -- Make sure you have a Keycard model in the workspace
-- Function to generate a random room layout
local function generateRandomRoom(roomType, position)
local roomSize = roomSizes[roomType]
local roomPart = Instance.new("Part")
roomPart.Name = roomType .. "Room"
roomPart.Size = roomSize
roomPart.Anchored = true
roomPart.CanCollide = true
roomPart.Material = Enum.Material.Concrete
roomPart.Position = position
roomPart.Parent = workspace
-- Add room-specific elements
if roomType == "FodderRoom" then
addFodderLoot(roomPart)
elseif roomType == "HallwayRoom" then
addHallwayLoot(roomPart)
elseif roomType == "ImportantRoom" then
addKeycard(roomPart)
elseif roomType == "NestRoom" then
addNestElements(roomPart)
elseif roomType == "DecorationRoom" then
addDecorationElements(roomPart)
end
end
-- Function to add fodder loot to a room
local function addFodderLoot(roomPart)
local lootSpawnLocations = {
roomPart.Position + Vector3.new(math.random(-5, 5), math.random(-5, 5), math.random(-5, 5)),
roomPart.Position + Vector3.new(math.random(-5, 5), math.random(-5, 5), math.random(5, 5)),
roomPart.Position + Vector3.new(math.random(5, 5), math.random(-5, 5), math.random(-5, 5))
}
for _, location in ipairs(lootSpawnLocations) do
local lootPart = Instance.new("Part")
lootPart.Name = "FodderLoot"
lootPart.Size = Vector3.new(2, 1, 2)
lootPart.Anchored = true
lootPart.CanCollide = true
lootPart.Material = Enum.Material.Plastic
lootPart.Position = location
lootPart.Parent = roomPart
end
end
-- Function to add hallway loot to a room
local function addHallwayLoot(roomPart)
local lootSpawnLocations = {
roomPart.Position + Vector3.new(math.random(-5, 5), math.random(-5, 5), math.random(-5, 5)),
roomPart.Position + Vector3.new(math.random(-5, 5), math.random(-5, 5), math.random(5, 5)),
roomPart.Position + Vector3.new(math.random(5, 5), math.random(-5, 5), math.random(-5, 5))
}
for _, location in ipairs(lootSpawnLocations) do
local lootPart = Instance.new("Part")
lootPart.Name = "HallwayLoot"
lootPart.Size = Vector3.new(2, 1, 2)
lootPart.Anchored = true
lootPart.CanCollide = true
lootPart.Material = Enum.Material.Metal
lootPart.Position = location
lootPart.Parent = roomPart
end
end
-- Function to add a keycard to a room
local function addKeycard(roomPart)
local keycardPosition = roomPart.Position + Vector3.new(math.random(-5, 5), math.random(-5, 5), math.random(-5, 5))
local keycard = keycardModel:Clone()
keycard.Name = "Keycard"
keycard.Position = keycardPosition
keycard.Parent = roomPart
end
-- Function to add nest elements to a room
local function addNestElements(roomPart)
-- Add some rocks, debris, etc.
for i = 1, 10 do
local debris = Instance.new("Part")
debris.Name = "NestDebris" .. i
debris.Size = Vector3.new(math.random(1, 3), math.random(1, 3), math.random(1, 3))
debris.Anchored = true
debris.CanCollide = true
debris.Material = Enum.Material.Rock
debris.Position = roomPart.Position + Vector3.new(math.random(-10, 10), math.random(-10, 10), math.random(-10, 10))
debris.Parent = roomPart
end
end
-- Function to add decoration elements to a room
local function addDecorationElements(roomPart)
-- Add some plants, statues, etc.
for i = 1, 5 do
local decoration = Instance.new("Part")
decoration.Name = "Decoration" .. i
decoration.Size = Vector3.new(math.random(1, 3), math.random(1, 3), math.random(1, 3))
decoration.Anchored = true
decoration.CanCollide = false
decoration.Material = Enum.Material.Wood
decoration.Position = roomPart.Position + Vector3.new(math.random(-10, 10), math.random(-10, 10), math.random(-10, 10))
decoration.Parent = roomPart
end
end
-- Function to generate the map
local function generateMap(numRooms)
for i = 1, numRooms do
local roomType = roomTypes[math.random(1, #roomTypes)]
local roomPosition = Vector3.new(math.random(-50, 50), 10, math.random(-50, 50)) -- Adjust Y for floor height
generateRandomRoom(roomType, roomPosition)
end
end
-- Example usage: Generate a map with 10 rooms
generateMap(10)
Explanation:
roomSizes and roomTypes: These tables define the sizes and types of the rooms.
generateRandomRoom(roomType, position): This function takes a room type and a position and creates a new Part for that room. It then calls the appropriate function to add room-specific elements.
addFodderLoot(roomPart), addHallwayLoot(roomPart), addKeycard(roomPart), addNestElements(roomPart), addDecorationElements(roomPart): These functions add the respective elements to the room part at random locations.
generateMap(numRooms): This function iterates numRooms times, randomly selects a room type and position, and then calls generateRandomRoom to create the room.
How to Use:
Create a new script in ServerScriptService and paste this code into it.
Make sure you have a Keycard model in your workspace. You can create a simple part and rename it to "Keycard".
Run the game. This will generate a map with 10 randomly generated rooms. You can adjust the generateMap(10) call to generate more or fewer rooms.
Important Notes:
Room Placement: The roomPosition is currently set to a fixed Y-value. You might need to adjust this to ensure the rooms are at a reasonable height.
Collision: The CanCollide property is set to true for the rooms and loot/keycard parts.
Customization: You can easily add more room types, loot items, or decorations by modifying the respective