SetPiece

This tutorial is based on JackSlender‘s and  Kzisor‘s one on the Klei Forums

Introduction

This tutorial teaches how to make a custom setpiece (i.e. an already constructed chunk of land).  It is assumed that you already have your base mod (mod folder and modmain) set up.

Setting up the workspace

Launch the Don’t Starve Mod Tools, then launch Tiled.  This program is pretty powerful, but only basic useage is required for a SetPiece.

Go to File: New.  This should bring up a little popup window saying:

Map size (in width and height): Choose the dimensions in ground tiles (turfs).

Tile size (in pixels): set this to 64 x 64 (you can choose whatever you want, but the game will count 64 pixels for each tile. e.g. setting this to 16×16 means that four tiles equal one in-game tile)

Import a tileset like this one.  This is just the compilation of tiles used for the setpiece.

Select Map: Add External Tileset and not New Tileset.

Now navigate to the place where you extracted the .zip file, and select the .tsx file.  This is our tileset.  If it works properly, you should see some textures in the bottom right corner, in the tilesets tab.

Name the layers properly.  On the right-middle side, there should be a button titled Layers.  Click that, and above it there should be something titled Tile Layer 1.  Double click that and rename it to BG_TILES.  Then open the dropdown button next to or below it and select New Object Layer.  Name this layer FG_OBJECTS.  This is the last thing to set up the editor.

Constructing the SetPiece

Make some ground for the setpiece.  Make sure to select the BG_TILES layer, or this won’t work.  Put the cursor over the tile wanted (in the tileset, bottom-right corner) and click to select it. Next, spread it around the middle of the screen simply by clicking and dragging. (Keep in mind that tiles in Don’t Starve are 64×64, so if you set your tiles to 16×16 earlier, you now need to combine 4 tiles x 4 tiles for every in-game tile.)

Now create some objects.  Select the FG_OBJECTS layer.  Then select the objects tab below and click on the rectangle tool in the tool bar above.

Click where you want the object to be located in relation to the tiles placed earlier.  It should create a small, gray rectangle.  Right click the rectangle, and click Object Properties.  It should bring up a popup box.  Type in the name of the prefab you want to create in the type box.  Be careful: if you type it in the name box, it won’t work, so make sure to type it in the type box. Then press OK.  You can add as many objects as you like.

You can move objects by selecting the cursor tool in the tool bar above, and remove them by right-clicking and selecting delete.

It is recommended to save the work so you can modify it later. The most important part is exporting it under File: Export as...

This will export the file into code.  Make sure it is set to .lua when exported. Export it to /yourmodfolder/scripts/map/static_layouts/

Implementing the SetPiece

Add code to initialize it (add your setpiece to an existing biome).

This code should go into your modworldgenmain.lua, a file in the same location as your modmain.lua. Notice that the Example mod features a lot of functions that may seem complicated, but allow for more customization.

Making a Scenario

If you have added the property scenario (including the name of the file in scripts/scenarios, without .lua) to an object in the setpiece, you can link it to an scripted scenario!

When the scenario prefab gets loaded, so does the script. Said file should have the following structure: