Jump to content

Recommended Posts

I'm aware that a character can be given the ability to dig without a tool, but it seems the code may be flawed?  It requires two "digs" to uproot a simple stump, and clearing farm tiles is less reliable.  I've tried updating the code in a few ways, but haven't had any luck.  Perhaps there's an easier way to do this or I'm overlooking an obvious typo?

DIG = Action({ rmb=true, invalid_hold_action=true }),
ACTIONS.DIG.fn = function(act)
    DoToolWork(act, ACTIONS.DIG)
    return true
end

ACTIONS.DIG.validfn = function(act)
    return ValidToolWork(act, ACTIONS.DIG)
end

ACTIONS.DIG.theme_music_fn = function(act)
    return act.target ~= nil
        and (act.target:HasTag("farm_debris") or act.target:HasTag("farm_plant")) and "farming"
		or nil
end


I'd also like to find a way for a character to till soil without a tool.  Since the "Till" action seems to immediately reference the player's inventory, I'm trying to figure out how to get around that.

ACTIONS.TILL.fn = function(act)
    if act.invobject ~= nil then
		if act.invobject.components.farmtiller ~= nil then
			return act.invobject.components.farmtiller:Till(act:GetActionPoint(), act.doer)
		elseif act.invobject.components.quagmire_tiller ~= nil then --Quagmire
        return act.invobject.components.quagmire_tiller:Till(act:GetActionPoint(), act.doer)
    end
end
end
local FarmTiller = Class(function(self, inst)
    self.inst = inst
end)

function FarmTiller:Till(pt, doer)
    if TheWorld.Map:CanTillSoilAtPoint(pt.x, 0, pt.z, false) then
		TheWorld.Map:CollapseSoilAtPoint(pt.x, 0, pt.z)
        SpawnPrefab("farm_soil").Transform:SetPosition(pt:Get())

		if doer ~= nil then
			doer:PushEvent("tilling")
		end
        return true
    end
    return false
end

return FarmTiller


Any help would be immensely appreciated.

4 minutes ago, Rickzzs said:

You  can see woodie's wereforms(pointspecialaction) and till(inherentaction), or just add a common componentaction via an empty component from the player.

Thanks.  I'll review Woodie's wereform code, but it's funny you mention inherent action.  I tried that, but maybe I mistyped it?  How would you have typed it?

inst:AddInherentAction(ACTIONS.TILL)

inst:AddComponent("farmtiller")

 

10 hours ago, Rickzzs said:

oh, inherentaction is excluded from self(the item must not be self). You can see all details in playeractionpicker.lua

Well that's too bad..  Seems like a lot of the code's working against me.  The actual code that seems to till doesn't seem so bad, but I think I need to make a new action that uses CanTillSoillAgPoint function, or would that also fail?  Ive only coded a few actions before, so it's not my forte.

Here's my current attempt, but I haven't had time to test it yet.  I worry I've gotten something wrong with the till related code, and the digging code seems to require two "digs" per stump.  No idea how/why that is.

local ActionHandler = GLOBAL.ActionHandler
local ACTIONS = GLOBAL.ACTIONS

local MYDIGACTION = AddAction("HARVESTDIG", "Dig", ACTIONS.DIG.fn)

local harvestdighandler = ActionHandler(MYDIGACTION, "dolongaction")
AddStategraphActionHandler("wilson", harvestdighandler)
AddStategraphActionHandler("wilson_client", harvestdighandler)

AddComponentPostInit("playeractionpicker", function(self)
	if self.inst:HasTag("able_to_dig") then
		local LEAPACTION = ACTIONS.LEAP
		local DIGID = ACTIONS.DIG.id
		local _GetRightClickActions = self.GetRightClickActions
		self.GetRightClickActions = function(self, position, target)
			local actions = _GetRightClickActions(self, position, target)
			local iscrazyandalive = not self.inst.replica.sanity:IsSane() and not self.inst:HasTag("playerghost")
			if iscrazyandalive then
				if #actions == 0 and position then
					local ishungry = self.inst.replica.hunger:GetCurrent() < 10
					local ispassable = self.map:IsPassableAtPoint(position:Get())
					if ispassable and not ishungry then
						actions = self:SortActionList({LEAPACTION}, position)
					end
				elseif target then
					if target:HasTag(DIGID.."_workable") then
						actions = self:SortActionList({MYDIGACTION}, target)

					local pt = self.inst:GetActionPoint()
					local doer = self.inst

					elseif TheWorld.Map:CanTillSoilAtPoint(pt.x, 0, pt.z, false) then
						TheWorld.Map:CollapseSoilAtPoint(pt.x, 0, pt.z)
						SpawnPrefab("farm_soil").Transform:SetPosition(pt:Get())

						if doer ~= nil then
							doer:PushEvent("tilling")
						end
						return true

					end
				end
			end
			return actions
		end
	end
end)

 

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
×
  • Create New...