Jump to content

Trade/Give action timing out

Recommended Posts

Basically what I'm trying to do is a copy of the GIVE action.


I'm trying to make a tree to be able to trade items with the player (logs for living logs).


... But, I've run into a issue. The buffered action keeps timing out in the client side. It works without issues for the host, but when a client tries to do the action it gets stuck from the stategraph and just times out.


Here's my code:

...AddAction("TREETRADE", "Give", function(act)    print("[TREETRADE]:", act.doer and act.doer.name, "is trying to trade with ", act.target and act.target.name)	if act.target ~= nil and act.target.components.treetrader ~= nil then        print("[TREETRADE]: Starting trade...")        act.target.components.treetrader:AcceptGift(act.doer, act.invobject)        return true    endend)	function SetupTreeTradeActions(inst, doer, target, actions)    if target:HasTag("treetrader") and not target:HasTag("player") then        table.insert(actions, GLOBAL.ACTIONS.TREETRADE)    endendAddComponentAction("USEITEM", "treetradable", SetupTreeTradeActions)AddPrefabPostInit("log", function (inst)    inst:AddComponent("treetradable")end)...local tree_trade_action_handler = GLOBAL.ActionHandler( GLOBAL.ACTIONS.TREETRADE, "give" )AddStategraphActionHandler("wilson", tree_trade_action_handler)AddStategraphActionHandler("wilson_client", tree_trade_action_handler)

It never reaches the TREETRADE action from the client side.


The component treetrader is basically just a copy of trader, adding a treetrader tag instead of trader. Same goes for treetredable, it's pretty of a copy of tradable.


"Why not just use the standard tradable component". Because everything meat related has the option to be given to the tree in that way.. and that is kind of weird.


I was somewhat able to trace back the BufferedAction all the way back to playercontroller using a dummy state identical in functionality to "give" like so:

local tree_trade_state_client = State({    name = "tree_trade",    tags = { "giving" },        onenter = function(inst)        print("[STATEGRAPH_CLIENT]: Entering state...")        inst.components.locomotor:Stop()        if not inst:HasTag("giving") then            inst.AnimState:PlayAnimation("give")        end        print("[STATEGRAPH_CLIENT]: Performing preview buffered action...")        inst:PerformPreviewBufferedAction()        inst.sg:SetTimeout(2)    end,    onupdate = function(inst)        print("[STATEGRAPH_CLIENT]: Updating...")        if inst:HasTag("giving") then            if inst.entity:FlattenMovementPrediction() then                inst.sg:GoToState("idle", "noanim")            end        elseif inst.bufferedaction == nil then            print("[STATEGRAPH_CLIENT]: Success! Clearing buffered action. Returning to idle.")            inst.AnimState:PlayAnimation("give_pst")            inst.sg:GoToState("idle", true)        end    end,    ontimeout = function(inst)        print("[STATEGRAPH_CLIENT]: Error. Time out. Exiting...")        inst:ClearBufferedAction()        inst.AnimState:PlayAnimation("give_pst")        inst.sg:GoToState("idle", true)    end})

.. but I kinda got lost in the way there.


So, the client gets stuck trying to do the PerformPreviewBufferedAction, how can I prevent this? Am I missing something?

Link to comment
Share on other sites

Still haven't been able to figure it out.


For now I'll just hook into the already existing GIVE like so:

GLOBAL.ACTIONS.GIVE.oldfn = GLOBAL.ACTIONS.GIVE.fnGLOBAL.ACTIONS.GIVE.fn = function(act)    if act.target and act.target.components.treetrader ~= nil then        return act.target.components.treetrader:AcceptGift( act.doer, act.invobject )    else        return GLOBAL.ACTIONS.GIVE.oldfn(act)    endendAddComponentAction("USEITEM", "treetradable", function(inst, doer, target, actions)    if target:HasTag("treetrader") and not target:HasTag("player") then        table.insert(actions, GLOBAL.ACTIONS.GIVE)    endend)

Works pretty well, but I still kind of want to know why my GIVE copycat won't work. I mean, other custom actions work well. Does the fact I'm trying to implement more than one action could be affecting it? I have two AddAction calls in my modmain. I don't think so, but still..

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

  • Create New...