Jump to content

Help Adding Science Value to an Object


Recommended Posts

Say i want to add a Science value to a book, so it unlocks all the tier 1 science recipes, another book that adds the tier 2 science recipes and a third that adds ancient science (Pseudoscience) recipes, with just having the books in your inventory, How could it be done ? I need help with this since is to fix an outdated mod of mine.

Link to comment
Share on other sites

Remove these lines in your gfbooks (1,2,3) prefabs:

inst.components.inventoryitem:SetOnDroppedFn(OnDropped)
inst.components.inventoryitem:SetOnPutInInventoryFn(OnPickup)

And add these lines to your modmain.lua:

local function NewBuilder(self)
	local _EvaluateTechTrees = self.EvaluateTechTrees
	self.EvaluateTechTrees = function(self)
		_EvaluateTechTrees(self)
		if self.inst.replica.inventory then 
			local changed = false
			if self.inst.replica.inventory:Has("gfbook2", 1) and self.accessible_tech_trees.SCIENCE < 2 then
				self.accessible_tech_trees.SCIENCE = 2
				changed = true	
			elseif self.inst.replica.inventory:Has("gfbook1", 1) and self.accessible_tech_trees.SCIENCE < 1 then
				self.accessible_tech_trees.SCIENCE = 1
				changed = true	
			end	
		
			if self.inst.replica.inventory:Has("gfbook3", 1) and self.accessible_tech_trees.ANCIENT < 4 then
				self.accessible_tech_trees.ANCIENT = 4
				changed = true
			end
		
			if changed then
				self.inst:PushEvent("techtreechange", { level = self.accessible_tech_trees })
				self.inst.replica.builder:SetTechTrees(self.accessible_tech_trees)
			end
		end
	end
end	
	
AddComponentPostInit("builder", NewBuilder)

 

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