Jump to content

Is Slow Worker possible?


Recommended Posts

I would like my custom character to chop and mine slower than other characters, in a similar way Woodie can chop trees faster. In Woodie's prefab file, I found this 

local function SetBeaverWorker(inst, enable)
    if enable then
        if inst.components.worker == nil then
            inst:AddComponent("worker")
            inst.components.worker:SetAction(ACTIONS.CHOP, 4)
            inst.components.worker:SetAction(ACTIONS.MINE, .334)
            inst.components.worker:SetAction(ACTIONS.DIG, .334)
            inst.components.worker:SetAction(ACTIONS.HAMMER, .25)
        end
    elseif inst.components.worker ~= nil then
        inst:RemoveComponent("worker")
    end
end

I put a function similar to this in my character's prefab, changed the values, but they have no effect. I even kept the values unchanged, thinking it would make my character chop 4 times faster (that's what i assume those values alter), but there was still no change.

I have a custom item that can chop and mine, and can take half the required swings to finish, so to counter-act I wanted my character to do it half as fast, so it would really balance out. 

Any help would be greatly appreciated!

Edited by Cherryzion
Link to comment
Share on other sites

45 minutes ago, Sudura2017 said:

This activates on becoming the Beaver, it seems. Perhaps you left something like that in?

I didn't copy the entire function over, my function looks like this

local function SlowWorker(inst)
	inst:AddComponent("worker")
	inst.components.worker:SetAction(ACTIONS.CHOP, 4)
	inst.components.worker:SetAction(ACTIONS.MINE, .334)
	inst.components.worker:SetAction(ACTIONS.DIG, .334)
	inst.components.worker:SetAction(ACTIONS.HAMMER, .25)
end

 

Link to comment
Share on other sites

 

1 hour ago, Cherryzion said:

I would like my custom character to chop and mine slower than other characters, in a similar way Woodie can chop trees faster. In Woodie's prefab file, I found this 


local function SetBeaverWorker(inst, enable)
    if enable then
        if inst.components.worker == nil then
            inst:AddComponent("worker")
            inst.components.worker:SetAction(ACTIONS.CHOP, 4)
            inst.components.worker:SetAction(ACTIONS.MINE, .334)
            inst.components.worker:SetAction(ACTIONS.DIG, .334)
            inst.components.worker:SetAction(ACTIONS.HAMMER, .25)
        end
    elseif inst.components.worker ~= nil then
        inst:RemoveComponent("worker")
    end
end

 

That looks to be the amount of times things actually take to mine/chop/dig up, or the amount of "damage" the beaver does to whatever it is gnawing and the code has no relevance to the speed at which Woodie chops wood or that werebeaver chops in terms of animation.

It doesn't seem to me that the woodie's prefab file has the cutting animation for him halved. It might be actually declared for Lucy, although I'm not sure how this makes sense since Woodie chops x2 faster even with using something like a Pick/Axe. But here's the code that I found some-what relevant in lucy.lua that has reference about chopping and has the number "2" for it (it's located at line 184 in the lucy.lua file, "fn" function):

inst:AddComponent("tool")
    inst.components.tool:SetAction(ACTIONS.CHOP, 2)

Hope this helps in some way!

Link to comment
Share on other sites

1 minute ago, EuedeAdodooedoe said:

But here's the code that I found some-what relevant in lucy.lua that has reference about chopping and has the number "2" for it (it's located at line 184 in the lucy.lua file, "fn" function):

I appreciate the help, but already found this code and used it for my item's prefab. This is the code that halves the required swings it takes to finish the tree. So if the number is 2, instead of 15 swings it only takes 8 (it rounds up). 

The code that makes him swing faster must be somewhere else, I'll go digging around to see if I could find something.

Link to comment
Share on other sites

I might have found a lead. Unfortunately, since it's an animation going on, it's in SGWilson where I believe Woodie gets his woodcutting speed, with his tag "woodcutter". It seems if the character has the tag "woodcutter", they initiate a different animation for cutting wood, which is ultimately the same except it has less frames in it, making it faster. 

So if I wanted to make my character chop and mine slower, I'd need to create new states for the character, that would be the same as a regular chopping wood, but has more frames in it, making it longer. If anyone knows how to do this and would be willing to help me, I'd greatly appreciate it!

Here is the code I found in SGWilson

Spoiler

    State{
        name = "chop_start",
        tags = { "prechop", "working" },

        onenter = function(inst)
            inst.components.locomotor:Stop()
            inst.AnimState:PlayAnimation(inst:HasTag("woodcutter") and "woodie_chop_pre" or "chop_pre")
        end,

        events =
        {
            EventHandler("unequip", function(inst) inst.sg:GoToState("idle") end),
            EventHandler("animover", function(inst)
                if inst.AnimState:AnimDone() then
                    inst.sg:GoToState("chop")
                end
            end),
        },
    },

    State{
        name = "chop",
        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")
        end,

        timeline =
        {
            ----------------------------------------------
            --Woodcutter chop

            TimeEvent(2 * FRAMES, function(inst)
                if inst.sg.statemem.iswoodcutter then
                    inst:PerformBufferedAction()
                end
            end),

            TimeEvent(5 * FRAMES, function(inst)
                if inst.sg.statemem.iswoodcutter then
                    inst.sg:RemoveStateTag("prechop")
                end
            end),

            TimeEvent(10 * FRAMES, function(inst)
                if inst.sg.statemem.iswoodcutter and
                    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(12 * FRAMES, function(inst)
                if inst.sg.statemem.iswoodcutter then
                    inst.sg:RemoveStateTag("chopping")
                end
            end),

            ----------------------------------------------
            --Normal chop

            TimeEvent(2 * FRAMES, function(inst)
                if not inst.sg.statemem.iswoodcutter then
                    inst:PerformBufferedAction()
                end
            end),

            TimeEvent(9 * FRAMES, function(inst)
                if not inst.sg.statemem.iswoodcutter then
                    inst.sg:RemoveStateTag("prechop")
                end
            end),

            TimeEvent(14 * FRAMES, function(inst)
                if not inst.sg.statemem.iswoodcutter and
                    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(16 * FRAMES, function(inst)
                if not inst.sg.statemem.iswoodcutter then
                    inst.sg:RemoveStateTag("chopping")
                end
            end),
        },

        events =
        {
            EventHandler("unequip", function(inst) inst.sg:GoToState("idle") end),
            EventHandler("animover", function(inst)
                if inst.AnimState:AnimDone() then
                    --We don't have a chop_pst animation
                    inst.sg:GoToState("idle")
                end
            end),
        },
    },
 

 

Edited by Cherryzion
Link to comment
Share on other sites

My character also has a con to work slower & it works like this

put in YOURCHARACTER.lua inside the master_postinit

inst:ListenForEvent("working", function(inst, data)
	inst.components.playercontroller:Enable(false)
	inst:DoTaskInTime(.25, function() inst.components.playercontroller:Enable(true) end) -- Mess around with ".25" to get desired work speed.
end)

Though, this will not have a "slower" working animations since you'd need to make those from scratch... And I think trying to edit DST animations that Klei makes's not good since, tools, hats, armor & all symbols except the player's body aren't given to you after decompiling with Ktools which means that if you try to edit the chopping anim you'll have to add literally 15+ symbols & reanimate them all over again, including the axe...which sucks a lot.

Hopefully, this will work for you :)!

Edited by SuperDavid
Link to comment
Share on other sites

5 minutes ago, SuperDavid said:

My character also has a con to work slower & it works like this

put in YOURCHARACTER.lua inside the master_postinit


inst:ListenForEvent("working", function(inst, data)
	inst.components.playercontroller:Enable(false)
	inst:DoTaskInTime(.25, function() inst.components.playercontroller:Enable(true) end) -- Mess around with ".25" to get desired work speed.
end)

Though, this will not have a "slower" working animations since you'd need to make those from scratch... And I think trying to edit DST animations that Klei makes's not good since, tools, hats, armor & all symbols except the player's body aren't given to you after decompiling with Ktools which means that if you try to edit the chopping anim you'll have to add literally 15+ symbols & reanimate them all over again, including the axe...which sucks a lot.

Hopefully, this will work for you :)!

Thanks a ton! If this doesn't slow down the working animation though, what does it do?

Link to comment
Share on other sites

8 minutes ago, SuperDavid said:

It causes the player to not be able to do anything for the desired amount of time, which basically can be like "slower" working.

I see! I've tested it out a bit, it works pretty well! All except it's unaffected if you just hold space. It doesn't bother me that much though, thank you!

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