Jump to content

"armorbroke" Event and State


Recommended Posts

In the Wilson SG, there is a state called armorbroke. In its onenter function, you can find a bit where the code searches through the player's inventory and looks for the same armor to equip. I have a mod that fixes it, so that, if the player doesn't have the exact same armor, the player would instead equip another armor that has the same equipment slot, for example, equipping log suit after thulecite suit runs out. A bit after the terraria updates this fix stopped working. I tried today to completely overwrite the onenter function:

ThePlayer.sg.sg.states.armorbroke.onenter = function(inst, armor) print("armor broke state", inst, armor) end

and saw that, 1) even though the onenter function was completely overwritten, my player is still equipping the next log suit after the previous one broke; also that 2) the onenter function was not getting the "armor" argument it needed. So I tested:

ThePlayer:ListenForEvent("armorbroke", function(inst, data) for k, v in pairs(data) do print(k, v) end end)

and saw that the event was pushed as it should be: data = {armor = armor}. Then I did this:

ThePlayer.sg.sg.states.armorboke = nil 
ThePlayer.sg.sg.events.armorbroke = nil 

And my player was still equipping the next log suit!

Does anyone know anything about this? Why exactly is the onenter function of the state not getting the armor variable, even though the event handler did push it? And did Klei move the equip-the-same-armor code somewhere else for the shield of terror? Am I missing something here?

 

 

 

 

And immediately after posting I find the answer to my own question... I was just one update behind in my copy of the game files, and after unzipping the latest one here is the new state:

    State{
        name = "armorbroke",
        tags = { "busy", "pausepredict" },

        onenter = function(inst)
            ForceStopHeavyLifting(inst)

            inst.AnimState:PlayAnimation("hit")
            inst.SoundEmitter:PlaySound("dontstarve/wilson/use_armour_break")

            if inst.components.playercontroller ~= nil then
                inst.components.playercontroller:RemotePausePrediction()
            end
            inst.sg:SetTimeout(10 * FRAMES)
        end,

        ontimeout = function(inst)
            inst.sg:GoToState("idle", true)
        end,
    },

And in the player common file at line 503:

function fns.ArmorBroke(inst, data)
    if data.armor ~= nil then
        local sameArmor = inst.components.inventory:FindItem(function(item)
            return item.prefab == data.armor.prefab
        end)
        if sameArmor ~= nil then
            inst.components.inventory:Equip(sameArmor)
        end
    end
end

 

Hope this helps you if you're also having trouble with this event.

Edited by Bad Willow
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...