Jump to content

Error [string "scripts/components/inventory.lua"]:637: attempt to index local 'inst' (a nil value)


Recommended Posts

13 hours ago, Lumina said:

Maybe you can explain what you are trying to do and copy here the code, so people will be able to help you better, without having to do too much search and testing.

trying to get an item to work. from what i get it might be a load up error, nothing to do with the character.

 

local assets=
{   
    Asset("ANIM", "anim/Healtorch.zip"),
    Asset("ANIM", "anim/swap_Healtorch.zip"),
    Asset("ANIM", "anim/torch.zip"),
    Asset("ANIM", "anim/swap_torch.zip"),
    
    Asset("SOUND", "sound/common.fsb"),
    
    Asset("ATLAS", "images/inventoryimages/cadstaff.xml"),
    Asset("IMAGE", "images/inventoryimages/cadstaff.tex"),
}

local prefabs =
{ "torchfire"
}

 

    local function OnEquip(inst, owner)
        owner.AnimState:OverrideSymbol("swap_object", "swap_Healtorch", "swap_Healtorch")
        owner.AnimState:Show("ARM_carry")
        owner.AnimState:Hide("ARM_normal")
        inst.components.equippable.dapperness = TUNING.CRAZINESS_MED
        
        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 say(speaker, words)
        if speaker and speaker.components.talker then
            speaker.components.talker:Say(words)
        end
    
    end
    
    local function healtarget(staff, target)
        local owner = staff.components.inventoryitem.owner
        if target:HasTag("player") or not target:HasTag("monster") then
            
            target.components.health:DoDelta(40)
            
        else
            say(owner, "DontActdum.")
        end
    end
    
 
    
    local function usecadstaff(staff, target)
        local owner = staff.components.inventoryitem.owner
        if not owner:HasTag("mond") then
            say(owner, "I don't know how to use it!")
            return
        end
 
        if target ~= nil and target.components.health ~= nil then
            if target.components.health.currenthealth < target.components.health.maxhealth then
                healtarget(staff,target)
            else
                say(owner, "He's/She's fine")
            end
        end
    end
    

local function fn()
    
 local inst = CreateEntity()

    inst.entity:AddTransform()
    inst.entity:AddAnimState()
    inst.entity:AddSoundEmitter()
    inst.entity:AddNetwork()
   
    MakeInventoryPhysics(inst)

    inst.AnimState:SetBank("torch")
    inst.AnimState:SetBuild("swap_torch")
    inst.AnimState:PlayAnimation("idle")
    inst.AnimState:SetBank("cadstaff")
    inst.AnimState:SetBuild("cadstaff")
    inst.AnimState:PlayAnimation("idle")

    inst.entity:SetPristine()

    if not TheWorld.ismastersim then
        return inst
    end

    inst.entity:SetPristine()
    
    inst:AddComponent("inspectable")
    
    inst:AddComponent("inventoryitem")
    inst.components.inventoryitem.imagename = "Healtorch"
    inst.components.inventoryitem.atlasname = "images/inventoryimages/cadstaff.xml"
    
    inst:AddComponent("spellcaster")
    inst.components.spellcaster:SetSpellFn(usecadstaff)
    inst.components.spellcaster.canuseontargets = true    
    inst.components.spellcaster.canonlyuseonlocomotors = true
    
    inst:AddComponent("weapon")
    inst.components.weapon:SetDamage(TUNING.TORCH_DAMAGE)
    
    inst:AddComponent("equippable")
    inst.components.equippable:SetOnEquip( OnEquip )
    inst.components.equippable:SetOnUnequip( OnUnequip )

    return inst
end

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

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