Jump to content

Ability activate after animation end


Recommended Posts

Howdy, I'm looking for a bit of assistance with a piece of script. I've created a sorta ability for a custom character that consumes sanity to regenerate health on keypress. I'm hoping to prevent the sanity loss/health regen until AFTER the animation finishes playing. I'm using the build_loop animation and cutting it off at .75sec but the sanity drain/health regen occurs right when I press my ability key. Not really sure how to do the "spoiler" thing to upload the part of the code that's giving me issues, and I don't wanna have a wall of code just sitting here being annoying lol.

Thank you for your time X>

Link to comment
Share on other sites

How would the "animover" function with a looping animation? I'm using "build_loop" animation to show the character is casting the spell. I have a DoTaskInTime() but I don't think it's doing anything to the animation (regardless of the time I use the animation seems to still take about .75/1sec, but without it the animations sometimes try to overlap and the "build_pst" seems to start looping itself for a second or 2) I've been looking at Stategraphs, which seems like what I'll need for this to work properly, but I really don't understand how they function or how to call them up at specific times/places.

local function OnKeyPressed(inst, data)    
    if data.inst == ThePlayer then        
        if data.key == KEY_Z then            
            print("KEY_Z has been pressed.")            
            if TheWorld.ismastersim then                
                if inst.components.sanity:GetPercent() >= 0.33 then
                    --inst.components.playercontroller:Enable(false)
                    inst.components.locomotor:Stop()
                    inst.components.locomotor:Clear()
                    inst.AnimState:PlayAnimation("build_pre")
                    inst:DoTaskInTime(10)
                    inst.AnimState:PushAnimation("build_loop", false)
                    inst.AnimState:PushAnimation("build_pst")
                    inst.AnimState:PushAnimation("idle")
                    inst.components.health:DoDelta(25)
                    inst.components.sanity:DoDelta(-33)
                --end
                else if inst.components.sanity:GetPercent() < 0.33 then
                    --inst.components.playercontroller:Enable(false)
                    if inst.components.talker then
                        inst.components.talker:Say("I don't have the power to do that.")
                    end
                    end
                end
                --inst.components.playercontroller:Enable(true)
            end    
        end
    end
end

Some parts I've tried using had some little effect but I've commented out for the time being, they make me stop and prevent movement but the code seems to finish running before the animation finishes so the "playercontroller:enable()" only prevent me from moving for like .1sec.

Am I correct to assume I need a Stategraph or would it be possible to do it here (character.lua btw)

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