Jump to content

Recommended Posts

Hello there!

I have a hard time figuring out what's wrong with my coding. I feel like I'm totally missing out something.

I'm trying to make my custom item stackable, but whenever I try to spawn it with commands, the game crashes with the attached message.

I use this coding in my item's .lua file in the local function section:

Quote

    inst:AddComponent("stackable")
    inst.components.stackable.maxsize = TUNING.STACK_SIZE_LARGEITEM

Is there anything additional coding I would have to do?

Here's my complete item.lua coding so far:

Spoiler

 

local assets=

    Asset("ANIM", "anim/wishpower.zip"),

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

local prefabs = 
{
}

local function fn(Sim)
    local inst = CreateEntity()
    inst.entity:AddTransform()
    inst.entity:AddAnimState()
    inst.entity:AddNetwork()
    inst.entity:AddSoundEmitter()
    
    MakeInventoryPhysics(inst)
    
    inst.AnimState:SetBank("wishpower")
    inst.AnimState:SetBuild("wishpower")
    inst.AnimState:PlayAnimation("idle")
    
    inst:AddComponent("stackable")
    inst.components.stackable.maxsize = TUNING.STACK_SIZE_LARGEITEM
    
    if not TheWorld.ismastersim then
        return inst
    end
    inst.entity:SetPristine()
    
    inst:AddComponent("inventoryitem")
    inst.components.inventoryitem.imagename = "wishpower"
    inst.components.inventoryitem.atlasname = "images/inventoryimages/wishpower.xml"
    
    MakeHauntableLaunch(inst)
    
    return inst
end

 

 

Névtelen.png

Edited by BillTheCipher
Spoiler

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

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

local prefabs = 
{
}

local function fn(Sim)
    local inst = CreateEntity()
    inst.entity:AddTransform()
    inst.entity:AddAnimState()
    inst.entity:AddNetwork()
    inst.entity:AddSoundEmitter()
    
    MakeInventoryPhysics(inst)
    
    inst.AnimState:SetBank("wishpower")
    inst.AnimState:SetBuild("wishpower")
    inst.AnimState:PlayAnimation("idle")
    
    if not TheWorld.ismastersim then
        return inst
    end
    inst.entity:SetPristine()

    -- Should be beneath the " if not TheWorld.ismastersim then"
    inst:AddComponent("stackable")
    inst.components.stackable.maxsize = TUNING.STACK_SIZE_LARGEITEM
    
    inst:AddComponent("inventoryitem")
    inst.components.inventoryitem.imagename = "wishpower"
    inst.components.inventoryitem.atlasname = "images/inventoryimages/wishpower.xml"
    
    MakeHauntableLaunch(inst)
    
    return inst
end

 

This should work, I put a little comment as well 

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