Sign in to follow this  
Malacath

[Tutorial] Creating a "handslot-equippable-item" from scratch

Recommended Posts

Malacath    123

Ok, again.

You only changed the Spriter project but I told you the code was wrong as well.

local assets={     Asset("ANIM", "anim/logclub.zip"),    Asset("ANIM", "anim/swap_logclub.zip"),     Asset("ATLAS", "images/inventoryimages/logclub.xml"),    Asset("IMAGE", "images/inventoryimages/logclub.tex"),}local prefabs ={    "collapse_small",}local function onequip(inst, owner)     owner.AnimState:OverrideSymbol("swap_object", "swap_logclub", "logclub")    --This here was wrong    owner.AnimState:Show("ARM_carry")     owner.AnimState:Hide("ARM_normal") endlocal function onunequip(inst, owner)     owner.AnimState:Hide("ARM_carry")     owner.AnimState:Show("ARM_normal") endlocal summonchance = 1local function onattack(inst, owner, target)    if math.random() < summonchance then        local pt = target:GetPosition()        local st_pt =  FindWalkableOffset(pt or owner:GetPosition(), math.random()*0.1*PI, 2, 3)        if st_pt then            inst.SoundEmitter:PlaySound("dontstarve/common/destroy_wood")            inst.SoundEmitter:PlaySound("dontstarve/common/destroy_wood")                        st_pt = st_pt + pt            local st = SpawnPrefab("collapse_small")            --print(st_pt.x, st_pt.y, st_pt.z)            st.Transform:SetPosition(st_pt.x, st_pt.y, st_pt.z)        end    endendlocal 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("logclub")            --This here was wrong    anim:SetBuild("logclub")    anim:PlayAnimation("idle")        inst:AddTag("sharp")    inst:AddComponent("weapon")    inst.components.weapon:SetDamage(120)    inst.components.weapon:SetOnAttack(onattack)        -------        inst:AddComponent("finiteuses")    inst.components.finiteuses:SetMaxUses(200)    inst.components.finiteuses:SetUses(200)        inst.components.finiteuses:SetOnFinished( onfinished )    inst:AddComponent("inspectable")        inst:AddComponent("inventoryitem")        inst:AddComponent("equippable")    inst.components.equippable:SetOnEquip( onequip )    inst.components.equippable:SetOnUnequip( onunequip )    inst.components.equippable.walkspeedmult = 0.75    return instendreturn Prefab( "common/inventory/logclub", fn, assets, prefabs) 

I can't test it right now, but this should work.

Edited by Malacath

Share this post


Link to post
Share on other sites
Malacath    123

Ah thanks, that works. It's tiny for some reason but that's a problem for another day.

I'm still sorta getting the hang of this.

You'll have to resize the image. Scaling inside spriter won't work, at least for the swappable build.

Share this post


Link to post
Share on other sites
Redrum313    0

Had it for a second then I tried to perfect the image a bit and now its not working again, even when I repaste your file into the directory. Now I'm REALLY confused. lol

Edited by Redrum313

Share this post


Link to post
Share on other sites
Redrum313    0

Crocko.com wont let me download a second file unless I pay for a membership. If you go to the "more reply options" tab at the bottom here you can just attach the .zip file directly. 

 

Once again your help is greatly appreciated.

Share this post


Link to post
Share on other sites
Redrum313    0

Here's where it sits at present. I can't explain why it's hovering in the air like this. I've redone the image numerous times, the one you sent me is still the only one that will show up in game though.

post-324334-0-38236700-1390167611_thumb.

Share this post


Link to post
Share on other sites
Kuloslav    22

That file was inserted quickly, not positioned carefully. Open the file swap_communicator.scml on notepad and replace to that code:

<?xml version="1.0" encoding="UTF-8"?><spriter_data scml_version="1.0" generator="BrashMonkey Spriter" generator_version="b5">    <folder id="0" name="swap_communicator">        <file id="0" name="swap_communicator/swap_communicator.png" width="100" height="100" pivot_x="0" pivot_y="1"/>    </folder>    <entity id="0" name="swap_communicator">        <animation id="0" name="BUILD" length="1000">            <mainline>                <key id="0">                    <object_ref id="0" name="swap_communicator" folder="0" file="0" abs_x="2.009901" abs_y="-4.613861" abs_pivot_x="0.490099" abs_pivot_y="0.113861" abs_angle="0" abs_scale_x="3" abs_scale_y="3" abs_a="1" timeline="0" key="0" z_index="0"/>                </key>            </mainline>            <timeline id="0" name="swap_communicator">                <key id="0" spin="0">                    <object folder="0" file="0" x="2.009901" y="-4.613861" pivot_x="0.490099" pivot_y="0.113861" angle="0" scale_x="3" scale_y="3"/>                </key>            </timeline>        </animation>    </entity></spriter_data>
After inserting the code, to be sure, open spriter and overwrite the project.
 
Link to communicator.zip below

communicator.zip

Edited by Kuloslav

Share this post


Link to post
Share on other sites
Tomohiko    4
It took me 2 hours to make my swap_myitem works.

Here some TIPS

 

1.

 .scml should be placed 1 directory above than .png file (not in the same directory).

 

2.

If you are re-editing .scml file, becareful.

 

Saving .scml file is a bit complicated.

 

Spriter does't save your project(.scml),

If you don't include file-extension manually.

 

When you saving the project, 

You need to enter fullname+extension , "swap_myitem.scml" and press save key. (than "swap_myitem" and press save)

 

3. If there is a .scml file that have exactly same name,

Spriter doesn't save or overwrite your project.

 

Without any dialoge, it ignores your save-command.

Do not get deceived yourself into believing You overwite the project !

Edited by Tomohiko
  • Like 1
  • GL Happy 1

Share this post


Link to post
Share on other sites
Tomohiko    4
**** File Structure Example ****

 

Before Spriter

exported --- myitem --- swap_myitem --- swap_myitem --- foobar.png

 

                              

After Spriter

exported --- myitem --- swap_myitem --- swap_myitem --- foobar.png

                                                           --- swap_myitem.scml

  • Like 1

Share this post


Link to post
Share on other sites

Ok, so everything is working right except that no image shows up while it's in my hand. It shows up in my inventory and it shows up on the ground, and the hand is positioned as if it's holding something, but the flag is invisible while in my hand.

 

I've followed the tutorial to the letter. I've made sure all the "myitem" references were changed correctly. I've tried every solution mentioned in this thread's comments. I've tried rearranging my folders the way Tomohiko suggested, and the other things he suggested. I've tried repositioning the image in Spriter a couple of different ways.

 

I cannot get this to work. What am I doing wrong?

 

EDIT: It's working now. Read the rest of this thread if you're having similar problems.

 

rainbowflag.zip

Edited by zeropoint101

Share this post


Link to post
Share on other sites

Ok, for anyone else having trouble, I figured out the problem. The main issue was a Spriter bug I think, but I can't seem to get the activation email for their forums to report it. Anyway, I had my file structure wrong to begin with(didn't have a second "swap_myitem" folder inside the first one), but corrected it the way Tomohiko suggested(and the way the tutorial shows, but I just screwed it up) and it still wasn't working.

 

Here was the problem.. when you are trying to save your spriter scml file for the swappable build, you need to be in the first "swap_myitem" folder, not the one inside it where your .png is. BUT, when you try to save there, spriter will just sort of blank out and immediately jump you to the second, inner folder. I thought maybe it just didn't register my click on the save button or something and didn't realize it had changed folders on me. So when I saved, the scml file was in the same inner folder where my png file was.

 

Even when I tried to go back and save it in the proper folder, Spriter just plain won't let you(this was tried on both version 5 AND 6.1 of Spriter). It just jumps you to the inner folder. The solution is to just save it in the inner folder, and then move it manually back the outer "swap_myitem" folder from Windows Explorer. Then everything worked fine.

Share this post


Link to post
Share on other sites

Also, for anyone who isn't aware of this(it really wasn't clear to me), Spriter is a GREAT program, but seems to be very much a beta product and is rather buggy at times, even though it doesn't say it's a beta. If you feel like you know what you're doing and you've thoroughly followed the instructions on anything Spriter-related, it's very likely a bug within Spriter causing the problem. Just report it on their forums and they seem to be good about getting things fixed quickly. I think..

 

EDIT: I posted this because of a bug issue I had with spriter myself that caused me a lot of frustration, and also a lot of people mentioning bugs on the Klei forums. I have since realized that at least some of these bugs may be fixed by just downloading the newest version from Brashmonkey's website. The one included will the Don't Starve mod tools is a bit older and I'm guessing the Don't Starve Mod Tools won't be updated really from experience I've had with other games' mod tools. I also have learned that Brashmonkey IS very good about addressing bugs and getting them fixed, so just hop over to their forums if you have a problem.

Edited by zeropoint101

Share this post


Link to post
Share on other sites

What would be the approach to making a custom "bodyslot-equippable-item" ?

 

I'm new at this, but I'm almost positive it would all be exactly the same steps except for the coding in the prefab file. I don't know enough lua yet to get more specific, but you're going to have to get pretty familiar with lua anyway if you want to do much modding. My guess would be it's in the lines where you see ARM_carry and ARM_normal.

Share this post


Link to post
Share on other sites

So, I'm having the same problem as everyone else -- inventory and ground image works fine, item is equippable and everything, but when it's in my character's hand it's completely invisible. I tried the fixes described in this thread, including changing the folder structure and a few times completely redoing the spriter project from scratch, but nothing's worked. I feel like I'm missing something really obvious, here.

 

The particular prefab I'm having probelms with is 'smellyalater', a custom weapon I'm working on; for ease of uploading I've just included the whole mod. Any help would be greatly appreciated!

signless.zip

Edited by misterinkwell

Share this post


Link to post
Share on other sites

So, I'm having the same problem as everyone else -- inventory and ground image works fine, item is equippable and everything, but when it's in my character's hand it's completely invisible. I tried the fixes described in this thread, including changing the folder structure and a few times completely redoing the spriter project from scratch, but nothing's worked. I feel like I'm missing something really obvious, here.

 

The particular prefab I'm having probelms with is 'smellyalater', a custom weapon I'm working on; for ease of uploading I've just included the whole mod. Any help would be greatly appreciated!

 

Hi Misterinkwell. I've been the most recent one in this thread having these problems and so I've learned a lot about these little quirks. I'll try to help you out if I can. The first thing I notice is that when I installed your mod, and opened up the game to DebugSpawn the item, I noticed that the console says "Has no modinfo.lua: skipping" and "Has no modmain.lua: skipping". Here's a screenshot..

 

7383229_orig.jpg

 

Do you get the same things showing when you open your console? My Don't Starve has been acting strangely, so that particular issue could just be me, but let me know. I can't get it to spawn at all(for now, but I've just spent a couple minutes on it so far) so that's probably just some of the strange problems I'm having.

 

The next thing I notice is in your scml file, the path seems wrong from what I've learned.. I think? In the line -

 

<file id="0" name="swap_smellyalater.png" width="152" height="202" pivot_x="0" pivot_y="1"/>

 

I think it should be

 

<file id="0" name="swap_smellyalater/swap_smellyalater.png" width="152" height="202" pivot_x="0" pivot_y="1"/>

 

Are you having the same problem I am with Spriter where it will kick you into the subfolder when you try to save in the project folder?

 

Let me know, and let me know if any of this gets you anywhere. I'll look at it more in depth if not.

Edited by zeropoint101

Share this post


Link to post
Share on other sites

Yeah, I'm having that same problem with the folder kicking, so exported the scml while it was in the inner folder and then just moved everything up. When I tried to move the scml up first and then export, the command console said there was no image associated with the file, so I assumed that was why it was blank -- but apparently not.

 

I also just edited the scml the way you described (with the scml still in the upper folder) but the prefab's still showing up invisible for me. I also deleted the exported anim files, thinking it just needed to export from scratch rather than overwriting something, but no luck.

 

Also nope, it spawns in just fine for me. I used c_spawn("prefab") and DebugSpawn("prefab") and both worked. Sorry it took me a bit to get back to you, my game is running like molasses right now, which is weird because this is literally the only mod I have installed at the moment.

Edited by misterinkwell

Share this post


Link to post
Share on other sites

Yeah, I'm having that same problem with the folder kicking, so exported the scml while it was in the inner folder and then just moved everything up. When I tried to move the scml up first and then export, the command console said there was no image associated with the file, so I assumed that was why it was blank -- but apparently not.

 

I also just edited the scml the way you described (with the scml still in the upper folder) but the prefab's still showing up invisible for me. I also deleted the exported anim files, thinking it just needed to export from scratch rather than overwriting something, but no luck.

 

Also nope, it spawns in just fine for me. I used c_spawn("prefab") and DebugSpawn("prefab") and both worked. Sorry it took me a bit to get back to you, my game is running like molasses right now, which is weird because this is literally the only mod I have installed at the moment.

 

 

I think the new update patch relating to the just released DLC is causing a few people some minor issues. Might be why you're game is running slow. And I'm not sure why mine said you have no modmain.lua. or modinfo.lua. Must be whatever is causing my other weird glitches. Hopefully I can get that solved too soon.

 

Ok, so I'm not sure this will solve the problem yet. I'll try to look into it more, hopefully later tonight, but for the sake of info and understanding this better..

 

I think you're maybe having a similar bug, but not exactly the same(in Spriter). For me, when it would jump me to the inner folder, for some reason it would still place the path correctly in the scml file.. as if I had saved it in the correct place to begin with. That's why it would work for me to just move it up to the project folder after saving it in the inner folder. But it seems yours is NOT putting the proper path when it jumps you to the inner folder. So you'll have to watch for that in the future and tinker with the scml file itself I imagine.

 

So, as far as getting this to work... hmm... I'm glad you tried deleting the animation zips. It seems like sometimes this has been a problem for me too, so I pretty much do it every time I export now just to make sure, but I've had a hell of time zeroing in on what causes this weirdness. I will try to dive into it and actually tinker with things myself and see if I can't get it to work. Hopefully I can get to it tonight here in a bit, but I'm not sure. I'll get back to you as soon as I can.

 

Oh, one other thing you could try messing with in the meantime.. see how this line in my scml looks ..

 

<folder id="0" name="swap_rainbowflag">

 

In yours, that line just says

 

<folder id="0">

 

but your "ground" scml is the same way and you said the ground image is working fine for you.

Share this post


Link to post
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
Sign in to follow this