Jump to content

Using fertilizer during winter


Recommended Posts

I don't follow.

In the RoG beta branch, anybody can fertilize farms in winter.

I am trying to make my character able to grow plants from farms, in the thick of winter (snowing time)

Normally characters cant, as the farms become inactive, what I want is for this char to be able to use them.

Link to comment
Share on other sites

I looked back at my RoG branch and noticed some things that caused bugs.

You are correct.

 

Now regarding your request.

 

We can take the very long road or the gigantic road.

 

The gigantic road:

local old1 = GLOBAL.ACTIONS.FERTILIZE.fnGLOBAL.ACTIONS.FERTILIZE.fn = function(act)    if act.target.components.crop and not act.target.components.crop:IsReadyForHarvest() and 	act.invobject and act.invobject.components.fertilizer and act.doer.prefab == "wilson" then		local obj = act.doer.components.inventory:RemoveItem(act.invobject)		obj.bypasswinter = true        if act.target.components.crop:Fertilize(obj) then			return true		else			obj.bypasswinter = nil			act.doer.components.inventory:GiveItem(obj)			return false		end	else		return old1(act)	endendAddComponentPostInit("crop", function(self)	local old2 = self.Fertilize	function self:Fertilize(fertilizer)		TheSim:FindEntities(pt.x, pt.y, pt.z, range, must_tags, cant_tags, must_oneoftags)		if fertilizer.bypasswinter then			self.growthpercent = self.growthpercent + fertilizer.components.fertilizer.fertilizervalue * self.rate			self.inst.AnimState:SetPercent("grow", self.growthpercent)			if self.growthpercent >=1 then				self.inst.AnimState:PlayAnimation("grow_pst")				self:Mature()				self.task:Cancel()				self.task = nil			end			fertilizer:Remove()			return true		else			return old2(self, fertilizer)		end	endend)

This does exactly as requested.

 

The long road:

AddComponentPostInit("crop", function(self)	local old = self.Fertilize	function self:Fertilize(fertilizer)		local pt = self.inst:GetPosition()		local ents = GLOBAL.TheSim:FindEntities(pt.x, pt.y, pt.z, 5, {"player", "greenthumb"}, {"playerghost"})		if #ents > 0 then			self.growthpercent = self.growthpercent + fertilizer.components.fertilizer.fertilizervalue * self.rate			self.inst.AnimState:SetPercent("grow", self.growthpercent)			if self.growthpercent >=1 then				self.inst.AnimState:PlayAnimation("grow_pst")				self:Mature()				self.task:Cancel()				self.task = nil			end			fertilizer:Remove()			return true		else			return old(self, fertilizer)		end	endend)-- inst:AddTag("greenthumb") in master_postinit of character

Crops will grow when someone with the greenthumb tag stands very close, so it doesn't matter who really fertilizes, as long as the guy with the perk is there.

Edited by DarkXero
Link to comment
Share on other sites

I looked back at my RoG branch and noticed some things that caused bugs.

You are correct.

 

Now regarding your request.

 

We can take the very long road or the gigantic road.

 

The gigantic road:

local old1 = GLOBAL.ACTIONS.FERTILIZE.fnGLOBAL.ACTIONS.FERTILIZE.fn = function(act)    if act.target.components.crop and not act.target.components.crop:IsReadyForHarvest() and 	act.invobject and act.invobject.components.fertilizer and act.doer.prefab == "wilson" then		local obj = act.doer.components.inventory:RemoveItem(act.invobject)		obj.bypasswinter = true        if act.target.components.crop:Fertilize(obj) then			return true		else			obj.bypasswinter = nil			act.doer.components.inventory:GiveItem(obj)			return false		end	else		return old1(act)	endendAddComponentPostInit("crop", function(self)	local old2 = self.Fertilize	function self:Fertilize(fertilizer)		TheSim:FindEntities(pt.x, pt.y, pt.z, range, must_tags, cant_tags, must_oneoftags)		if fertilizer.bypasswinter then			self.growthpercent = self.growthpercent + fertilizer.components.fertilizer.fertilizervalue * self.rate			self.inst.AnimState:SetPercent("grow", self.growthpercent)			if self.growthpercent >=1 then				self.inst.AnimState:PlayAnimation("grow_pst")				self:Mature()				self.task:Cancel()				self.task = nil			end			fertilizer:Remove()			return true		else			return old2(self, fertilizer)		end	endend)

This does exactly as requested.

 

The long road:

AddComponentPostInit("crop", function(self)	local old = self.Fertilize	function self:Fertilize(fertilizer)		local pt = self.inst:GetPosition()		local ents = GLOBAL.TheSim:FindEntities(pt.x, pt.y, pt.z, 5, {"player", "greenthumb"}, {"playerghost"})		if #ents > 0 then			self.growthpercent = self.growthpercent + fertilizer.components.fertilizer.fertilizervalue * self.rate			self.inst.AnimState:SetPercent("grow", self.growthpercent)			if self.growthpercent >=1 then				self.inst.AnimState:PlayAnimation("grow_pst")				self:Mature()				self.task:Cancel()				self.task = nil			end			fertilizer:Remove()			return true		else			return old(self, fertilizer)		end	endend)-- inst:AddTag("greenthumb") in master_postinit of character

Crops will grow when someone with the greenthumb tag stands very close, so it doesn't matter who really fertilizes, as long as the guy with the perk is there.

 

Thanks a ton! Still familiarizing myself with the games code, so the help is greatly appreciated.

Thnks again :D

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