Jump to content

Custom Item dont show


Recommended Posts

A lot of your code for the weapon is from don't starve instead of don't starve together.  Your onEquip/Unequip should be outside the main function, your missing network code, and some code is different like "local trans = inst.entity:AddTransform()" should be "inst.entity:AddTransform()".  Here is what it should look like. 

 

local assets = { 
    Asset("ANIM", "anim/chocolate_weapon.zip"),
    Asset("ANIM", "anim/swap_chocolate_weapon.zip"), 

    Asset("ATLAS", "images/inventoryimages/chocolate_weapon.xml"),
    Asset("IMAGE", "images/inventoryimages/chocolate_weapon.tex"),
}


local prefabs = {
}

local function OnEquip(inst, owner) 
    owner.AnimState:OverrideSymbol("swap_object", "swap_chocolate_weapon", "chocolate_weapon")
    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()

    
    inst.AnimState:SetBank("chocolate_weapon")
    inst.AnimState:SetBuild("chocolate_weapon")
    inst.AnimState:PlayAnimation("idle")
	
	MakeInventoryPhysics(inst)
		
	if not TheWorld.ismastersim then
		return inst
	end	
	
	inst.entity:SetPristine()
	
	--inst:AddComponent("weapon")
	--inst.components.weapon:SetDamage()
	--inst.components.weapon:SetOnAttack(OnAttack)

    inst:AddComponent("inventoryitem")
    inst.components.inventoryitem.imagename = "chocolate_weapon"
    inst.components.inventoryitem.atlasname = "images/inventoryimages/chocolate_weapon.xml"
    
    inst:AddComponent("equippable")
    inst.components.equippable:SetOnEquip(OnEquip)
    inst.components.equippable:SetOnUnequip(OnUnequip)

    return inst
end

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

The weapon spawns but the image doesn't show up in your hand, might be an issue with your anim file.  Might have to rebuild it.

 

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