Jump to content

Making Items Uncraftable Based on Sanity, etc?


Recommended Posts

Hello! I'm pretty new to modding, and was wondering if it's possible to make items uncraftable when sanity is below a certain threshold? Later I would like to translate that to "dark energy" which is a custom meter that I made for my character.

The code I've been fiddling around with: 

 

inst:DoPeriodicTask(5, function()
		local old = inst.replica.builder.CanLearn
		local de = inst.components.darkenergy:GetPercent()
		function inst.replica.builder:CanLearn(recname)
	
		if forbidden1 [recname] and de < .40  then
			return false
		elseif forbidden2 [recname] and de < .30 then 
			return false
		elseif forbidden3 [recname] and de >=.40 then
			return old(self,recname)
		else 
			return old(self,recname)
		
		end
	
		end
	end)

I've gotten it to work where once de (dark energy) gets below 30, the recipes disappear, but I have issues with the recipes reappearing once de increases above 40. 

Any help/tips would be greatly appreciated!!

Edit: I think I realized why the recipe won't reappear: they are taken out of the game until restart. Is there a way to lock recipes instead of taking them out completely?

Edited by theDarkFey
Link to comment
Share on other sites

I'm not familiar with the mod environment but you should need to overwrite CanLearn only once. Check the dark energy inside CanLearn and not outside.

local oldCanLearn = inst.replica.builder.CanLearn
inst.replica.builder.CanLearn = function(recname)
	local de = self.inst.components.darkenergy:GetPercent()
	if forbidden1 [recname] and de < .40  then
		return false
	elseif forbidden2 [recname] and de < .30 then 
		return false
	elseif forbidden3 [recname] and de >=.40 then
		return oldCanLearn(self,recname)
	else 
		return oldCanLearn(self,recname)		
end

 

Edited by SlowMaybe
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...