Jump to content

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


Malacath
 Share

Recommended Posts

Can you give some more info. Like a crash log or maybe upload your file?

The game doesn't crash, the mod does appear in my mod selection screen, just when I try to spawn it in, it doesnt appear, (apparently the game doesn't recognise the prefab "violin" (which is my item))

Link to comment
Share on other sites

Couple of things you should really change:

  1. Your modmain.lua file goes into you main folder and not your prefab folder.
  2. (Expands on the first point) Your file structure should be similar to the games file structure. Look at other mods for an example.
  3. Some of your code that you put in your modmain should be in your prefab file so I guess your prefab file would be called "violin" and most of the code you have should be in there.

Use this for an example mod and just change the code and images around.

Edited by BaconAndRibs
Link to comment
Share on other sites

Couple of things you should really change:

  1. Your modmain.lua file goes into you main folder and not your prefab folder.
  2. (Expands on the first point) Your file structure should be similar to the games file structure. Look at other mods for an example.
  3. Some of your code that you put in your modmain should be in your prefab file so I guess your prefab file would be called "violin" and most of the code you have should be in there.

Use this for an example mod and just change the code and images around.

Hmm, for some reason the game still doesn't let me spawn in the violin, even when i type in 'wand'.

Edited by NeddoFreddo
Link to comment
Share on other sites

Is it in a zip file or maybe upload two folders? If you are unable to upload it then I can't do much to help but the only thing I can think of is replacing the images and scml files in the example mod and change the code. You just change the names around and see if it works out. That's what modding involves, making mistakes and trying to find where you made the mistake.

Link to comment
Share on other sites

Is it in a zip file or maybe upload two folders? If you are unable to upload it then I can't do much to help but the only thing I can think of is replacing the images and scml files in the example mod and change the code. You just change the names around and see if it works out. That's what modding involves, making mistakes and trying to find where you made the mistake.

Ok here it is.Violin.zip

Link to comment
Share on other sites

Ok here it is.attachicon.gifViolin.zip

 

Uh, I tested out your mod, and I can spawn the violin just fine. 

 

How are you trying to spawn the item in? Are you typing:  c_spawn("violin", 1)  into the console? Because it works fine when I do that.

 

The only other thing off about it is it says "MISSING NAME" when you hover your mouse over the violin. (you can fix that by adding this into your violin.lua file;

STRINGS.NAMES.VIOLIN = "Violin"
Link to comment
Share on other sites

 

Uh, I tested out your mod, and I can spawn the violin just fine. 

 

How are you trying to spawn the item in? Are you typing:  c_spawn("violin", 1)  into the console? Because it works fine when I do that.

 

The only other thing off about it is it says "MISSING NAME" when you hover your mouse over the violin. (you can fix that by adding this into your violin.lua file;

STRINGS.NAMES.VIOLIN = "Violin"

Yes, I typed that exact thing (like I always do!) Also turns out it did't work for me because the whole thing was inside another folder (like there were 2 violin folders.)

The inventory image is still the one of the deafault mod, can u help?

This was originally designed to be part of a character mod, and I wanted to give it the effects of a pan flute and add a crafting recipe. (btw i have already made the character http://steamcommunity.com/sharedfiles/filedetails/?id=486052508)

Sorry to bother you.

Edited by NeddoFreddo
Link to comment
Share on other sites

Yes, I typed that exact thing (like I always do!) Also turns out it did't work for me because the whole thing was inside another folder (like there were 2 violin folders.)

The inventory image is still the one of the deafault mod, can u help?

This was originally designed to be part of a character mod, and I wanted to give it the effects of a pan flute and add a crafting recipe. (btw i have already made the character http://steamcommunity.com/sharedfiles/filedetails/?id=486052508)

Sorry to bother you.

 

Hm, the image inside the inventoryimages/violin.tex Is still the image of the wand.

 

Do you have Steam's "Don't Starve Mod Tools" installed? If you install that, it should take care of exporting all your .png images to their .xml and .tex versions for you.

 

To install it; open up steam and open the "library" tab and click "tools", and find Dont Starve Mod Tools, and install it.

 

Now whenever you run Dont Starve, the steam autocompiler will take all the .png images in your folders and export them and do all that stuff for you.

 

If that doesnt work, you could always do it the old fashioned way.

Link to comment
Share on other sites

Hm, the image inside the inventoryimages/violin.tex Is still the image of the wand.

 

Do you have Steam's "Don't Starve Mod Tools" installed? If you install that, it should take care of exporting all your .png images to their .xml and .tex versions for you.

 

To install it; open up steam and open the "library" tab and click "tools", and find Dont Starve Mod Tools, and install it.

 

Now whenever you run Dont Starve, the steam autocompiler will take all the .png images in your folders and export them and do all that stuff for you.

 

If that doesnt work, you could always do it the old fashioned way.

Thanks, I just ran the autocompiler again. and replaced the image. I figured out how to add it to my character, and did, but could you please give me some tips on how to make it work like a panflute/

Thanks

Edited by NeddoFreddo
Link to comment
Share on other sites

Thanks, I just ran the autocompiler again. and replaced the image. I figured out how to add it to my character, and did, but could you please give me some tips on how to make it work like a panflute/

Thanks

Yea, I recently made a similar item so I can help.

You can basically just copy most of the code from the panflute's files into your own and it should work. Do you know where to find the game files for don't starve?

The panflute is also a prefab, so look for the prefabs folder, and you should find it in there.

Link to comment
Share on other sites

Yea, I recently made a similar item so I can help.

You can basically just copy most of the code from the panflute's files into your own and it should work. Do you know where to find the game files for don't starve?

The panflute is also a prefab, so look for the prefabs folder, and you should find it in there.

Thanks, but I am having problems with the character for some reason. Where do i put all the violin files if I want it to be part of the character? I have tried to put it in the anim folder, would the main folder work?

Link to comment
Share on other sites

Thanks, but I am having problems with the character for some reason. Where do i put all the violin files if I want it to be part of the character? I have tried to put it in the anim folder, would the main folder work?

If you want it to be part of the character, everything should be part of one mod instead of two seperate mods. So they both need to be in the same mod folder.

 

you can do this by just copying and pasting all of the files from the violin mod to their respective folders in your character mod, and changing the modmain.lua a bit.

 

 

So take both of the files in your mods/violin/anim folder (violin.zip and swap_violin.zip)  and paste them into the anim folder of your character's mod; mods/wilfred/anim  (assuming your mod folder is named wilfred.)

So you should have the anim files for both your character and the violin in the same anim folder.

 

now you do the rest with the other folders; exported, images, and scripts.

 

copy everything inside your violin/exported folder (the two folders), and paste them in wilfred/anim.

And copy the one folder inside violin/images, and paste it in wilfred/images.

now copy violin.lua from violin/scripts/prefabs, and paste it in wilfred/scripts/prefabs.

 

And that should be it.

 

Now, since there can only be one modmain.lua, you cant just copy and paste it into the folder. You need to change the existing modmain.lua to include your code along with it. and since your voilins modmain.lua is only 3 lines, you'll literally only have to add one word to wilfred's modmain.lua to include it. (I think)

in wilfred's modmain.lua, find where you added the prefabs. its probably something like 

PrefabFiles = {    "wilfred",}

Just add the violin pefab and a comma to that line like this;

PrefabFiles = {    "wilfred", "violin",}

and thats it.

I'm pretty sure you dont need to do anything with the modinfo.lua

 

to make him spawn with it, just add it to the startng inventory code, just like you did with the one man band.

 

 

and that should work! (don't forget to disable your other violin mod before running it, because it'll crash if you have two mods adding the same prefab into the game)

Link to comment
Share on other sites

If you want it to be part of the character, everything should be part of one mod instead of two seperate mods. So they both need to be in the same mod folder.

 

you can do this by just copying and pasting all of the files from the violin mod to their respective folders in your character mod, and changing the modmain.lua a bit.

 

 

So take both of the files in your mods/violin/anim folder (violin.zip and swap_violin.zip)  and paste them into the anim folder of your character's mod; mods/wilfred/anim  (assuming your mod folder is named wilfred.)

So you should have the anim files for both your character and the violin in the same anim folder.

 

now you do the rest with the other folders; exported, images, and scripts.

 

copy everything inside your violin/exported folder (the two folders), and paste them in wilfred/anim.

And copy the one folder inside violin/images, and paste it in wilfred/images.

now copy violin.lua from violin/scripts/prefabs, and paste it in wilfred/scripts/prefabs.

 

And that should be it.

 

Now, since there can only be one modmain.lua, you cant just copy and paste it into the folder. You need to change the existing modmain.lua to include your code along with it. and since your voilins modmain.lua is only 3 lines, you'll literally only have to add one word to wilfred's modmain.lua to include it. (I think)

in wilfred's modmain.lua, find where you added the prefabs. its probably something like 

PrefabFiles = {    "wilfred",}

Just add the violin pefab and a comma to that line like this;

PrefabFiles = {    "wilfred", "violin",}

and thats it.

I'm pretty sure you dont need to do anything with the modinfo.lua

 

to make him spawn with it, just add it to the startng inventory code, just like you did with the one man band.

 

 

and that should work! (don't forget to disable your other violin mod before running it, because it'll crash if you have two mods adding the same prefab into the game)

Hey, thanks so much, but when I moved all of the violin components into wilfred's folders, the panflute thing never worked afterwards. (i mean that it was not putting things to sleep.) Can you please help?

And yeah, thanks for all the help, I probably sound like a complete noob asking all these questions. 

Edited by NeddoFreddo
  • Like 1
Link to comment
Share on other sites

Hey, thanks so much, but when I moved all of the violin components into wilfred's folders, the panflute thing never worked afterwards. (i mean that it was not putting things to sleep.) Can you please help?

And yeah, thanks for all the help, I probably sound like a complete noob asking all these questions. 

 

Yea, I can help. you'll need to be more specific about what you need though, or show me your code so I can see what you're doing d:

 

It's okay, a lot of people here are. I've only been here 3 weeks. There really is a lack of the basic introductory programming tutorials for don't starve. The only way most people can do it is by looking at the game's code or code from other people's mods.

Link to comment
Share on other sites

Yea, I can help. you'll need to be more specific about what you need though, or show me your code so I can see what you're doing d:

 

It's okay, a lot of people here are. I've only been here 3 weeks. There really is a lack of the basic introductory programming tutorials for don't starve. The only way most people can do it is by looking at the game's code or code from other people's mods.

I wanted to make the violin act like a panflute, i.e. putting things to sleep on use.

I've got the violin to do some of the panflute things, when you hover over it in your inventory, it shows the option to rightclick and play, but when you right click nothing actually happens.

I'll upload the code so you can take a look at it. 

 

This might seem a little weird, but I think the violin will be wwwaaayyyy to op. I wanted to add this thing where there is a one in ten chance that when you play the violin, it will play a 'bad note' where birds will fly away and anything that can attack you will. (attack you.)

I think that that is a little complicated, if you can help thanks but if you can't don't worry.

 

I also wanted to add a examination quote for wilfred, do you know how?

Thanks

violin.lua

Edited by NeddoFreddo
Link to comment
Share on other sites

I wanted to make the violin act like a panflute, i.e. putting things to sleep on use.

I've got the violin to do some of the panflute things, when you hover over it in your inventory, it shows the option to rightclick and play, but when you right click nothing actually happens.

I'll upload the code so you can take a look at it. 

 

This might seem a little weird, but I think the violin will be wwwaaayyyy to op. I wanted to add this thing where there is a one in ten chance that when you play the violin, it will play a 'bad note' where birds will fly away and anything that can attack you will. (attack you.)

I think that that is a little complicated, if you can help thanks but if you can't don't worry.

 

I also wanted to add a examination quote for wilfred, do you know how?

Thanks

 

Ah, I remember had this same problem when I was working on mine as well. It turns out it needs to have the Flute tag, otherwise it wont play. just add;  inst:AddTag("flute")   somwhere in the item's main fn function.

 

But also there is a problem with TUNING.VIOLIN_SLEEPRANGE, because the violin doesnt have a defined "sleeprange", so it will crash the game if you try to play it. 

 

See; when you see something in the code like TUNING.SOMETHINGINALLCAPS, it's actually just taking a number in the game's tuning.lua file. But you can just replace it with your own number and it will work exactly the same.

just type the number 10 in place of TUNING.VIOLIN_SLEEPRANGE, and it will have a range of 10 feet. (or meters or whatever)

 

same thing with this line

inst.components.sleeper:AddSleepiness(5, TUNING.VIOLIN_SLEEPTIME)

replace it with whatever number you want

inst.components.sleeper:AddSleepiness(5, 20)

this will make them fall asleep for 20 seconds

 

 

also, yea. For description, you can put this right underneath where you defined what it's name was;

STRINGS.CHARACTERS.GENERIC.DESCRIBE.VIOLIN = "whatever you want here, in quotes"
  • Thanks 1
Link to comment
Share on other sites

 

Ah, I remember had this same problem when I was working on mine as well. It turns out it needs to have the Flute tag, otherwise it wont play. just add;  inst:AddTag("flute")   somwhere in the item's main fn function.

 

But also there is a problem with TUNING.VIOLIN_SLEEPRANGE, because the violin doesnt have a defined "sleeprange", so it will crash the game if you try to play it. 

 

See; when you see something in the code like TUNING.SOMETHINGINALLCAPS, it's actually just taking a number in the game's tuning.lua file. But you can just replace it with your own number and it will work exactly the same.

just type the number 10 in place of TUNING.VIOLIN_SLEEPRANGE, and it will have a range of 10 feet. (or meters or whatever)

 

same thing with this line

inst.components.sleeper:AddSleepiness(5, TUNING.VIOLIN_SLEEPTIME)

replace it with whatever number you want

inst.components.sleeper:AddSleepiness(5, 20)

this will make them fall asleep for 20 seconds

 

 

also, yea. For description, you can put this right underneath where you defined what it's name was;

STRINGS.CHARACTERS.GENERIC.DESCRIBE.VIOLIN = "whatever you want here, in quotes"

Thank you so much, it worked!

Is there a way to change the animation so the violin does not look like a pan flute when I play it?

If not, it doesn't matter too much. (OK it does matter alot but if you don't know how it's fine)

Link to comment
Share on other sites

Thank you so much, it worked!

Is there a way to change the animation so the violin does not look like a pan flute when I play it?

If not, it doesn't matter too much. (OK it does matter alot but if you don't know how it's fine)

 

As I've just recently found out for myself, custom animations are crazy complicated and difficult to make. If you manage to make the animation in spriter, I could probably show you how to put it into the game, since I'm currently working on doing that with my own mod right now d:

 

I don't know if there is a way to just change the picture of the panflute to a violin in the animation, if that's what you were wondering. 

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