Jump to content

[HELP modding] Chop and Mine without item


Recommended Posts

 Recently I've been making yet another character mod and said character is supposed to be able to chop and mine without the need of an ax or pickaxe(character has claws for that task)

 I've been searching around and found something to help, however, it binds to to the digging and hammering and prevents me from using a shovel to dig anything, the code I've been using is the following:

 

For Modmain:

 

local ACTIONS = GLOBAL.ACTIONSlocal myactions = {}myactions[ACTIONS.CHOP] = 5myactions[ACTIONS.MINE] = 3myactions[ACTIONS.HAMMER] = 0myactions[ACTIONS.DIG] = 0local multiact = AddAction("MULTI", "Work", function(act)    if act.target.components.workable then        local action = act.target.components.workable.action        local numworks = myactions[action] or 1        act.target.components.workable:WorkedBy(act.doer, numworks)    end    return trueend)AddStategraphActionHandler("wilson", GLOBAL.ActionHandler(multiact, "multi"))AddStategraphState("wilson", GLOBAL.State {    name = "multi",    tags = {"notalking", "autopredict"},    onenter = function(inst)        inst.sg.statemem.action = inst:GetBufferedAction()        local target = inst.sg.statemem.action and inst.sg.statemem.action.target or nil        inst.components.locomotor:Stop()        inst.AnimState:PlayAnimation("throw")        inst.sg:SetTimeout(cooldown)        if target and target:IsValid() then            inst:FacePoint(target.Transform:GetWorldPosition())        end    end,    timeline = {        GLOBAL.TimeEvent(7 * GLOBAL.FRAMES, function(inst)            inst:PerformBufferedAction()        end),        GLOBAL.TimeEvent(16 * GLOBAL.FRAMES, function(inst)            if inst.components.playercontroller and            inst.components.playercontroller:IsAnyOfControlsPressed(GLOBAL.CONTROL_SECONDARY,            GLOBAL.CONTROL_ACTION, GLOBAL.CONTROL_CONTROLLER_ALTACTION) and            inst.sg.statemem.action and inst.sg.statemem.action.target and            inst.sg.statemem.action.target.components.workable and            inst.sg.statemem.action.target.components.workable.workleft > 0 then                inst:PushBufferedAction(inst.sg.statemem.action)            end        end),    },    events = {        GLOBAL.EventHandler("animover", function(inst)            if inst.AnimState:AnimDone() then                inst.sg:GoToState("idle", true)            end        end),    },})

for the prefab:

inst:DoTaskInTime(0, function()    inst.components.playeractionpicker.rightclickoverride = function(inst, target, position)        local actions = {}        if target and target.components.workable and target.components.workable.workable then            local inv = inst.components.inventory            if inv and not inv:GetEquippedItem(EQUIPSLOTS.HANDS) then                table.insert(actions, ACTIONS.MULTI)            end        end        return inst.components.playeractionpicker:SortActionList(actions, target)    endend)

Can someone give me a hand on how to fix this dig and hammering issue?

 

Link to comment
Share on other sites

@halfrose, modmain:

local ACTIONS = GLOBAL.ACTIONSlocal myactions = {}myactions[ACTIONS.CHOP] = 5myactions[ACTIONS.MINE] = 3local multiact = AddAction("MULTI", "Work", function(act)	if act.target.components.workable then		local action = act.target.components.workable.action		local numworks = myactions[action] or 1		act.target.components.workable:WorkedBy(act.doer, numworks)	end	return trueend)multiact.rmb = trueAddStategraphActionHandler("wilson", GLOBAL.ActionHandler(multiact, "multi"))AddStategraphState("wilson", GLOBAL.State {    name = "multi",    tags = {"notalking", "autopredict"},    onenter = function(inst)        inst.sg.statemem.action = inst:GetBufferedAction()        local target = inst.sg.statemem.action and inst.sg.statemem.action.target or nil        inst.components.locomotor:Stop()        inst.AnimState:PlayAnimation("throw")        inst.sg:SetTimeout(cooldown)        if target and target:IsValid() then            inst:FacePoint(target.Transform:GetWorldPosition())        end    end,    timeline = {        GLOBAL.TimeEvent(7 * GLOBAL.FRAMES, function(inst)            inst:PerformBufferedAction()        end),        GLOBAL.TimeEvent(16 * GLOBAL.FRAMES, function(inst)            if inst.components.playercontroller and            inst.components.playercontroller:IsAnyOfControlsPressed(GLOBAL.CONTROL_SECONDARY,            GLOBAL.CONTROL_ACTION, GLOBAL.CONTROL_CONTROLLER_ALTACTION) and            inst.sg.statemem.action and inst.sg.statemem.action.target and            inst.sg.statemem.action.target.components.workable and            inst.sg.statemem.action.target.components.workable.workleft > 0 then                inst:PushBufferedAction(inst.sg.statemem.action)            end        end),    },    events = {        GLOBAL.EventHandler("animover", function(inst)            if inst.AnimState:AnimDone() then                inst.sg:GoToState("idle", true)            end        end),    },})--- --- ---local function multiRightActions(inst, target, position)	if target and (target:HasTag("CHOP_workable") or target:HasTag("MINE_workable")) then -- use tags or replicas, not components		return inst.components.playeractionpicker:SortActionList({ ACTIONS.MULTI }, target) -- hosts and clients have playeractionpicker component	end	return nil, true -- this true enables the old right actionsendAddComponentPostInit("playeractionpicker", function(self)	if self.inst:HasTag("multitasker") then		self.rightclickoverride = multiRightActions	endend)

And put

inst:AddTag("multitasker")

in common_postinit.

 

 

Also, the inst:DoTaskInTime you have there is not needed.

Edited by DarkXero
Link to comment
Share on other sites

@halfrose, modmain:

local ACTIONS = GLOBAL.ACTIONSlocal myactions = {}myactions[ACTIONS.CHOP] = 5myactions[ACTIONS.MINE] = 3local multiact = AddAction("MULTI", "Work", function(act)	if act.target.components.workable then		local action = act.target.components.workable.action		local numworks = myactions[action] or 1		act.target.components.workable:WorkedBy(act.doer, numworks)	end	return trueend)multiact.rmb = trueAddStategraphActionHandler("wilson", GLOBAL.ActionHandler(multiact, "multi"))AddStategraphState("wilson", GLOBAL.State {    name = "multi",    tags = {"notalking", "autopredict"},    onenter = function(inst)        inst.sg.statemem.action = inst:GetBufferedAction()        local target = inst.sg.statemem.action and inst.sg.statemem.action.target or nil        inst.components.locomotor:Stop()        inst.AnimState:PlayAnimation("throw")        inst.sg:SetTimeout(cooldown)        if target and target:IsValid() then            inst:FacePoint(target.Transform:GetWorldPosition())        end    end,    timeline = {        GLOBAL.TimeEvent(7 * GLOBAL.FRAMES, function(inst)            inst:PerformBufferedAction()        end),        GLOBAL.TimeEvent(16 * GLOBAL.FRAMES, function(inst)            if inst.components.playercontroller and            inst.components.playercontroller:IsAnyOfControlsPressed(GLOBAL.CONTROL_SECONDARY,            GLOBAL.CONTROL_ACTION, GLOBAL.CONTROL_CONTROLLER_ALTACTION) and            inst.sg.statemem.action and inst.sg.statemem.action.target and            inst.sg.statemem.action.target.components.workable and            inst.sg.statemem.action.target.components.workable.workleft > 0 then                inst:PushBufferedAction(inst.sg.statemem.action)            end        end),    },    events = {        GLOBAL.EventHandler("animover", function(inst)            if inst.AnimState:AnimDone() then                inst.sg:GoToState("idle", true)            end        end),    },})--- --- ---local function multiRightActions(inst, target, position)	if target and (target:HasTag("CHOP_workable") or target:HasTag("MINE_workable")) then -- use tags or replicas, not components		return inst.components.playeractionpicker:SortActionList({ ACTIONS.MULTI }, target) -- hosts and clients have playeractionpicker component	end	return nil, true -- this true enables the old right actionsendAddComponentPostInit("playeractionpicker", function(self)	if self.inst:HasTag("multitasker") then		self.rightclickoverride = multiRightActions	endend)

And put

inst:AddTag("multitasker")

in common_postinit.

 

 

Also, the inst:DoTaskInTime you have there is not needed.

 

oh thanks so much! it is now working fine! really, thanks!

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