Jump to content

[SOLVED] Need help fixing weird anim glitch


Recommended Posts

Hello, I need help fixing a weird anim glitch.

So, when my character attacks with his fists while insane instead of playing the punch anim he plays the throw anim & that's how I want it to be.

The problem is if you equip a item then attack with your fists while insane the item you last held will show up when you use the throw anim & I don't know how to fix that :(...

Here's gifs they show more of what's the problem.

 

This how it should look like always (but it only is like this when you never equip a item, once you equip a item you have to relog for the item to go away from the anim)

Help 1.gif

This's how the anim becomes after you equip a item (in the example I equipped a nightsword & unequipped it but as you can see it's still in the throw anim...)

Help 2.gif

I would love any help, thank you a lot for reading :D!!!

BTW here's the code that changes my character's punch anim when he goes insane & stuff if anyone needs to edit it to help me.

local function HackState(sg, state)
    local _attack_onenter = sg.states[state]["onenter"]
    sg.states[state]["onenter"] = function(inst)
    _attack_onenter(inst)
    local needs_fix = inst.prefab == "adam" and not inst.replica.inventory:GetEquippedItem(GLOBAL.EQUIPSLOTS.HANDS)
    if needs_fix and inst.replica.sanity:IsSane() then
    inst.sg.statemem.isbeaver = nil
    inst.AnimState:PlayAnimation("punch")
    inst.sg:SetTimeout(24 * GLOBAL.FRAMES)
	elseif needs_fix and not inst.replica.sanity:IsSane() then
    inst.sg.statemem.isbeaver = nil
    inst.AnimState:PlayAnimation("throw")
	inst.sg:SetTimeout(14 * GLOBAL.FRAMES)
    end
    end
end

local function HackAttack(sg)
    HackState(sg, "attack")
    HackState(sg, "dojostleaction")
end

AddStategraphPostInit("wilson", HackAttack)
AddStategraphPostInit("wilson_client", HackAttack)

 

Edited by SuperDavid
Link to comment
Share on other sites

Because unlike armor and backpacks, the game doesn't really have to clear the swap_object symbol.

It just switches the arm shown.

inst:ListenForEvent("unequip", function(inst, data)
	if data and data.eslot == EQUIPSLOTS.HANDS then
		inst.AnimState:ClearOverrideSymbol("swap_object")
	end
end)

Put this in your master_postinit to clear the symbol.

Link to comment
Share on other sites

@DarkXero Sorry to bother you but can I maybe ask how I would do something?

This's the code I need help with

local function HackState(sg, state)
    local _attack_onenter = sg.states[state]["onenter"]
    sg.states[state]["onenter"] = function(inst)
    _attack_onenter(inst)
    local needs_fix = inst.prefab == "adam" and not inst.replica.inventory:GetEquippedItem(GLOBAL.EQUIPSLOTS.HANDS)
    if needs_fix and inst.replica.sanity:IsSane() then
    inst.sg.statemem.isbeaver = nil
    inst.AnimState:PlayAnimation("punch")
    inst.sg:SetTimeout(24 * GLOBAL.FRAMES)
	elseif needs_fix and not inst.replica.sanity:IsSane() then
    inst.sg.statemem.isbeaver = nil
    inst.AnimState:PlayAnimation("throw")
	inst.sg:SetTimeout(14 * GLOBAL.FRAMES)
    end
    end
end

local function HackAttack(sg)
    HackState(sg, "attack")
    HackState(sg, "dojostleaction")
end

AddStategraphPostInit("wilson", HackAttack)
AddStategraphPostInit("wilson_client", HackAttack)

So, what I need help is when my character enters gelid mode I want this

elseif needs_fix and not inst.replica.sanity:IsSane() then
    inst.sg.statemem.isbeaver = nil
    inst.AnimState:PlayAnimation("throw")
	inst.sg:SetTimeout(14 * GLOBAL.FRAMES)

to be replaced with this

elseif needs_fix and not inst.replica.sanity:IsSane() then
    inst.sg.statemem.isbeaver = nil
    inst.AnimState:PlayAnimation("throw")
	inst.sg:SetTimeout(24 * GLOBAL.FRAMES)

I tried doing something like

local function HackState(sg, state)
    local _attack_onenter = sg.states[state]["onenter"]
    sg.states[state]["onenter"] = function(inst)
    _attack_onenter(inst)
    local needs_fix = inst.prefab == "adam" and not inst.replica.inventory:GetEquippedItem(GLOBAL.EQUIPSLOTS.HANDS)
    if needs_fix and inst.replica.sanity:IsSane() then
    inst.sg.statemem.isbeaver = nil
    inst.AnimState:PlayAnimation("punch")
    inst.sg:SetTimeout(24 * GLOBAL.FRAMES)

	elseif needs_fix and not inst.replica.sanity:IsSane() and inst.gelid_mode == nil then
    inst.sg.statemem.isbeaver = nil
    inst.AnimState:PlayAnimation("throw")
	inst.sg:SetTimeout(14 * GLOBAL.FRAMES)

    elseif needs_fix and not inst.replica.sanity:IsSane() and inst.gelid_mode == true then
    inst.sg.statemem.isbeaver = nil
    inst.AnimState:PlayAnimation("throw")
	inst.sg:SetTimeout(24 * GLOBAL.FRAMES)
    end
    end
end

but that didn't work. Could you maybe tell me if this would even be possible or not? Thank you so much DarkXero & you don't need to help if you don't want to :D:D:D ( but I always very much apprciate your help :D)!!!

Link to comment
Share on other sites

local function HackState(sg, state)
    local _attack_onenter = sg.states[state]["onenter"]
    sg.states[state]["onenter"] = function(inst)
		_attack_onenter(inst)
		local needs_fix = inst.prefab == "adam" and not inst.replica.inventory:GetEquippedItem(GLOBAL.EQUIPSLOTS.HANDS)
		if needs_fix and inst.replica.sanity:IsSane() then
			inst.sg.statemem.isbeaver = nil
			inst.AnimState:PlayAnimation("punch")
			inst.sg:SetTimeout(24 * GLOBAL.FRAMES)
		elseif needs_fix and not inst.replica.sanity:IsSane() then
			inst.sg.statemem.isbeaver = nil
			inst.AnimState:PlayAnimation("throw")
			if inst.noactualfreezing:value() then
				inst.sg:SetTimeout(24 * GLOBAL.FRAMES)
			else
				inst.sg:SetTimeout(14 * GLOBAL.FRAMES)
			end
		end
    end
end

local function HackAttack(sg)
    HackState(sg, "attack")
    HackState(sg, "dojostleaction")
end

AddStategraphPostInit("wilson", HackAttack)
AddStategraphPostInit("wilson_client", HackAttack)

Here I make use of the noactualfreezing variable that is networked, and it is true when gelid mode is activated.

You can't just use inst.gelid_mode here, because "wilson_client" makes use of the state, and inst.gelid_mode is nil for clients.

Link to comment
Share on other sites

@DarkXero So sorry to bother you again & again :( but I used this code

local function HackState(sg, state)
    local _attack_onenter = sg.states[state]["onenter"]
    sg.states[state]["onenter"] = function(inst)
	_attack_onenter(inst)
	local needs_fix = inst.prefab == "adam" and not inst.replica.inventory:GetEquippedItem(GLOBAL.EQUIPSLOTS.HANDS)
	if needs_fix and inst.replica.sanity:IsSane() then
	inst.sg.statemem.isbeaver = nil
	inst.AnimState:PlayAnimation("punch")
	inst.sg:SetTimeout(24 * GLOBAL.FRAMES)
	elseif needs_fix and not inst.replica.sanity:IsSane() then
	inst.sg.statemem.isbeaver = nil
	inst.AnimState:PlayAnimation("throw")
	if inst.noactualfreezing:value() then
	inst.sg:SetTimeout(24 * GLOBAL.FRAMES)
	else
	inst.sg:SetTimeout(14 * GLOBAL.FRAMES)
	end
	end
    end
end

And it works fine, kinda. You see when he goes insane he attacks at 14 frames which's good but then when he's insane & turns gelid mode his attack goes 24 frame which's good but when the gelid mode ends his insane attack stays at 24 frames & never goes back to 14 frames :shock:... I'm so, so sorry to ask again for your help but maybe you know why this happens? So sorry for bothering you so much & thanks you so, so, so, so, so much for your help & guidance DarkXero :D:D:D!!!!!!!!!!

Link to comment
Share on other sites

23 minutes ago, DarkXero said:

Are you setting


inst.noactualfreezing:set(false)

after leaving gelid mode (which you should, so your character can freeze properly)?

He..hehe.... oops :shock:...

Thanks so much I completely forgot about that :D....... You're so helpful DarkXero, thank you so much :D!!!!!!

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