Jump to content

Help with mod configuration in prefabs? [SOLVED]


Recommended Posts

I'm back for more help! Concerning my Animal Variety mod, which gives purely cosmetic recolours to some mobs, I need some help with getting mod configuration to work.

Ideally I'd like users to be able to opt in and out of which sets of animal colours they use (eg variety catcoons, but default pigs), but I can't get mod configuration to work from within the prefab files.

I'd also be interested to know if there's any more efficient way of doing what I've done here (giving these prefabs more build options to randomly choose from when generating them).

All the prefab edits are similar to this, names adds for the different builds:

local names = {"frog","frog_2","frog_3","frog_4","frog_5"}

Then called up randomly down in the local function (fn)

inst.AnimState:SetBank("frog")
inst.buildname = names[math.random(#names)]
inst.AnimState:SetBuild(inst.buildname)

Thanks to anyone who can help me out with this!

Animal Variety (DST).rar

Edited by justjasper
Link to comment
Share on other sites

2 hours ago, Aquaterion said:

This should work; I rewrote your whole mod so it doesn't actually modify base files, but does everything in modmain.lua.

Again if you don't understand anything, let me know.

Animal Variety (DST).zip

This is amazing, thank you! I'm going to try and do this with a similar mod of mine (painted pig houses) so I can get the hang of doing it this way. Super helpful (as always), I really dearly appreciate it.

@AquaterionThis'll work as a client-only mod now?

How would I use onsave and onload from modmain? For some of these variants I edited those to keep the colours consistent on save/load.

Edited by justjasper
Link to comment
Share on other sites

something like this, sorry i can't really go in much detail right now as i'm not feeling too well

for animal, builds in pairs(varietyanimals) do
	if toggles[animal] then
		AddPrefabPostInit(animal, function(inst)
			inst.AnimState:SetBuild(builds[math.random(#builds)])
			
			if animal == "rabbit" or animal == "bunnyman" then
				for id, build in pairs(builds) do
					inst.AnimState:SetClientsideBuildOverride("insane", build, insaneanimals[animal])
				end
			end
			
			inst._OnSave = inst.OnSave --get the current save/load functions
			inst._OnLoad = inst.OnLoad --if they exist
			
			inst.OnSave = function(inst, data)
				data.build = blabla
				if inst._OnSave then
					inst._OnSave(inst, data)
				end
			end
		end)
	end
end

 

Link to comment
Share on other sites

17 hours ago, Aquaterion said:

something like this, sorry i can't really go in much detail right now as i'm not feeling too well

I haven't managed to get this working yet, and I've run into a problem that may or may not be related to saving/loading - when spawned via console pigs/pig guards have the different colours, but on reloading they all have only the default skin, and it appears no pigs spawning from houses will use the new colours. None of the other animals have this issue. I'm guessing pigs due to having the werepig aspect are coded in a more complex way, but I can't figure out what code to change in modmain to get them to randomise consistently.

Thanks for all your help so far, and there's no rush, take care of yourself, I hope you're feeling better soon.

Link to comment
Share on other sites

 

 

for animal, builds in pairs(varietyanimals) do
	if toggles[animal] then
		AddPrefabPostInit(animal, function(inst)
			local chosenbuild = builds[math.random(#builds)]
			inst.AnimState:SetBuild(chosenbuild)
			
			if inst.build then
				inst.build = chosenbuild
			end
			
			if animal == "rabbit" or animal == "bunnyman" then
				inst.AnimState:SetClientsideBuildOverride("insane", build, insaneanimals[animal])
			end
			
			inst._OnSave = inst.OnSave --get the current save/load functions
			inst._OnLoad = inst.OnLoad --if they exist
			
			inst.OnSave = function(inst, data)
				data.build = chosenbuild
				if inst._OnSave then
					inst._OnSave(inst, data)
				end
			end
			
			inst.OnLoad = function(inst, data)
				if data and data.build then
					inst.AnimState:SetBuild(data.build)
					if inst.build then
						inst.build = data.build
					end
					if inst.prefab == "rabbit" or inst.prefab == "bunnyman" then
						inst.AnimState:SetClientsideBuildOverride("insane", data.build, insaneanimals[inst.prefab])
					end
				end
				if inst._OnLoad then
					inst._OnLoad(inst, data)
				end
			end
		end)
	end
end

 

Try this

Edited by Aquaterion
Link to comment
Share on other sites

56 minutes ago, Aquaterion said:

Try this

Oh man I wasn't actually far off with the save/load edits I tried using, funnily enough, good to know! 

I had to "for id, build in pairs(builds) do" back in near the first instance of SetClientsideBuildOverride to get it to stop erroring, but it works! 

Thanks a lot, you've been an amazing help.

Edited by justjasper
Link to comment
Share on other sites

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
 Share

×
  • Create New...