Wonderlarr Posted May 18, 2021 Share Posted May 18, 2021 I need to extend time values for basically every stategraph in the game, and I really DON'T feel like rewriting every Stategraph, so I'm wondering if I can somehow change constants for a specific prefab, or run their stategraphs at double speed somehow. Not sure if this is possible, it's really remote. Alternatively, if someone can figure out how to slow down an entire prefab more easily, I would love to know how you'd do that. Link to comment https://forums.kleientertainment.com/forums/topic/130075-can-i-temporarily-change-a-constant-for-a-specific-prefab/ Share on other sites More sharing options...
Gleenus Posted May 18, 2021 Share Posted May 18, 2021 3 hours ago, TheSkylarr said: I need to extend time values for basically every stategraph in the game, and I really DON'T feel like rewriting every Stategraph, so I'm wondering if I can somehow change constants for a specific prefab, or run their stategraphs at double speed somehow. Not sure if this is possible, it's really remote. Alternatively, if someone can figure out how to slow down an entire prefab more easily, I would love to know how you'd do that. In my Enerlectrics project, I wanted to make an enerlectric axe that cut tree fast as Woodie The only way I found to do this was: "store the onenter function of the state" "create a new onenter function" "in this new onenter function, if the new axe is equipped, go to my custom state" "else, return the original state" I know this work fine BUT I see in some codes people using debug functions to change local variables It is weird, I don't know exactly how it work, but it work If you look in your mod folder, usually the functions to do that are called "getval" and "setval" They use the debug functions "debug.getupvalue" and "debug.setupvalue" The mod ("workshop-2187646441") uses that to apply custom colour cubes Link to comment https://forums.kleientertainment.com/forums/topic/130075-can-i-temporarily-change-a-constant-for-a-specific-prefab/#findComment-1461476 Share on other sites More sharing options...
Wonderlarr Posted May 18, 2021 Author Share Posted May 18, 2021 6 hours ago, Gleenus said: In my Enerlectrics project, I wanted to make an enerlectric axe that cut tree fast as Woodie The only way I found to do this was: "store the onenter function of the state" "create a new onenter function" "in this new onenter function, if the new axe is equipped, go to my custom state" "else, return the original state" I know this work fine BUT I see in some codes people using debug functions to change local variables It is weird, I don't know exactly how it work, but it work If you look in your mod folder, usually the functions to do that are called "getval" and "setval" They use the debug functions "debug.getupvalue" and "debug.setupvalue" The mod ("workshop-2187646441") uses that to apply custom colour cubes Here's the weird thing, in my case I'm trying to replace a global variable in a stategraph, FRAMES, do you think it would work for that? I can't test it myself right this second sadly or I would just go for it. Link to comment https://forums.kleientertainment.com/forums/topic/130075-can-i-temporarily-change-a-constant-for-a-specific-prefab/#findComment-1461542 Share on other sites More sharing options...
Gleenus Posted May 18, 2021 Share Posted May 18, 2021 (edited) 2 hours ago, TheSkylarr said: Here's the weird thing, in my case I'm trying to replace a global variable in a stategraph, FRAMES, do you think it would work for that? I can't test it myself right this second sadly or I would just go for it. I think not You need to route the stategraph to a custom one I can show how I did it if you want, just pm-me @edit Or I can show here later Edited May 18, 2021 by Gleenus 1 Link to comment https://forums.kleientertainment.com/forums/topic/130075-can-i-temporarily-change-a-constant-for-a-specific-prefab/#findComment-1461593 Share on other sites More sharing options...
Gleenus Posted May 18, 2021 Share Posted May 18, 2021 Here is my code to make a very fast axe (similar to Woodie, but a bit faster) local chop_saw=State{ name = "chop_saw", tags = { "prechop", "chopping", "working" }, onenter = function(inst) inst.sg.statemem.action = inst:GetBufferedAction() inst.sg.statemem.iswoodcutter = inst:HasTag("woodcutter") inst.AnimState:PlayAnimation(inst.sg.statemem.iswoodcutter and "woodie_chop_loop" or "chop_loop") inst.SoundEmitter:PlaySound("dontstarve/wilson/hit_metal") end, timeline = { TimeEvent(2 * FRAMES, function(inst) inst:PerformBufferedAction() end), TimeEvent(4 * FRAMES, function(inst) inst.sg:RemoveStateTag("prechop") end), TimeEvent(6 * FRAMES, function(inst) if inst.components.playercontroller ~= nil and inst.components.playercontroller:IsAnyOfControlsPressed( CONTROL_PRIMARY, CONTROL_ACTION, CONTROL_CONTROLLER_ACTION) and inst.sg.statemem.action ~= nil and inst.sg.statemem.action:IsValid() and inst.sg.statemem.action.target ~= nil and inst.sg.statemem.action.target.components.workable ~= nil and inst.sg.statemem.action.target.components.workable:CanBeWorked() and inst.sg.statemem.action.target:IsActionValid(inst.sg.statemem.action.action) and CanEntitySeeTarget(inst, inst.sg.statemem.action.target) then inst:ClearBufferedAction() inst:PushBufferedAction(inst.sg.statemem.action) end end), TimeEvent(8 * FRAMES, function(inst) inst.sg:RemoveStateTag("chopping") end), }, } AddStategraphPostInit("wilson",function(sg) sg.old_states_chop_onenter = sg.states.chop.onenter sg.states.chop.onenter = function(inst) if inst.components.inventory and inst.components.inventory and inst.components.inventory.equipslots['hands'] and inst.components.inventory.equipslots['hands']:HasTag("ee_saw") then inst.sg:GoToState("chop_saw") return else return sg.old_states_chop_onenter(inst) end end end) AddStategraphState("wilson",chop_saw) You will probably need to set some "GLOBAL" before some functions In my code I set the state in a secondary file, that is why I didn't need it Link to comment https://forums.kleientertainment.com/forums/topic/130075-can-i-temporarily-change-a-constant-for-a-specific-prefab/#findComment-1461642 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