Jump to content

Recommended Posts

I've made a follower creature that can be also picked up to inventory.

The problem is, it's annoying when character picks up items using [spacebar] and the creature gets picked up as well.

How to make it so an item (creature) can be picked up only with mouse-click?

Butterflies and fireflies set inst.components.inventoryitem.canbepickedup = false and make themselves the target of an action with a net with workable component. However, PlayerController:GetActionButtonAction() (together with GetPickupAction(); both in components/playercontroller.lua) makes using tools on spacebar possible as well. I guess custom mod action (that imitates pickup action) could solve that.

Here's what I did, but it doesn't work. What am I missing? I haven't made custom actions for this game yet, so I have no idea what's wrong.

local ATTYLAPICK = GLOBAL.Action({ priority=1 })	
ATTYLAPICK.str = "Pick Up"
ATTYLAPICK.id = "ATTYLAPICK"
ATTYLAPICK.fn = function(act)
	if act.doer.components.inventory ~= nil and
        act.target ~= nil and
        act.target.components.inventoryitem ~= nil and
		act.target:HasTag("attyla") then

        act.doer:PushEvent("onpickupitem", { item = act.target })
        return true
    end
end
AddAction(ATTYLAPICK)

local attyla_pickhandler = ActionHandler(ACTIONS.ATTYLAPICK, "doshortaction")
AddStategraphActionHandler("wilson", attyla_pickhandler)

Also, I've trying to set creature's canbepickedup to false - didn't work. I can only examine it.

Leaving canbepickedup as true and setting ATTYLAPICK to higher priority didn't work either - PICKUP still is used over my action, so...

Obviously I'm doing something wrong here. Maybe there's some smart person that can help me.

Edited by PanAzej

Try adding (based on componentactions.lua/SCENE/inventoryitem)

AddComponentAction("SCENE", "inventoryitem", function(inst, doer, actions, right)
    if inst.replica.inventoryitem:CanBePickedUp() and doer.replica.inventory ~= nil and 
        not (inst:HasTag("catchable") or inst:HasTag("fire")) and inst:HasTag("attyla") then
        table.insert(actions, ACTIONS.ATTYLAPICK)
    end
end)
AddStategraphActionHandler("wilson_client", attyla_pickhandler)

Also see (Component Actions part):

 

Edited by Muche
1 hour ago, Muche said:

Try adding (based on componentactions.lua/SCENE/inventoryitem)


AddComponentAction("SCENE", "inventoryitem", function(inst, doer, actions, right)
    if inst.replica.inventoryitem:CanBePickedUp() and doer.replica.inventory ~= nil and 
        not (inst:HasTag("catchable") or inst:HasTag("fire")) and inst:HasTag("attyla") then
        table.insert(actions, ACTIONS.ATTYLAPICK)
    end
end)
AddStategraphActionHandler("wilson_client", attyla_pickhandler)

Also see (Component Actions part):

Thank you very much! I still had to fix something, but it works perfectly now! :D

I've set canbepickedup to false, so ATTYLAPICK and PICKUP don't overlap.

Here's the final code (just in case somebody somewhere sometime would have the same problem as me):

local ATTYLAPICK = GLOBAL.Action({ priority=1 })	
ATTYLAPICK.str = "Pick up"
ATTYLAPICK.id = "ATTYLAPICK"
ATTYLAPICK.fn = function(act)
	if act.doer.components.inventory ~= nil and
        act.target ~= nil and
        act.target.components.inventoryitem ~= nil and
		act.target:HasTag("attyla") then

        act.doer:PushEvent("onpickupitem", { item = act.target })
		act.doer.components.inventory:GiveItem(act.target, nil, act.target:GetPosition())
        return true
    end
end
AddAction(ATTYLAPICK)

local attyla_pickhandler = ActionHandler(ACTIONS.ATTYLAPICK, "doshortaction")
AddStategraphActionHandler("wilson", attyla_pickhandler)

AddComponentAction("SCENE", "inventoryitem", function(inst, doer, actions, right)
    if doer.replica.inventory ~= nil and inst:HasTag("attyla") and not inst:HasTag("fire") then
        table.insert(actions, ACTIONS.ATTYLAPICK)
    end
end)
AddStategraphActionHandler("wilson_client", attyla_pickhandler)

 

Edited by PanAzej

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