Jump to content

[HELP] Custom Item Crashes upon Drop/Equip


Katalyis

Recommended Posts

So, I was attempting to update my 'Lodger, the Worldologist' mod and create a custom item for him. I have tried following every tutorial, but nothing has worked so far.

 

The issue is is that the custom item in question -a handheld old timey candle lantern- shows up in his inventory upon start of the game, and the inventory picture for this works. However, the moment it is equipped or dropped on the ground, the game proceeds to crash. Prior to when the crashing started, the items just simply would not show up and instead were just invisible when equipped or dropped.

 

I believe the crashing started when I copied the 'lighter' and 'swap_lighter'. I renamed the .zip files, changed out the atlas-0.tex, renamed the bins. I have since backtracked to using the sample item 'wand' zips and changed those out. There are sprites for the dropped and equipped versions, so I'm not entirely sure why it's refusing to see them. Any help would be greatly appreciated. I've included the zip file so everyone can have a look at the coding. I'm pretty much a noob when it comes to DS coding, and what I have is basically thanks to tutorials and rummaging around the game files, but adding new things to this extent is a whole new ball game for me.

lodhelp.zip

Link to comment
Share on other sites

I can't see the .zip, so yeah...

 

Did you use the search function to make sure you linked everything up correctly?

 

Sorry, I could've sworn I had attached the file but when I went back to review the post it wasn't there. It's there now.

 

And yes, I did use the search function and make sure everything was linked up. I figured that had been my first mistake, was that I somehow just goobered the connection to something, but I haven't found any after a few checks with the search function.

Link to comment
Share on other sites

One thing I get is

Could not find anim bank [lighter]

but that shouldn't be crashing it - however you should set your bank name to your entity name in spriter, which is just 'lan', to make it actually show on ground/dropped.

    anim:SetBank("lan")

Your override implies "swap_lighter" as symbol name on your build, yet the symbol name is supposedly "lan".

        owner.AnimState:OverrideSymbol("swap_object", "swap_lan", "lan")

Also you want to set pivot point on the lan.png in swap_lan to where you want your character's hand to be when holding it.

 

After doing all that it didnt crash but it still refused to actually show, so I just recompiled spriter images without changing anything else and... it worked, so something was odd with the output of your modtools, or you forgot to actually recompile spriter stuff :p

 

post-336434-0-26533200-1413706610_thumb.

 

attached the changed mod if it's easier for you to see what I've done, let me know if you want me to take the files down Lodger.zip

 

Link to comment
Share on other sites

One thing I get is

Could not find anim bank [lighter]

but that shouldn't be crashing it - however you should set your bank name to your entity name in spriter, which is just 'lan', to make it actually show on ground/dropped.

    anim:SetBank("lan")

Your override implies "swap_lighter" as symbol name on your build, yet the symbol name is supposedly "lan".

        owner.AnimState:OverrideSymbol("swap_object", "swap_lan", "lan")

Also you want to set pivot point on the lan.png in swap_lan to where you want your character's hand to be when holding it.

 

After doing all that it didnt crash but it still refused to actually show, so I just recompiled spriter images without changing anything else and... it worked, so something was odd with the output of your modtools, or you forgot to actually recompile spriter stuff :razz:

 

attachicon.giflan.jpg

 

attached the changed mod if it's easier for you to see what I've done, let me know if you want me to take the files down attachicon.gifLodger.zip

 

Huh. See, while trying to follow tutorials, I found that were telling me different things with the 'OverrideSymbol' area.

 

And I'm guessing it's the 'recompiling spriter images' part. I have no idea what that is or how to do it so...yeah, that's probably why that was goofing up. As I said, real noob with this stuff, and this is the first time I've touched Spriter so I've been exclusively following tutorials for it and none of them said anything about recompiling. :/

Link to comment
Share on other sites

The first argument to OverrideSymbol is symbol used by animation itself (in this case, player animations, all of them), and that's fixed unless you're making your own. Second is build name, which is spriter file name, third is symbol name, which is directory name within your spriter project.  The guides iirc use swap_something as both spriter name and directory name, which while simpler to follow is causing confusion what's what.

 

And yeah, to actually turn spriter animations into game-readable ones you have to use modtools - if you're using steam version, this should tell you how (at least i assume steam didn't change in the meantime, tho the post is a bit old), otherwise there's a link for brebuilt binaries at the end of getting started. Or you can rebuild them from source repo, if you prefer (or are not on windows).

Link to comment
Share on other sites

The first argument to OverrideSymbol is symbol used by animation itself (in this case, player animations, all of them), and that's fixed unless you're making your own. Second is build name, which is spriter file name, third is symbol name, which is directory name within your spriter project.  The guides iirc use swap_something as both spriter name and directory name, which while simpler to follow is causing confusion what's what.

 

And yeah, to actually turn spriter animations into game-readable ones you have to use modtools - if you're using steam version, this should tell you how (at least i assume steam didn't change in the meantime, tho the post is a bit old), otherwise there's a link for brebuilt binaries at the end of getting started. Or you can rebuild them from source repo, if you prefer (or are not on windows).

 

Alright then, that makes more sense now.

 

Ah, alright. Well thank you for helping me out and pointing me towards the compiling stuff, I appreciate it. c: Hopefully I can get this thing working and functioning properly without breaking it any more.

Link to comment
Share on other sites

inst.AnimState:SetScale(0.5, 0.5, 0.5)

for scaling the dropped form, and for equip form just edit "atlas-0.tex" in "swap_lan".

 

 

Well, the SetScale worked for the dropped form. However, the equipped form part isn't working. I've tried editting it, going so far as to 400x400 for it and it's still the same size as before.

Link to comment
Share on other sites

Changing atlas texes while using spriter for building them is not a good idea since modtools will just rebuild the file. Besides, scaling the whole atlas will never work because they are % based anyway, atlas does not save the ingame size, it's defined somewhere in build.bin . But anyhow, don't do that, just scale the swap_lan/lan/lan.png file (you may want to reopen the spriter file and make sure the pivot is where you want it afterwards, tho it again is % based) and recompile it (if you have set up mod tools through steam it should do it automatically on game start)

Link to comment
Share on other sites

Changing atlas texes while using spriter for building them is not a good idea since modtools will just rebuild the file. Besides, scaling the whole atlas will never work because they are % based anyway, atlas does not save the ingame size, it's defined somewhere in build.bin . But anyhow, don't do that, just scale the swap_lan/lan/lan.png file (you may want to reopen the spriter file and make sure the pivot is where you want it afterwards, tho it again is % based) and recompile it (if you have set up mod tools through steam it should do it automatically on game start)

 

I have tried scaling the swap_lan/lan/lan.png and started up the Steam version, let the compiler do its thing. But I have not seen any difference in the scaling of any item afterwards. I've only seen the change with the 'animscale' for the dropped version, but so far nothing has affected the equipped version.

Link to comment
Share on other sites

Okay, I have one final question. Now, obviously since this is a lantern, I want it to produce light when it's either equipped, or dropped on the ground. It works similar to Willow's lighter, in that it has infinite uses and doesn't run out of fuel. the lantern just wouldn't set anything on fire.

 

Now I have tried to keep from bothering anyone for more help, I looked for any tutorials or help threads, and even combing through the game code but I can't quite seem to find anything about having an item emit light. There is a serious lack of info on this sort of thing. I've seen people have characters that emit light, but nothing about items.

 

So, how would I tell it to check if the item is equipped or dropped, and tell the item to emit light?

Link to comment
Share on other sites

If the png scaling didn't take effect, it might be that autocompiler didn't figure it should rebuild the file, try changing scml slightly or just resaving over it, or deleting anim/swap_lan or something along those lines, to force it to rebuild the file.

 

As for light, you probably could use similar logic to lighter/torches, just not add burnable or fueled components, e.g. add

    inst.fire = SpawnPrefab( "lighterfire" )    local follower = inst.fire.entity:AddFollower()    follower:FollowSymbol( owner.GUID, "swap_object", 35, -35, 1 )

to onequip and

    inst.fire:Remove()    inst.fire = nil

to onunequip of lan. Obviously numbers would need to change, and I'd prob just make my own prefab to spawn - you 'can' look at torchfire/lanternfire and try to make your own based on them. I've no clue about the particle system stuff tho, I'm typically either directly setting fixed Light params or use lighttweener.

Link to comment
Share on other sites

If the png scaling didn't take effect, it might be that autocompiler didn't figure it should rebuild the file, try changing scml slightly or just resaving over it, or deleting anim/swap_lan or something along those lines, to force it to rebuild the file.

 

As for light, you probably could use similar logic to lighter/torches, just not add burnable or fueled components, e.g. add

    inst.fire = SpawnPrefab( "lighterfire" )    local follower = inst.fire.entity:AddFollower()    follower:FollowSymbol( owner.GUID, "swap_object", 35, -35, 1 )

to onequip and

    inst.fire:Remove()    inst.fire = nil

to onunequip of lan. Obviously numbers would need to change, and I'd prob just make my own prefab to spawn - you 'can' look at torchfire/lanternfire and try to make your own based on them. I've no clue about the particle system stuff tho, I'm typically either directly setting fixed Light params or use lighttweener.

 

I did get the autocompiler to work, and the images for the lantern are showing up in the game normally, proper size and all. At least that's one problem taken care of.

 

I copied and added your lines into their proper spots, but as soon as I equip the item, it immediately crashes the game. This lantern apparently does not want to function properly. :|

Link to comment
Share on other sites

I did get the autocompiler to work, and the images for the lantern are showing up in the game normally, proper size and all. At least that's one problem taken care of.

 

I copied and added your lines into their proper spots, but as soon as I equip the item, it immediately crashes the game. This lantern apparently does not want to function properly. :|

 

That's weird... is there anything in the log as for why it would crash? Coz I just did it myself and it's not crashing

    local function OnEquip(inst, owner)         owner.AnimState:OverrideSymbol("swap_object", "swap_lan", "lan")        owner.AnimState:Show("ARM_carry")         owner.AnimState:Hide("ARM_normal")     inst.fire = SpawnPrefab( "lighterfire" )    local follower = inst.fire.entity:AddFollower()    follower:FollowSymbol( owner.GUID, "swap_object", 35, -35, 1 )    end    local function OnUnequip(inst, owner)         owner.AnimState:Hide("ARM_carry")         owner.AnimState:Show("ARM_normal")     inst.fire:Remove()    inst.fire = nil    end

what's different? lol

Link to comment
Share on other sites

That's weird... is there anything in the log as for why it would crash? Coz I just did it myself and it's not crashing

    local function OnEquip(inst, owner)         owner.AnimState:OverrideSymbol("swap_object", "swap_lan", "lan")        owner.AnimState:Show("ARM_carry")         owner.AnimState:Hide("ARM_normal")     inst.fire = SpawnPrefab( "lighterfire" )    local follower = inst.fire.entity:AddFollower()    follower:FollowSymbol( owner.GUID, "swap_object", 35, -35, 1 )    end    local function OnUnequip(inst, owner)         owner.AnimState:Hide("ARM_carry")         owner.AnimState:Show("ARM_normal")     inst.fire:Remove()    inst.fire = nil    end

what's different? lol

 

Nothing, that's what the strangest part of it is.

local assets={     Asset("ANIM", "anim/lan.zip"),    Asset("ANIM", "anim/swap_lan.zip"),     Asset("ATLAS", "images/inventoryimages/lan.xml"),    Asset("IMAGE", "images/inventoryimages/lan.tex"),}local prefabs = {}local function OnEquip(inst, owner)    owner.AnimState:OverrideSymbol("swap_object", "swap_lan", "lan")    owner.AnimState:Show("ARM_carry")    owner.AnimState:Hide("ARM_normal") inst.fire = SpawnPrefab( "lighterfire" )local follower = inst.fire.entity:AddFollower()follower:FollowSymbol( owner.GUID, "swap_object", 35, -35, 1 )end local function OnUnequip(inst, owner)    owner.AnimState:Hide("ARM_carry")    owner.AnimState:Show("ARM_normal")inst.fire:Remove()inst.fire = nilend    local inst = CreateEntity()    local trans = inst.entity:AddTransform()    local anim = inst.entity:AddAnimState()    MakeInventoryPhysics(inst)        anim:SetBank("lan")    anim:SetBuild("lan")    anim:PlayAnimation("idle")    inst:AddComponent("inventoryitem")    inst.components.inventoryitem.imagename = "lan"    inst.components.inventoryitem.atlasname = "images/inventoryimages/lan.xml"        inst:AddComponent("equippable")    inst.components.equippable:SetOnEquip( OnEquip )    inst.components.equippable:SetOnUnequip( OnUnequip )    return instendreturn  Prefab("common/inventory/lan", fn, assets, prefabs)

I reverted the code back to before the lighting coding was added, and it worked fine. With my prior attempts at doing it myself, it waited until I had equipped the item before crashing -which I believe was a 'attempt to index field 'fire' (a nil value) error-. With this coding, the moment I try to enable the mod it goes to the 'this mod failed to run last time' screen and freezes the game.

Link to comment
Share on other sites

 

Try adding "lighterfire", to local prefabs.

 

local prefabs ={	"lighterfire",}    

 

 

I tried that after giving it a glance over and going 'well maybe that's the issue'. Nope. Same 'failed to run' screen when I enable the mod.

Link to comment
Share on other sites

I reverted the code back to before the lighting coding was added, and it worked fine. With my prior attempts at doing it myself, it waited until I had equipped the item before crashing -which I believe was a 'attempt to index field 'fire' (a nil value) error-. With this coding, the moment I try to enable the mod it goes to the 'this mod failed to run last time' screen and freezes the game.

 

Oh, I guess at some odd case you couldve ended up with equipped item without the fire element? I guess you could do 

if(inst.fire)theninst.fire:Remove()inst.fire=nilend

but it shouldnt be necesary... hmm

Link to comment
Share on other sites

ohh the reason your code crashed (the one you posted) is because you overwrote the

 

local function fn()
 

before onequip too :razz: Still doesn't explain why equip code wasnt working in the first place

 

EDIT:

 

local assets={     Asset("ANIM", "anim/lan.zip"),    Asset("ANIM", "anim/swap_lan.zip"),     Asset("ATLAS", "images/inventoryimages/lan.xml"),    Asset("IMAGE", "images/inventoryimages/lan.tex"),}local prefabs = {}local function fn()    local function OnEquip(inst, owner)         owner.AnimState:OverrideSymbol("swap_object", "swap_lan", "lan")        owner.AnimState:Show("ARM_carry")         owner.AnimState:Hide("ARM_normal")     inst.fire = SpawnPrefab( "lighterfire" )    local follower = inst.fire.entity:AddFollower()    follower:FollowSymbol( owner.GUID, "swap_object", 35, -35, 1 )    end    local function OnUnequip(inst, owner)         owner.AnimState:Hide("ARM_carry")         owner.AnimState:Show("ARM_normal")         if(inst.fire)then            inst.fire:Remove()            inst.fire = nil        end    end    local inst = CreateEntity()    local trans = inst.entity:AddTransform()    local anim = inst.entity:AddAnimState()    MakeInventoryPhysics(inst)        anim:SetBank("lan")    anim:SetBuild("lan")    anim:PlayAnimation("idle")        inst:AddComponent("inventoryitem")    inst.components.inventoryitem.imagename = "lan"    inst.components.inventoryitem.atlasname = "images/inventoryimages/lan.xml"        inst:AddComponent("equippable")    inst.components.equippable:SetOnEquip( OnEquip )    inst.components.equippable:SetOnUnequip( OnUnequip )    return instendreturn  Prefab("common/inventory/lan", fn, assets, prefabs)

Link to comment
Share on other sites

Here's the link to the log.txt: https://drive.google.com/file/d/0BwUHW2TEtYocM1c4Vy0tS25yV2M/view?usp=sharing

 

I see something about issues with the 'fn' in the 'return  Prefab("common/inventory/lan", fn, assets, prefabs)' end line that's causing error issues.

 

EDIT: Ooooh, yep and there it is. That was probably why it was yelling at me about it.

Link to comment
Share on other sites

This isn't necessary, but if you add this to local function (fn)

    inst:AddComponent("characterspecific")    inst.components.characterspecific:SetOwner("lod")	    inst:DoTaskInTime(0, function() if not GetPlayer() or GetPlayer().prefab ~= "lod" then inst:Remove() end end)

Then, if the player isn't playing as Lodger and spawns it in through the console, then the game will automatically remove the lantern from the inventory.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

Please be aware that the content of this thread may be outdated and no longer applicable.

×
×
  • Create New...