PanAzej Posted April 14, 2016 Share Posted April 14, 2016 -- Make a special action for buff banner local play_buffbanner = State({ name = "play_buffbanner", tags = { "doing", "playing", "busy" }, onenter = function(inst) local equipslots = nil if EQUIPSLOTS["BACK"] then equipslots = EQUIPSLOTS["BACK"] else equipslots = EQUIPSLOTS["BODY"] end local buffbanner = inst.components.inventory:GetEquippedItem(equipslots) inst.components.locomotor:Stop() inst.AnimState:PlayAnimation("action_uniqueitem_pre") inst.AnimState:PushAnimation("horn", false) inst.AnimState:OverrideSymbol("horn01", "buffbannerhorn_pre", "horn01") inst:DoTaskInTime(0.7, function() inst.AnimState:OverrideSymbol("horn01", "buffbannerhorn", "horn01") end) --inst.AnimState:Hide("ARM_carry") inst.AnimState:Show("ARM_normal") if inst.components.inventory.activeitem and inst.components.inventory.activeitem.components.instrument then inst.components.inventory:ReturnActiveItem() end end, timeline = { TimeEvent(21*FRAMES, function(inst) inst.SoundEmitter:PlaySound("tf2soldier/tf2soldier/buffbanner") inst:PerformBufferedAction() end), }, events = { EventHandler("animqueueover", function(inst) if inst.AnimState:AnimDone() then inst.sg:GoToState("idle") end end), }, onexit = function(inst) if inst.components.inventory:GetEquippedItem(EQUIPSLOTS.HANDS) then inst.AnimState:Show("ARM_carry") inst.AnimState:Hide("ARM_normal") end local equipslots = nil if EQUIPSLOTS["BACK"] then equipslots = EQUIPSLOTS["BACK"] else equipslots = EQUIPSLOTS["BODY"] end local buffbanner = inst.components.inventory:GetEquippedItem(equipslots) if buffbanner ~= nil and buffbanner:HasTag("buffbanner") then buffbanner:AddTag("buffdeployed") buffbanner:RemoveTag("buffdeployable") buffbanner:RemoveComponent("instrument") inst.AnimState:ClearOverrideSymbol("swap_body") inst.AnimState:OverrideSymbol("swap_body", "swap_buffbanner_flag", "swap_body") end end, }) local function SGWilsonPostInit(sg) sg.states["play_buffbanner"] = play_buffbanner end AddStategraphState("SGwilson", play_buffbanner) AddStategraphPostInit("wilson", SGWilsonPostInit) local BUFFBANNERING = GLOBAL.Action({ priority= 10 }) BUFFBANNERING.str = "Deploy Banner" BUFFBANNERING.id = "BUFFBANNERING" BUFFBANNERING.fn = function(act) if act.invobject and act.invobject.components.instrument and act.doer and act.doer:HasTag("tf2soldier") then return act.invobject.components.instrument:Play(act.doer) end end AddAction(BUFFBANNERING) local buffbanner_handler = ActionHandler(ACTIONS.BUFFBANNERING, "play_buffbanner") AddStategraphActionHandler("wilson", buffbanner_handler) AddComponentAction("INVENTORY", "instrument", function(inst, doer, actions) if inst:HasTag("buffbanner") and inst:HasTag("buffdeployable") and doer:HasTag("tf2soldier") then table.insert(actions, ACTIONS.BUFFBANNERING) end end) AddStategraphActionHandler("wilson_client", buffbanner_handler) I've made an item with a custom action, but it has problems on clients - apparently client wants to go to an invalid state ("play_buffbanner"). I tried making it work by adding a postinit to wilson_client - animation played but nothing happened after that, item didn't do stuff it was supposed to. I tried adding postinit by overwriting state "play_horn", but that did nothing, so I guess it's not because I added a new state. What am I doing wrong? Any help is greatly appreciated! Link to comment Share on other sites More sharing options...
DarkXero Posted April 15, 2016 Share Posted April 15, 2016 Well 3 hours ago, PanAzej said: animation played but nothing happened after that, item didn't do stuff it was supposed to maybe the issue isn't in the stategraph code? I see you copied the "play_horn" state. wilson goes to that state for the ACTIONS.PLAY action. wilson_client goes to the "play" state. So it should look like this: -- Make a special action for buff banner local play_buffbanner = State({ name = "play_buffbanner", tags = { "doing", "playing", "busy" }, onenter = function(inst) local equipslots = nil if EQUIPSLOTS["BACK"] then equipslots = EQUIPSLOTS["BACK"] else equipslots = EQUIPSLOTS["BODY"] end local buffbanner = inst.components.inventory:GetEquippedItem(equipslots) inst.components.locomotor:Stop() inst.AnimState:PlayAnimation("action_uniqueitem_pre") inst.AnimState:PushAnimation("horn", false) inst.AnimState:OverrideSymbol("horn01", "buffbannerhorn_pre", "horn01") inst:DoTaskInTime(0.7, function() inst.AnimState:OverrideSymbol("horn01", "buffbannerhorn", "horn01") end) --inst.AnimState:Hide("ARM_carry") inst.AnimState:Show("ARM_normal") if inst.components.inventory.activeitem and inst.components.inventory.activeitem.components.instrument then inst.components.inventory:ReturnActiveItem() end end, timeline = { TimeEvent(21*FRAMES, function(inst) inst.SoundEmitter:PlaySound("tf2soldier/tf2soldier/buffbanner") inst:PerformBufferedAction() end), }, events = { EventHandler("animqueueover", function(inst) if inst.AnimState:AnimDone() then inst.sg:GoToState("idle") end end), }, onexit = function(inst) if inst.components.inventory:GetEquippedItem(EQUIPSLOTS.HANDS) then inst.AnimState:Show("ARM_carry") inst.AnimState:Hide("ARM_normal") end local equipslots = nil if EQUIPSLOTS["BACK"] then equipslots = EQUIPSLOTS["BACK"] else equipslots = EQUIPSLOTS["BODY"] end local buffbanner = inst.components.inventory:GetEquippedItem(equipslots) if buffbanner ~= nil and buffbanner:HasTag("buffbanner") then buffbanner:AddTag("buffdeployed") buffbanner:RemoveTag("buffdeployable") buffbanner:RemoveComponent("instrument") inst.AnimState:ClearOverrideSymbol("swap_body") inst.AnimState:OverrideSymbol("swap_body", "swap_buffbanner_flag", "swap_body") end end, }) AddStategraphState("wilson", play_buffbanner) local BUFFBANNERING = GLOBAL.Action({ priority= 10 }) BUFFBANNERING.str = "Deploy Banner" BUFFBANNERING.id = "BUFFBANNERING" BUFFBANNERING.fn = function(act) if act.invobject and act.invobject.components.instrument and act.doer and act.doer:HasTag("tf2soldier") then return act.invobject.components.instrument:Play(act.doer) end end AddAction(BUFFBANNERING) AddComponentAction("INVENTORY", "instrument", function(inst, doer, actions) if inst:HasTag("buffbanner") and inst:HasTag("buffdeployable") and doer:HasTag("tf2soldier") then table.insert(actions, ACTIONS.BUFFBANNERING) end end) local buffbanner_handler = ActionHandler(ACTIONS.BUFFBANNERING, "play_buffbanner") AddStategraphActionHandler("wilson", buffbanner_handler) local buffbanner_handler_client = ActionHandler(ACTIONS.BUFFBANNERING, "play") AddStategraphActionHandler("wilson_client", buffbanner_handler_client) Link to comment Share on other sites More sharing options...
PanAzej Posted April 15, 2016 Author Share Posted April 15, 2016 4 hours ago, DarkXero said: Well maybe the issue isn't in the stategraph code? I see you copied the "play_horn" state. wilson goes to that state for the ACTIONS.PLAY action. wilson_client goes to the "play" state. So it should look like this: -- Make a special action for buff banner local play_buffbanner = State({ name = "play_buffbanner", tags = { "doing", "playing", "busy" }, onenter = function(inst) local equipslots = nil if EQUIPSLOTS["BACK"] then equipslots = EQUIPSLOTS["BACK"] else equipslots = EQUIPSLOTS["BODY"] end local buffbanner = inst.components.inventory:GetEquippedItem(equipslots) inst.components.locomotor:Stop() inst.AnimState:PlayAnimation("action_uniqueitem_pre") inst.AnimState:PushAnimation("horn", false) inst.AnimState:OverrideSymbol("horn01", "buffbannerhorn_pre", "horn01") inst:DoTaskInTime(0.7, function() inst.AnimState:OverrideSymbol("horn01", "buffbannerhorn", "horn01") end) --inst.AnimState:Hide("ARM_carry") inst.AnimState:Show("ARM_normal") if inst.components.inventory.activeitem and inst.components.inventory.activeitem.components.instrument then inst.components.inventory:ReturnActiveItem() end end, timeline = { TimeEvent(21*FRAMES, function(inst) inst.SoundEmitter:PlaySound("tf2soldier/tf2soldier/buffbanner") inst:PerformBufferedAction() end), }, events = { EventHandler("animqueueover", function(inst) if inst.AnimState:AnimDone() then inst.sg:GoToState("idle") end end), }, onexit = function(inst) if inst.components.inventory:GetEquippedItem(EQUIPSLOTS.HANDS) then inst.AnimState:Show("ARM_carry") inst.AnimState:Hide("ARM_normal") end local equipslots = nil if EQUIPSLOTS["BACK"] then equipslots = EQUIPSLOTS["BACK"] else equipslots = EQUIPSLOTS["BODY"] end local buffbanner = inst.components.inventory:GetEquippedItem(equipslots) if buffbanner ~= nil and buffbanner:HasTag("buffbanner") then buffbanner:AddTag("buffdeployed") buffbanner:RemoveTag("buffdeployable") buffbanner:RemoveComponent("instrument") inst.AnimState:ClearOverrideSymbol("swap_body") inst.AnimState:OverrideSymbol("swap_body", "swap_buffbanner_flag", "swap_body") end end, }) AddStategraphState("wilson", play_buffbanner) local BUFFBANNERING = GLOBAL.Action({ priority= 10 }) BUFFBANNERING.str = "Deploy Banner" BUFFBANNERING.id = "BUFFBANNERING" BUFFBANNERING.fn = function(act) if act.invobject and act.invobject.components.instrument and act.doer and act.doer:HasTag("tf2soldier") then return act.invobject.components.instrument:Play(act.doer) end end AddAction(BUFFBANNERING) AddComponentAction("INVENTORY", "instrument", function(inst, doer, actions) if inst:HasTag("buffbanner") and inst:HasTag("buffdeployable") and doer:HasTag("tf2soldier") then table.insert(actions, ACTIONS.BUFFBANNERING) end end) local buffbanner_handler = ActionHandler(ACTIONS.BUFFBANNERING, "play_buffbanner") AddStategraphActionHandler("wilson", buffbanner_handler) local buffbanner_handler_client = ActionHandler(ACTIONS.BUFFBANNERING, "play") AddStategraphActionHandler("wilson_client", buffbanner_handler_client) Thank you very much, it works! Quote maybe the issue isn't in the stategraph code? I was trying to add state play_buffbanner to wilson_client, replacing all component checks with replica checks and whatnot. Everything seemed to work nicely, but the weird thing was, item didn't react at all. So I figured: "maybe client stategraph can't add tags or iterate to anything at all". So I made everything about checking the state serverside, but that didn't work as well... Probably I just screwed something up, I tend to make simple mistakes... Quote I see you copied the "play_horn" state. Yeah, I think that after changing it so much it's just better to make it a new state completely. Thanks once more! I would never figure it out myself... Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now