Jump to content

Recommended Posts

Ok.....thought this might be fun for all.
 
So I've been working on a few items, and it seems like everytime I gain a foot foward on how things work, I get a big awkard step back.
I started with the handslot item from scratch found "here"  
I built a Lantern. Which you have to build a bit more on the prefab for it to all work then whats offered on the page.
and a few more swap type files for the on and off stuff.
 
SO I looked at a few examples. The monkeyskull lantern is pretty cool, and there is a neat brass lantern as well on the mods page,
 
And it all seemed to go well. I forgot to declare a variable here and there, but for the most part in troubleshooting, I seemed to work things out....of course. Until I got this (dont laugh, cause im not sure how to fix it)
 

Could not find anim bank [ground_shiplantern]
Could not find anim bank [ground_shiplantern]
.../../mods/shiplantern/scripts/prefabs/shiplantern.lua:42: attempt to index field 'Light' (a nil value)

 
Oh and those are the third renames of the bank and build. 
 
for those wanting to look at the prefab

 

local assets=
{
Asset("ANIM", "anim/ground_shiplantern.zip"),
Asset("ANIM", "anim/swap_shiplantern.zip"),
Asset("SOUND", "sound/wilson.fsb"),

Asset("ATLAS", "images/inventoryimages/shiplantern.xml"),
Asset("IMAGE", "images/inventoryimages/shiplantern.tex"),
}
prefabs = {"shiplantern",
}

local function turnon(inst)
if not inst.components.fueled:IsEmpty() then
if not inst.components.machine.ison then
if inst.components.fueled then
inst.components.fueled:StartConsuming()
end
inst.Light:Enable(true)
inst.AnimState:PlayAnimation("idle_on")

if inst.components.equippable:IsEquipped() then
inst.components.inventoryitem.owner.AnimState:OverrideSymbol("swap_object", "swap_shiplantern", "swap_shiplantern_on")
inst.components.inventoryitem.owner.AnimState:Show("SHIPLANTERN_OVERLAY")

end
inst.components.machine.ison = true

inst.SoundEmitter:PlaySound("dontstarve/wilson/lantern_on")
inst.SoundEmitter:PlaySound("dontstarve/wilson/lantern_LP", "loop")

inst.components.inventoryitem:ChangeImageName("shiplantern_lit")
end
end

end

local function turnoff(inst)
if inst.components.fueled then
inst.components.fueled:StopConsuming()
end
inst.Light:Enable(off)
inst.AnimState:PlayAnimation("idle_off")

if inst.components.equippable:IsEquipped() then
inst.components.inventoryitem.owner.AnimState:OverrideSymbol("swap_object", "swap_shiplantern", "swap_shiplantern_off")
inst.components.inventoryitem.owner.AnimState:Hide("SHIPLANTERN_OVERLAY")
end

inst.components.machine.ison = false

inst.SoundEmitter:KillSound("loop")
inst.SoundEmitter:PlaySound("dontstarve/wilson/lantern_off")

inst.components.inventoryitem:ChangeImageName("ShipLantern")
end

local function OnLoad(inst, data)
if inst.components.machine and inst.components.machine.ison then
inst.AnimState:PlayAnimation("idle_on")
turnon(inst)
else
inst.AnimState:PlayAnimation("idle_off")
turnoff(inst)
end
end

local function ondropped(inst)
turnoff(inst)
turnon(inst)
end

local function onpickup(inst)
turnon(inst)
end

local function onputininventory(inst)
turnoff(inst)
end
--

local function onequip(inst, owner)
owner.AnimState:Show("ARM_carry")
owner.AnimState:Hide("ARM_normal")
owner.AnimState:OverrideSymbol("shiplantern_overlay", "swap_shiplantern", "shiplantern_overlay")

if inst.components.fueled:IsEmpty() then
owner.AnimState:OverrideSymbol("swap_object", "swap_shiplantern", "swap_shiplantern_off")
owner.AnimState:Hide("SHIPLANTERN_OVERLAY")
else
owner.AnimState:OverrideSymbol("swap_object", "swap_shiplantern", "swap_shiplantern_on")
owner.AnimState:Show("SHIPLANTERN_OVERLAY")
end
turnon(inst)
end

local function onunequip(inst, owner)
owner.AnimState:Hide("ARM_carry")
owner.AnimState:Show("ARM_normal")
owner.AnimState:ClearOverrideSymbol("shiplantern_overlay")
owner.AnimState:Hide("SHIPLANTERN_OVERLAY")
end

local function nofuel(inst)
local owner = inst.components.inventoryitem and inst.components.inventoryitem.owner
if owner then
owner:PushEvent("torchranout", {torch = inst})
end

turnoff(inst)
end

local function takefuel(inst)
if inst.components.equippable and inst.components.equippable:IsEquipped() then
turnon(inst)
end
end

local function fuelupdate(inst)
local fuelpercent = inst.components.fueled:GetPercent()
inst.Light:SetIntensity(Lerp(0.4, 0.6, fuelpercent))
inst.Light:SetRadius(Lerp(3, 5, fuelpercent))
inst.Light:SetFalloff(.9)
end

local function fn(Sim)
local inst = CreateEntity()
local trans = inst.entity:AddTransform()
local anim = inst.entity:AddAnimState()
local sound = inst.entity:AddSoundEmitter()
MakeInventoryPhysics(inst)

anim:SetBank("ground_shiplantern")
anim:SetBuild("swap_shiplantern")
anim:PlayAnimation("idle")

inst:AddTag("light")

inst:AddComponent("inspectable")

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

inst.components.inventoryitem:SetOnDroppedFn(ondropped)
inst:AddComponent("equippable")

inst:AddComponent("fueled")

inst:AddComponent("machine")
inst.components.machine.turnonfn = turnon
inst.components.machine.turnofffn = turnoff
inst.components.machine.cooldowntime = 0
inst.components.machine.caninteractfn = function() return not inst.components.fueled:IsEmpty() and (inst.components.inventoryitem.owner == nil or inst.components.equippable.isequipped) end

inst.components.equippable:SetOnEquip( onequip )
inst.components.equippable:SetOnUnequip( onunequip )

inst.OnLoad = OnLoad

return inst
end
return Prefab("common/inventory/shiplantern", fn, assets, prefabs)

 

there it is. 

as far as I can tell it has to do with the Spriter portion not being able to find the ANIM files, more then likely due to a typo somewhere that I am not seeing. And to be honest ive tried rechanging the names around, and troubleshooting some rookie mistakes in my script, I couldn't tell you where to look first. If none of this helps, and someone needs to look at the Anim files, let me know and ill pm you a link via dropbox. Any help is appreciated. 

Link to comment
https://forums.kleientertainment.com/forums/topic/53996-my-lamp-wont-lamp/
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
×
  • Create New...