Jump to content

Hyperactive actions


Recommended Posts

Give your character a custom stategraph using stategraphs/SGwilson.lua as a start and change all the relevant actions to "give" which has almost no time.

ActionHandler(ACTIONS.CHOP,
        function(inst)
            if inst:HasTag("beaver") then
                return not inst.sg:HasStateTag("gnawing") and "gnaw" or nil
            end
            return not inst.sg:HasStateTag("prechop")
                and (inst.sg:HasStateTag("chopping") and
                    "chop" or
                    "chop_start")
                or nil
        end),

To

ActionHandler(ACTIONS.CHOP, "give"),

For example.

I don't think it gets any shorter than that.

Link to comment
Share on other sites

I think the OP is thinkingg more like woodie who chop faster? Not to make all the actions almost instantaneous.

The stategraph mod is the action handler with the "give" one is probably a bit too rough ^^

Link to comment
Share on other sites

3 hours ago, ZupaleX said:

I think the OP is thinkingg more like woodie who chop faster? Not to make all the actions almost instantaneous.

The stategraph mod is the action handler with the "give" one is probably a bit too rough ^^

Yeah, I want his actions to be like, x1.5 or x2 faster than normal

Link to comment
Share on other sites

51 minutes ago, ZupaleX said:

Well then a good start would be to look at woodie and his CHOP action :)

I found this

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)
 

But it only seems to kick in when Woodie is a beaver, so it isn't working for my character.

Link to comment
Share on other sites

If you look at the function that does the work, it does the check for tool effectiveness before the check for the worker effectiveness, which is why you can't use it as a player unless you're slapping stuff barehanded.

If your hunch doesn't work out, you could set the tool effectiveness by listening for the "equipped" and "unequipped" events (so you can't just drop the thing after putting it on once and have other people with boosted tools).

function Tool:GetEffectiveness(action)
    return self.actions[action] or 0
end

-- So use something like this in your onequip (this is for an axe, for example)
local function onequipped(inst, data)
  inst.components.tool:SetAction(ACTIONS.CHOP, 2)
end

EDIT: Actually, I think I'm still missing the point, so nevermind me unless I got it right :/

Edited by Yabumi
Link to comment
Share on other sites

Ok let's be more precise

 

from SGWilson.lua

Spoiler

    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),
        },
    }

 

Note how you have 2 section in the timeline. One if the actor has a "iswoodcutter", and one if not. You will notice that the timeline for the actor with "woodcutter" is much faster (after 2, 5 and 10 FRAMES something happens) than the non "woodcutter" (after 2, 9 and 14 FRAMES).

Also the animation played depends on that "woodcutter". If the actor has it, it plays woodie_chop_loop otherwise it plays chop_loop.

The thing is that if you want to mine faster as well or do other stuffs faster you probably don't want to redo all the animations in a faster version.

I think I remember a function from the AnimState userdata which was accelerating the playback but I am not 100% positive.

 

EDIT: I checked out quickly the metatable for AnimState

Spoiler

for k, v in pairs(getmetatable(c_select().AnimState).__index) do print(k) end

[00:01:47]: SetLayer	
[00:01:47]: SetRayTestOnBB	
[00:01:47]: IsCurrentAnimation	
[00:01:47]: SetFinalOffset	
[00:01:47]: SetManualBB	
[00:01:47]: SetHighlightColour	
[00:01:47]: SetOrientation	
[00:01:47]: GetSymbolPosition	
[00:01:47]: ClearSymbolExchanges	
[00:01:47]: Hide	
[00:01:47]: SetSortOrder	
[00:01:47]: ClearOverrideSymbol	
[00:01:47]: BuildHasSymbol	
[00:01:47]: SetBloomEffectHandle	
[00:01:47]: SetDepthWriteEnabled	
[00:01:47]: SetDepthTestEnabled	
[00:01:47]: SetSymbolExchange	
[00:01:47]: AddOverrideBuild	
[00:01:47]: Show	
[00:01:47]: PlayAnimation	
[00:01:47]: SetTime	
[00:01:47]: SetSortWorldOffset	
[00:01:47]: SetClientsideBuildOverride	
[00:01:47]: OverrideItemSkinSymbol	
[00:01:47]: Pause	
[00:01:47]: SetHaunted	
[00:01:47]: SetClientSideBuildOverrideFlag	
[00:01:47]: Resume	
[00:01:47]: FastForward	
[00:01:47]: SetDeltaTimeMultiplier	
[00:01:47]: SetDepthBias	
[00:01:47]: ClearAllOverrideSymbols	
[00:01:47]: SetErosionParams	
[00:01:47]: GetCurrentAnimationTime	
[00:01:47]: ShowSymbol	
[00:01:47]: GetCurrentAnimationLength	
[00:01:47]: GetMultColour	
[00:01:47]: OverrideSymbol	
[00:01:47]: SetPercent	
[00:01:47]: OverrideMultColour	
[00:01:47]: SetAddColour	
[00:01:47]: ClearBloomEffectHandle	
[00:01:47]: SetLightOverride	
[00:01:47]: SetScale	
[00:01:47]: SetBank	
[00:01:47]: SetMultiSymbolExchange	
[00:01:47]: OverrideShade	
[00:01:47]: AssignItemSkins	
[00:01:47]: GetCurrentFacing	
[00:01:47]: SetBuild	
[00:01:47]: ClearOverrideBuild	
[00:01:47]: PushAnimation	
[00:01:47]: GetAddColour	
[00:01:47]: SetSkin	
[00:01:47]: OverrideSkinSymbol	
[00:01:47]: SetMultColour	
[00:01:47]: AnimDone	
[00:01:47]: HideSymbol	

 

You might try the FastForward?

EDIT2:

I did a quick in game test. You can use SetDeltaTimeMultiplier(factor) to increase or decrease the speed of an animation.

You could set that multiplier to your factor upon entering the state ("chop", "mine", etc...) and reset it back to 1 when exiting the state.

Practically it would be

inst.AnimState:SetDeltaTimeMultiplier(2) -- to make it twice faster

[... do your stuffs ...]

inst.AnimState:SetDeltaTimeMultiplier(1) -- to set it back to default value

 

Edited by ZupaleX
Link to comment
Share on other sites

You're going to need to make a edit the states which you want your to be faster in, for example you want your character to preform chopping trees faster you will have to override chop states & add your new thing to check for then it preforms the action faster if it finds a special tag or something.

This is how you would make a custom state, put it in modmain.lua

Spoiler

AddStategraphState("wilson", State{
	name = "your_state",
	tags = { "busy", "canrotate", "pausepredict" },

	onenter = function(inst)
		
	end,
	
	timeline =
	{
	TimeEvent(10, function(inst)
		
	end),
	},
	
	events =
	{
	EventHandler("animover", function(inst)
		if inst.AnimState:AnimDone() then
		
		end
	end),
	},
	
	onexit = function(inst)
		
	end,
})

 

You will want to get states from SGwilson & put them in this state thing then add your own stuff to it, sorry if I didn't explain clearly gl :)!

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