Jump to content

Recommended Posts

I have been trying to make one of my custom items from the mod that i am currently working on, play wigfrids sing animation when using it, but whatever i do it keeps not working, if any one could help me make the animation work on use that would be great!

This is the code that i currently have :

 

local function SetPocketRummageMem(inst, item)
    inst.sg.mem.pocket_rummage_item = item
end

local function OwnsPocketRummageContainer(inst, item)
    local owner = item.components.inventoryitem and item.components.inventoryitem:GetGrandOwner() or nil
    if owner == inst then
        return true
    end
    local mount = inst.components.rider and inst.components.rider:GetMount() or nil
    if owner == mount or item == mount then
        return true
    end
end

local function IsHoldingPocketRummageActionItem(holder, item)
    local owner = item.components.inventoryitem and item.components.inventoryitem.owner or nil
    return owner == holder
        or (    --Allow linked containers like woby's rack    
                owner.components.inventoryitem == nil and
                owner.entity:GetParent() == holder
            )
end

local function ClosePocketRummageMem(inst, item)
    if item == nil then
        item = inst.sg.mem.pocket_rummage_item
    elseif item ~= inst.sg.mem.pocket_rummage_item then
        return
    end
    if item then
        inst.sg.mem.pocket_rummage_item = nil

        if OwnsPocketRummageContainer(inst, item) and item.components.container then
            item.components.container:Close(inst)
        end
    end
end

local function CheckPocketRummageMem(inst)
    local item = inst.sg.mem.pocket_rummage_item
    if item then
        if not (item.components.container and
                item.components.container:IsOpenedBy(inst) and
                OwnsPocketRummageContainer(inst, item))
        then
            SetPocketRummageMem(inst, nil)
        else
            local stayopen = inst.sg.statemem.keep_pocket_rummage_mem_onexit
            if not stayopen and inst.sg.statemem.is_going_to_action_state then
                local buffaction = inst:GetBufferedAction()
                if buffaction and
                    (    buffaction.action == ACTIONS.BUILD or
                        (buffaction.action == ACTIONS.DROP and buffaction.invobject ~= item) or
                        (buffaction.invobject and IsHoldingPocketRummageActionItem(item, buffaction.invobject))
                    )
                then
                    stayopen = true
                end
            end
            if not stayopen then
                ClosePocketRummageMem(inst)
            end
        end
    end
end

local function TryResumePocketRummage(inst)
    local item = inst.sg.mem.pocket_rummage_item
    if item then
        if item.components.container and
            item.components.container:IsOpenedBy(inst) and
            OwnsPocketRummageContainer(inst, item)
        then
            inst.sg.statemem.keep_pocket_rummage_mem_onexit = true
            inst.sg:GoToState("start_pocket_rummage", item)
            return true
        end
        inst.sg.mem.pocket_rummage_item = nil
    end
    return false
end

AddAction("PERFORM", "Perform!", function(act)
if act.invobject then
act.invobject.components.performable:Perform(act.doer)

return true
end

return false
end)

AddComponentAction("EQUIPPED", "performable", function(inst, doer, target, actions, right)
if doer.replica.inventory:GetActiveItem() == nil and (doer.replica.rider == nil or not doer.replica.rider:IsRiding()) then
table.insert(actions, ACTIONS.PERFORM)
end
end)

local perform_state = State{
name = "my_custom_perform_state",
tags = { "busy", "nointerrupt", "keep_pocket_rummage" },

    onenter = function(inst)
        local buffaction = inst:GetBufferedAction()
        local songdata = buffaction and buffaction.invobject.songdata or nil

    if songdata ~= nil then
            inst.AnimState:PushAnimation(songdata.INSTANT and "quote" or "my_custom_perform_state", false)
            if songdata.INSTANT then
                inst.components.talker:Say(GetString(inst, "ANNOUNCE_" .. string.upper(songdata.NAME)), nil, true)
            end
        end
    end,

onexit = CheckPocketRummageMem,

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

    timeline =
    {
        TimeEvent(3 * FRAMES, function(inst)
            local buffaction = inst:GetBufferedAction()
            local songdata = buffaction and buffaction.invobject.songdata or nil
            if songdata then
                inst.SoundEmitter:PlaySound(songdata.SOUND or ("dontstarve_DLC001/characters/wathgrithr/"..(songdata.INSTANT and "quote" or "my_custom_perform_state")))
            end
        end),

        TimeEvent(24 * FRAMES, function(inst)
            inst:PerformBufferedAction()
        end),
        TimeEvent(34 * FRAMES, function(inst)
            inst.sg:RemoveStateTag("busy")
            inst.sg:RemoveStateTag("nointerrupt")
        end),
FrameEvent(42, TryResumePocketRummage),
    },
}


local perform_state_client = State{
name = "my_custom_perform_state",
server_states = { "my_custom_perform_state" },
forward_server_states = true,
onenter = function(inst) inst.sg:GoToState("action_uniqueitem_busy") end
}

AddStategraphState("wilson_client", perform_state_client)
AddStategraphState("wilson", perform_state)
AddStategraphActionHandler("wilson", GLOBAL.ActionHandler(ACTIONS.PERFORM, "my_custom_perform_state"))
AddStategraphActionHandler("wilson_client", GLOBAL.ActionHandler(ACTIONS.PERFORM, "my_custom_perform_state"))

 

Haha same, but if no one is gonna help i am gonna try to use the all beloved software that is spriter to make the animation @0@   

I mean if anyone could teach me how to reuse animations that already are in the game in general, it would be great

  • Health 1

https://steamcommunity.com/sharedfiles/filedetails/?id=2898572674

This is what I mostly use as base to adjust the standard animations as custom animations my tall-Maxwell ^^

BUT! as far as I remember the folders sadly don't include Wigfrieds sing animation, so you will have to decompile the folders for wigfried's singing animation and then recompile it, rename the sing animation to maybe customsing and add it to your modmain as for example customitemsing.zip etc.

(I am too exhausted to write a step by step explanation atm x_x)

  • Health 1

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
×
  • Create New...