theDarkFey Posted June 4, 2017 Share Posted June 4, 2017 (edited) 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 June 4, 2017 by theDarkFey Link to comment Share on other sites More sharing options...
SlowMaybe Posted June 5, 2017 Share Posted June 5, 2017 (edited) 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 June 5, 2017 by SlowMaybe Link to comment Share on other sites More sharing options...
theDarkFey Posted June 10, 2017 Author Share Posted June 10, 2017 I figured out a way to do it, thank you for the reply Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now