Sign in to follow this  
Dancehero99

Making my first mod for DST

Recommended Posts

Dancehero99    1

Hello guys,

Today I started searching for information to make my own mod. It's a lot of fun but also very frustrating, though I'm barely a programmer. But I still want to try to make my own mod. I also want to learn to program better and I hope someone is able to help me trough some basics of modding. 

I want to make boots for Don't starve together. Wearing the boots should give for a movement speed. 

The following steps are what I want to achieve:

  1. First someone has to craft the boots.
  2. someone has to be able to put on the boots. 
  3. Someone is wearing the boots and walks faster. This is where my focus is on!
    1. When used, hunger will go down faster. 
  4. The boots have been used for 8 minutes and the player has to craft new ones.

I only want to focus on step 3. Can someone give me an idea what I should do to achieve my goal? In which file should I program this? I first want to make the person walk fast without boots on to get famliar with the code (for example), how can I do that?

 

I would like to hear some stuff :)) 

Fabian 

Share this post


Link to post
Share on other sites
Ultroman    699

Welcome to the world of Don't Starve modding! :D

There are a bunch of things you should do, in order to make your life easier going into this.

  • Get yourself a nice text editor. I use Notepad++ and can highly recommend it. Make sure to set the "Language" to "LUA" while you're coding LUA. That'll help you greatly in many ways. The "Find in files" function is also useful, for finding examples of code usage in the game-files.
  • Take a LUA Crash Course and perhaps do some more tutorials. It WILL save you LOADS of time and frustration.
  • Look in the FAQ for general information.
  • You'll find the game code scripts in:
    • DS: steamapps\common\dont_starve\data\scripts
      You'll find the new/changed data files for each DLC in: steamapps\common\dont_starve\data\DLC000#
    • DST: steamapps\common\Don't Starve Together\data\databundles\scripts.zip
      Unpack that somewhere far away from your game folder. In the "prefabs" folder you'll find all the entities in the game (players, items, creatures, bosses etc.). Some prefabs files hold more than one prefab, like spider.lua and cavespiders.lua which have several creature prefabs in them, and e.g. the amulet.lua and hats.lua which have several item prefabs in them. Everything in the game is made up of components, which are in a separate folder. Living creatures have brains (AI) and stategraphs (a collection of states they can be in and actions they can perform, which together determine how they operate. It also handles a lot of the waiting for and switching of animations etc. based on the actions performed) and these are in separate folders, as well. The UI-stuff is mostly found in the widgets folder.
  • Look at the amazing collection of modding tips and tutorials you can find in this forum section (DS) and this "getting started with modding guide" thread (DST). Both have some overlap between DS and DST. There are some for working with items, images and animations.
  • Learn the basics of the files involved in mods. I have a post here explaining the contents of modinfo.lua.
  • Some information about modicons.
  • To see how working mods are made, download a few mods, and look at their code. I can recommend this one for a simple TUNING-variable tweak, and CactusArmor.zip for a simple armor (although it is a DST mod, I think the code should work for both DS and DST, except the api_version in modinfo.lua).
  • When you're completely baffled by something, try to find a mod that does something very similar to what you're doing. You can usually figure out what they're doing which you aren't doing, or vice versa.

 

Searching the forum

"I know how to search a #%&€ forum!" Yeah, but this one is special. When using the search bar at the top, it defaults to searching all the forums, not just the modding forums, so you'll get search results for all Klei's games and all the forums they have, not just the modding forums. These are the two easiest ways I've found to search for modding threads. One (normal forum search) allows you to search exclusively for threads for one of the games, and is probably the most easily accessible, while the other method (advanced search) allows you to search for threads for both games (DS and DST) at the same time OR exclusively one of the games.

Normal modding forum search, when searching exclusively for DS or DST, but NOT BOTH:

Advanced modding forum search, when you don't care whether the thread is for DS or DST:

  • Click the search-bar at the top of the page
  • Click the button that appears to the left of it and choose "Advanced Search"
  • Select "Topics" on the left
  • In the "Forums" dropdown below, scroll downwards and select BOTH
    [Don't Starve Together] Mods and Tools
    and
    [Don't Starve] Mods and Tools
    from the list.
    The content is kind of muddled together between the games, despite the mods trying their best to keep them separate, but much of the code can be used for either game. Just be aware that there are differences between the two games, and that you might sometimes need to make slight changes or even take a completely different approach for certain functionality between the games. If you want to be at least almost sure not to have this problem, only select the forum for the game you are modding for.
  • Then type in your search at the top, and press Enter or the magnifying glass

 

Debugging

In order to see the full error log, which has more information than the game has room on the screen to show you, and also shows what might have lead to the error, you need to look at the game logs.

For DS there's only one log. It's called "log.txt" and it's right here:

<SystemDriveLetter>:\Users\<UserName>\Documents\Klei\DoNotStarve

For DST, there are two "types" of logs.

If your game crashed while playing, the error is most likely found in your server_log.txt file(s). If your server has caves in it, there will be a server_log.txt for both the regular server "shard" and the caves server "shard". You can find those files here:

<SystemDriveLetter>:\Users\<UserName>\Documents\Klei\DoNotStarveTogether\Cluster_#
(# = 1-5; this is the placement of your server on the list of servers in-game)

In that folder, you will find a "Master" folder and perhaps also a "Caves" folder. Both should have a server_log.txt in them.

There is also a client_log.txt. If the game dies in the main menu or while loading the game or on the character select screen, in which case there might not be any server_log.txt files, you can still find the client_log.txt file here:

<SystemDriveLetter>:\Users\<UserName>\Documents\Klei\DoNotStarveTogether

These files are crucial for us to help you, when you're asking how to fix a crash. Attach those files to your crash post, by dragging and dropping them onto the reply you are about to submit, and if you suspect that it's your mod causing it, also post a zip of your mod.

You can also use those files to your advantage when debugging your mod. If something in your mod is not working, or even if it is crashing during play, you can give yourself lots of hints and information about what code is actually being executed and which parts are not. You do this by using print-statements, like shown below. These print-statements show up in the client_log.txt, which you can even look at while the game is playing (Notepad++ should automatically ask you to reload the file if you come back to it after it has been changed, but not always!!).

-- Simple print just to show if a function was called.
print("MyFunction was called")

-- Printing numbers
print("Current sanity value: "..inst.components.sanity.current)

-- Printing booleans. To print booleans (true/false) you MUST wrap the boolean in a tostring() call,
-- to tell LUA to convert it to a string.
-- Example 1:
print("My value is higher than 100: "..tostring(myvalue > 100))

-- Example 2:
local isMyFeatureOn = true
print("Feature is on: "..tostring(isMyFeatureOn))

You can really use print-statements to great advantage. If you're unsure why your mod isn't working, just slap in print-statements in all the functions and have them print out "<function name> was called", and follow the trail in the log and your code side-by-side. Add in some extra print-statements to make sure your variables are set to what you expect, and I can almost guarantee you, that you will find out what is going wrong.


Speaking of your mod (irrelevant for those who did not post this thread)

It sounds awesome, but from what I understand you want to add an extra equipment slot for boots. That's going to be a tough one, but it can be done. The problem is, there are already quite a few very popular mods which add equipment slots for e.g. amulets, so you'd be fighting with those. It might be easier to begin with, to simply make your boots add movementspeed whenever they are put into someone's inventory who has a locomotor-component, and remove it again when it leaves their inventory. You can do this by adding an external speed multiplier to the locomotor-component of the carrier.

Making them lose durability while they're being used is also definitely doable.

If I were you, I'd concentrate on getting the item's basic stuff working first, so they are visible on the ground, and can be picked up and put in the inventory where they are also visible. Setting up a recipe for them is not hard either, and is good practice. Those things are already challenging for newcomers. Sadly, I don't think you can make them actually show on the character when equipped, but I can't be sure. I haven't dabbled a lot in graphics and animations for this game.

There are plenty of threads on the forum about making items and solving problems with animations, so you should have no trouble finding information about that.

Edited by Ultroman

Share this post


Link to post
Share on other sites
Dancehero99    1

Wow thank you for your comment, that's really awesome!

It's a good idea to not focus on the character visibly wearing the boots! That's kinda an eyer opener for me (my English vocabulaire is not so great, sorry). 

I actually already have notepad++ and I am able to upload my future mod to steam too. In fact, you can already download it, but there is no code in it yet. To change the settings in my notepad++ is a really good idea, I will defenitely do that. 

I'm very grateful for your tips. I will look into the LUA crash course and all the other links you posted. 

I would like to post more questions when I'm stuck in the future (I will be), do I post those question on this topic or do I make a new one?

Have a great day,

Fabian 

 

Share this post


Link to post
Share on other sites
Ultroman    699

Always make a new topic, and try to stick to a few related questions at a time. Never try to bite off too much at a time. It also usually leads to long-winded and confusing threads, which makes them less helpful when people find them in the future while looking for help.

Always remember to attach a zip of your mod, as well, and be very clear in what you want to achieve, and what your problem is. The more information we have, the better we can help you.

I'll just add another point to the guide above, about how to debug your mod and see the reasons for a crash.

Share this post


Link to post
Share on other sites
Ultroman    699

There you go. I wrote some stuff about debugging e.g. log files and print-statements. People are so surprised when I mention print-statements, but they're crucial for figuring out what exactly is going on.

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