Jump to content

Recommended Posts

I've been creating a mod that adds several entities. My plan was for it to be used for decorations and server administrators, but I think it would be nice if everyone could have them without having to use a command to spawn them because they are completely functional
But I don't know how to make them generate naturally in the world.

You make a modworldgenmain.lua file, and within that file you put something along the lines of this

local require = GLOBAL.require
local AddRoomPreInit = AddRoomPreInit
local GetModConfigData = GetModConfigData

local function GenerateMobForRoom(room, factor)
	AddRoomPreInit(room, function(room)
		if room.contents.distributeprefabs then
			room.contents.distributeprefabs.yourmobprefabname = factor
		end
	end)
end

if GetModConfigData("Your Mob something something") == 1 then
	if GLOBAL.KnownModIndex:IsModEnabled("workshop-1467214795") or GLOBAL.KnownModIndex:IsModForceEnabled("workshop-1467214795") then
	GenerateMobForRoom("MeadowRocky", 0.035)
	GenerateMobForRoom("VolcanoRock", 0.035)	
	GenerateMobForRoom("Rocky", 0.035)
	else
	GenerateMobForRoom("Rocky", 0.035)
	end
end

In this snippet, there's a random workshop ID. That's for Island Adventures. Just in case someone has that mod enabled since it's popular enough to be considered every time you make world gen based mods. The prefab names list are the biomes you want it to generate in. You can list more than one. The numbers next to them is straightforward as to how many you want to spawn in the biome.You can replace the ones here with your own rooms instead of using the ones here. Which can be found in C:\Steam\steamapps\common\Don't Starve Together\data\databundles\scripts.zip\scripts\map\rooms\forest usually.

The GetModconfigData is just the option to turn it on and off just in case people don't want your mob spawning everywhere. You put the toggles and config stuff in your modinfo.lua

  • Thanks 1
On 3/19/2024 at 12:42 AM, Feything said:

You make a modworldgenmain.lua file, and within that file you put something along the lines of this

local require = GLOBAL.require
local AddRoomPreInit = AddRoomPreInit
local GetModConfigData = GetModConfigData

local function GenerateMobForRoom(room, factor)
	AddRoomPreInit(room, function(room)
		if room.contents.distributeprefabs then
			room.contents.distributeprefabs.yourmobprefabname = factor
		end
	end)
end

if GetModConfigData("Your Mob something something") == 1 then
	if GLOBAL.KnownModIndex:IsModEnabled("workshop-1467214795") or GLOBAL.KnownModIndex:IsModForceEnabled("workshop-1467214795") then
	GenerateMobForRoom("MeadowRocky", 0.035)
	GenerateMobForRoom("VolcanoRock", 0.035)	
	GenerateMobForRoom("Rocky", 0.035)
	else
	GenerateMobForRoom("Rocky", 0.035)
	end
end

In this snippet, there's a random workshop ID. That's for Island Adventures. Just in case someone has that mod enabled since it's popular enough to be considered every time you make world gen based mods. The prefab names list are the biomes you want it to generate in. You can list more than one. The numbers next to them is straightforward as to how many you want to spawn in the biome.You can replace the ones here with your own rooms instead of using the ones here. Which can be found in C:\Steam\steamapps\common\Don't Starve Together\data\databundles\scripts.zip\scripts\map\rooms\forest usually.

The GetModconfigData is just the option to turn it on and off just in case people don't want your mob spawning everywhere. You put the toggles and config stuff in your modinfo.lua

Thank you very much, the help was very valuable :wilson_love:

I really appreciate it  Now I can continue with that work.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
  • Create New...