Jump to content

Problem With Equipable Item


Recommended Posts

Hey, i am working again on my mod Drok the Caveman, but i am running into a problem.

 

I currently am making a spear you can throw. But it won't show when you have it equiped. The inventory image and ground textures are working fine, just the equiped item won't show.

 

Removed.

 

This is the prefab lua for the throwing spear:

local assets={     Asset("ANIM", "anim/javelin.zip"),    Asset("ANIM", "anim/swap_javelin.zip"),     Asset("ATLAS", "images/inventoryimages/javelin.xml"),    Asset("IMAGE", "images/inventoryimages/javelin.tex"),}local prefabs = {}local function fn(colour)    local function OnEquip(inst, owner)         owner.AnimState:OverrideSymbol("swap_object", "swap_javelin", "swap_javelin")        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 inst = CreateEntity()    local trans = inst.entity:AddTransform()    local anim = inst.entity:AddAnimState()    local sound = inst.entity:AddSoundEmitter()    MakeInventoryPhysics(inst)        anim:SetBank("javelin")    anim:SetBuild("javelin")    anim:PlayAnimation("idle")    inst:AddComponent("inspectable")    inst:AddComponent("inventoryitem")    inst.components.inventoryitem.imagename = "javelin"    inst.components.inventoryitem.atlasname = "images/inventoryimages/javelin.xml"        inst:AddComponent("equippable")    inst.components.equippable:SetOnEquip( OnEquip )    inst.components.equippable:SetOnUnequip( OnUnequip )        return instendSTRINGS.NAMES.JAVELIN = "Throwing Spear"STRINGS.CHARACTERS.DROK.DESCRIBE.JAVELIN = "Drok good hunt!"STRINGS.CHARACTERS.GENERIC.DESCRIBE.JAVELIN = "It's some sort of ancient throwing device."return  Prefab("common/inventory/javelin", fn, assets, prefabs) 

 

Does anyone have a clue?

Thanks

Link to comment
Share on other sites

Nothing stands out, perhaps double check the spriter file directory structure/symbol names.

 

Allright, this is my folder structure and names:

 

exported

   javelin

      javelin

         javelin01 (holds the ground images and throwing images)

         javelinbroken01 (holds the broken parts images for when the tool is used)

         javelin.scml

         javelin.zip

      swap_javelin

         swap javelin

            swap_javelin.scml

            swap_javelin.zip

            javelin.png

 

 

Hope you can help

Link to comment
Share on other sites

Ahh, you need to have swap_javelin folder at the same level as scml file, then the held item image inside it, e.g.

 

->swap_javelin.scml

->swap_javelin (dir)

  |-->javelin.png

 

The directory name is the 3rd argument for OverrideSymbol (it gets translated into symbol name in intermediate files).

 

It 'might' actually work if you leave it as is and use 'symbol0' as 3rd argument, but I'd suggest against it even if it happens to work, because it's 'undefined behavior'.

Link to comment
Share on other sites

Ahh, you need to have swap_javelin folder at the same level as scml file, then the held item image inside it, e.g.

 

->swap_javelin.scml

->swap_javelin (dir)

  |-->javelin.png

 

The directory name is the 3rd argument for OverrideSymbol (it gets translated into symbol name in intermediate files).

 

It 'might' actually work if you leave it as is and use 'symbol0' as 3rd argument, but I'd suggest against it even if it happens to work, because it's 'undefined behavior'.

 

Ah, we're making some progress. Now a new problem occurs. 

The pivot point is not correct in the game.

post-447131-0-54772700-1417806527_thumb.

 

But i did set the pivot point in spriter

post-447131-0-86493600-1417806183_thumb.

 

Do you have any idea what i did wrong?

Thanks mate

Link to comment
Share on other sites

That's odd... the game acts as if pivot is 0 0. Might be that spriter went silly, my typical approach is just opening the scml file in notepad++/sublime and checking manually if pivots are actually set properly - the pivots are in the same line as filenames at the very top of the file.

Link to comment
Share on other sites

That's odd... the game acts as if pivot is 0 0. Might be that spriter went silly, my typical approach is just opening the scml file in notepad++/sublime and checking manually if pivots are actually set properly - the pivots are in the same line as filenames at the very top of the file.

 

Tried it but still doesn't work... 

 

Any last stands?

 

Even scaling the spear in spriter doesnt seem to have an effect in the game

Link to comment
Share on other sites

Scaling in spriter will not work because the animation is unused, just the symbol is (think of it as copy pasting your png on a particular slot of existing klei animation). Anyhow, I'm out of ideas, unless you want to upload the swap_javelin dir as a whole (or at least the spriter file), maybe it would tell me what could go wrong. It certainly shouldn't ignore pivot like that.

Link to comment
Share on other sites

Scaling in spriter will not work because the animation is unused, just the symbol is (think of it as copy pasting your png on a particular slot of existing klei animation). Anyhow, I'm out of ideas, unless you want to upload the swap_javelin dir as a whole (or at least the spriter file), maybe it would tell me what could go wrong. It certainly shouldn't ignore pivot like that.

 

Allright, here comes the swap_javelin file! 

 

exported.zip

 

 

Hope you can help me out ^^

Link to comment
Share on other sites

Okay I get what happened - the pivot is set on the object not on the image. This is the part modtools are reading:

<file id="0" name="swap_javelin/Javelin.png" width="320" height="200" pivot_x="0" pivot_y="1"/>

the pivot set on keys is being ignored as far as builds are concerned. What it means to you is, set pivots by double clicking on the image file on the folder/file listing on the right side of spriter UI, instead of... well, wherever you set pivots on key/object level, I dunno.

 

Try this (just scml file) swap_javelin.zip

Link to comment
Share on other sites

Okay I get what happened - the pivot is set on the object not on the image. This is the part modtools are reading:

<file id="0" name="swap_javelin/Javelin.png" width="320" height="200" pivot_x="0" pivot_y="1"/>

the pivot set on keys is being ignored as far as builds are concerned. What it means to you is, set pivots by double clicking on the image file on the folder/file listing on the right side of spriter UI, instead of... well, wherever you set pivots on key/object level, I dunno.

 

Try this (just scml file) attachicon.gifswap_javelin.zip

 

Allright, it worked. The only problem is that it's too small. Since scaling it in spriter won't work, do you have any ideas on how to scale it?

 

post-447131-0-57234300-1417812272_thumb.

Link to comment
Share on other sites

Uh the simplest way - just rescale the swap png? Just remember to reload/resave file in spriter after doing size changes or it will end up totally out of place.

 

Ah thanks, do you by any change happen to know how to make the projectile face the target? if i throw the spear to a target thats left, up, or down from the character it just seems odd because it has an animation that faces to the right.

 

Any ideas?

Link to comment
Share on other sites

I was wrestling with custom made projectile issues at one point, I ended up with the need to do
    inst.AnimState:SetOrientation( ANIM_ORIENTATION.OnGround )

on projectile prefab/entity for my own projectiles to rotate proper and set the spriter animation to show as if throw from left to right.

 

For some reason klei projectiles are misbehaving unless they use inst.AnimState:SetOrientation( ANIM_ORIENTATION.Default ), so I suspect there might be some animation flag, or a different way to do it too.

Link to comment
Share on other sites

I was wrestling with custom made projectile issues at one point, I ended up with the need to do

    inst.AnimState:SetOrientation( ANIM_ORIENTATION.OnGround )

on projectile prefab/entity for my own projectiles to rotate proper and set the spriter animation to show as if throw from left to right.

 

For some reason klei projectiles are misbehaving unless they use inst.AnimState:SetOrientation( ANIM_ORIENTATION.Default ), so I suspect there might be some animation flag, or a different way to do it too.

 

So what do you think is the best way to do it? It looks kinda odd if you throw the spear the wrong way around ahah!

Link to comment
Share on other sites

My projectiles are separate entities from weapons firing them, but it should still apply to normal thrown weapons, I suppose try putting

inst.AnimState:SetOrientation( ANIM_ORIENTATION.OnGround ) 

somewhere in OnThrow function, and see how it behaves? Depending on what you are doing on hit, you may need to reset it to Default in OnHit/Miss tho.

 

Link to comment
Share on other sites

My projectiles are separate entities from weapons firing them, but it should still apply to normal thrown weapons, I suppose try putting

inst.AnimState:SetOrientation( ANIM_ORIENTATION.OnGround ) 

somewhere in OnThrow function, and see how it behaves? Depending on what you are doing on hit, you may need to reset it to Default in OnHit/Miss tho.

 

I got it working, it looks a little bit weird. The spear is off target when it hits.

Maybe i can tweak it in spriter to make it look a bit better? Any ideas? Thanks mate!

 

Or maybe there is another inst.AnimState:SetOrientation that orientates to the target without being a texture on the ground?

Link to comment
Share on other sites

according to constants.lua

ANIM_ORIENTATION ={	Default = 0,	OnGround = 1,}

0 won't make it rotate at all, as you saw... I just tweak it in spriter until I'm satisfied with results, I don't know of a better option.

 

Thank you! It doesnt really look weird anymore, i just tweak the speed a bit it looks fine now!

 

Do you happen to know how to make the projectile go back to the idle animation when you missed? Right now when you miss with the spear it goes on forever so you cant pick it up again.

 

This is the code i have for the missing part:

    local function OnMiss(inst, owner, target)        inst.AnimState:PlayAnimation("idle", true)        inst.AnimState:SetOrientation( ANIM_ORIENTATION.Default )    end    inst.components.projectile:SetHoming(false)    inst.components.projectile:SetOnMissFn(OnMiss)

Thanks again

Link to comment
Share on other sites

Hmm... try adding

inst.Physics:Stop()

into OnMiss() function

 

It worked! The only weird thing now is that the idle animation doesnt really fit when you miss, maybe i'll add a missed animation in which the spear just bounces of the ground or something. ^^

 

I'll keep you up to date on the progress :D

Link to comment
Share on other sites

Hmm... try adding

inst.Physics:Stop()

into OnMiss() function

 

I made an animation that looks better, it now bounces of the ground. But the problem is that the bounce repeats itself while it has to just lay there.

 

Maybe i must create a second animation (missed_idle) or something and flush the animation after the miss animation?

 

Also, when you pick up the missed spear and drop it again it also plays the missed animation.

 

Can you help me again? Thanks :D

Link to comment
Share on other sites

I made an animation that looks better, it now bounces of the ground. But the problem is that the bounce repeats itself while it has to just lay there.

 

Maybe i must create a second animation (missed_idle) or something and flush the animation after the miss animation?

 

Also, when you pick up the missed spear and drop it again it also plays the missed animation.

 

Can you help me again? Thanks :grin:

 

Did you set the animation to loop on accident? (PlayAnimation("anim",true) or in spriter maybe, though I think the latter doesn't matter)

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