Jump to content

How do i make existing item perishable?


Recommended Posts

Hi

I'm a complete novice at modding.

I want to make the prefab silk perishable which I was able to do by adding this into silk.lua and adding

inst:AddComponent("perishable")
inst.components.perishable:SetPerishTime(TUNING.PERISH_FAST)
inst.components.perishable:StartPerishing()
inst.components.perishable.onperishreplacement = "spoiled_food"

 

Instead of changing each and every script ie silk.lua can i add this code into modmain.lua.  How do i get the instance to refer to the object silk?

 

Link to comment
Share on other sites

local addperish = {
	["silk"]	=	GLOBAL.TUNING.PERISH_FAST	,
	["twigs"]	=	GLOBAL.TUNING.PERISH_SLOW	,
}
for k,v in pairs(addperish) do
	AddPrefabPostInit(k or "",function(inst)
		if inst.components.perishable==nil then
			inst:AddComponent("perishable")
		end
		inst.components.perishable:SetPerishTime(v)
		inst.components.perishable:StartPerishing()
		inst.components.perishable.onperishreplacement = "spoiled_food"
	end)
end

 

Link to comment
Share on other sites

Thank you so much for doing this John. Hopefully I can borrow your expertise for a little longer. I want to adapt your code to include a large list and I'm sure I'll be able to do that. The perish timer will be the same on all items so I won't need to specify each item. My day length is currently set at 16 minutes so I want to try a timer of 20 days first so 320*60 seconds I believe. Can this code be used on armour, weapons? Is the perishable component different/ runs separately to the armour component? Can the code be adapted to delete items instead of leaving rot?

Edited by Berwin
Link to comment
Share on other sites

just keep adding onto this table

local addperish = {
	["e"]		=	GLOBAL.TUNING.PERISH_FAST,
	["laa"]	=	GLOBAL.TUNING.PERISH_FAST,
	["egdf"]	=	GLOBAL.TUNING.PERISH_FAST,
	["cgd"]	=	GLOBAL.TUNING.PERISH_FAST,
	["gds"]	=	GLOBAL.TUNING.PERISH_FAST,
	["aol"]	=	GLOBAL.TUNING.PERISH_FAST,
	["yiftf"]	=	GLOBAL.TUNING.PERISH_FAST,
}

just change the key names into the prefab names intended

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...