Jump to content

Invisible Hand Equippable item


Recommended Posts

Hey, sorry for double posting, but the other thread seemed to get a tad too long with the switching of issues.

I made a hand equippable item, everything works fine right now...except for one thing, the Swappable is missing.

There IS a .zip file for the swappable, it's just not using it for some odd reason.

This is the code in the .lua of the item.

 

local assets =
{
    Asset("ANIM", "anim/giita.zip"),
    Asset("ANIM", "anim/swap_giita.zip"),
    
    Asset("ATLAS", "images/inventoryimages/giita.xml"),
    Asset("IMAGE", "images/inventoryimages/giita.tex"),
}
local prefabs =
{
}

local function ShouldAcceptItem(inst, item)
    if item.prefab == "silk" then
       return true
    end
    return false
end

local function OnGetItemFromPlayer(inst, giver, item)
    if item.prefab == "silk" then
       inst.components.finiteuses.current = inst.components.finiteuses.current + 25
    end
    if inst.components.finiteuses.current > inst.components.finiteuses.total then
       inst.components.finiteuses.current = inst.components.finiteuses.total
    end
end

local function OnEquip(inst, owner)
    owner.AnimState:OverrideSymbol("swap_object", "swap_giita", "swap_giita")
    owner.AnimState:Show("ARM_carry")
    owner.AnimState:Hide("ARM_normal")
end

local function OnUnequip(inst, owner)
    owner.AnimState:Hide("ARM_carry")
    owner.AnimState:Show("ARM_normal")
end

local function fn()
    local inst = CreateEntity()
    inst.entity:AddTransform()
    inst.entity:AddAnimState()
    inst.entity:AddNetwork()

    MakeInventoryPhysics(inst)

    inst.AnimState:SetBank("giita")
    inst.AnimState:SetBuild("giita")
    inst.AnimState:PlayAnimation("idle")

    inst:AddTag("sharp")

    inst.entity:SetPristine()

    if not TheWorld.ismastersim then
        return inst
    end

    inst:AddComponent("weapon")
    inst.components.weapon:SetDamage(60)
    
    inst:AddComponent("finiteuses")
    inst.components.finiteuses:SetMaxUses(150)
    inst.components.finiteuses:SetUses(150)
    if inst.components.finiteuses.current < 0 then
       inst.components.finiteuses.current = 0
    end
    
    inst:AddComponent("trader")
    inst.components.trader.onaccept = OnGetItemFromPlayer
    inst.components.trader:SetAcceptTest(ShouldAcceptItem)

    

    inst:AddComponent("inspectable")

    inst:AddComponent("inventoryitem")
    inst.components.inventoryitem.imagename = "giita"
    inst.components.inventoryitem.atlasname = "images/inventoryimages/giita.xml"

    inst:AddComponent("equippable")
    inst.components.equippable:SetOnEquip(OnEquip)
    inst.components.equippable:SetOnUnequip(OnUnequip)

    MakeHauntableLaunch(inst)

    return inst
end

STRINGS.NAMES.GIITA = "Giita the Guitar"
STRINGS.CHARACTERS.GENERIC.DESCRIBE.GIITA = "Smells like cake."

return  Prefab("common/inventory/giita", fn, assets, prefabs)

Edited by Kooby
Link to comment
Share on other sites

The issue is likely within the compiled animation. The specifics for how the Spriter project for a swap animation needs to be set up are very precise, and unclear.

 

From what I can tell, the requirements are this (some may simply be a matter of standardization):

  • Spriter project must be named "swap_itemname"
  • Animation bank name must be "swap_itemname"
  • Animation name must be "BUILD"
  • Animation must override the pivot to set where the hand will grasp the object
  • Image must be located in a subfolder within the spriter project, not next to the project file
  • In the XML of the project file (open the file in a text editor), the line that begins 
    <folder id="0"

    must be

    <folder id="0" name="swap_itemname">

    ('name' must equal the name of the subfolder containing the image)

Edited by Arkathorn
Link to comment
Share on other sites

I remember that this issue has been fixed already in a different thread a few weeks ago :D

By the ways these requirements are only for hand held items. For wearable items it is not as strict. At least I have wearable items which works as intended without having to do all this bollocks with the animation named BUILD and whatnot, but for hand held item I never got it to work in any other way.

Edited by ZupaleX
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...