Jump to content

[TUTORIAL] Making a Custom SetPiece


JackSlender
 Share

Recommended Posts

Hey, guys, this tutorial is for people who would like to make a custom setpiece (i.e. a pre-generated chunk of land), but don't know the specifics of it.  The tutorial will be kind of long and elaborate, but hopefully it will be helpful.  It will require basic modding knowledge, and it is assumed that you already have your base mod (mod folder and modmain) set up.  Now let's start.

First half (setting up all of the properties):

So, first we need to set up the proper program.  First things first, launch the Don't Starve Mod Tools.  You're going to need to launch Tiled.  Now this program is pretty powerful, but I'm only going to go over what you need to know.  You need to go to File, New.  This should bring up a little popup window like this:

post-343838-0-47706200-1394487164_thumb.

As the picture says, the two values on the left are the tile size of the setpiece.  We are going to set those to five for now.  The values on the right are the tile size.  Set those to sixty-four.  That will set up the basic map properties.

Now, we need to import the tileset.  This is just the compilation of tiles we use for our setpiece.  You'll actually have to download this for it to work:

tileset.zip

Now (if you've downloaded it) extract it to a familiar location such as your desktop.  Now go back into Tiled.  Select Map, Add External Tileset and not New Tileset.

post-343838-0-10745800-1394487167_thumb.

Now navigate to the place where you extracted the .zip file, and select ground.tsx.  This is our tileset.  If this works properly, you should see this in the bottom-right corner of your program:

post-343838-0-19402300-1394487170_thumb.

Next, we need to name our layers properly.  On the left-middle side, you should see a button titled Layers.  Click that, and above it you should see something titled Tile Layer 1.  Double click that and rename it to BG_TILES.  Next you should click this button:

post-343838-0-14896500-1394487176_thumb.

And select New Object Layer.  Name this layer FG_OBJECTS.  This is the last thing we need to do to set up the editor.  Now we move on to creating the actual tiles and objects.

Second half (building the setpiece)

Now that we're all set up, we need to make some ground for our setpiece.  Make sure to select the BG_TILES layer, or this won't work.  Put your cursor over the tile you want (in the bottom-right corner) and click to select it.  For the sake of simplicity, I'll use grass.  Next, spread it around the middle of the screen simply by clicking and dragging.  It should hopefully look something like this:

post-343838-0-85633200-1394487172_thumb.

Wonderful, now we need to create some objects!  So you will need to select the FG_OBJECTS layer.  Make sure to highlight both of these, top one first:

post-343838-0-60216900-1394487178_thumb.

And click up here on this little rectangle thingy.

post-343838-0-00839800-1394487181_thumb.

Now, just click where you want the object to be located in relation to the tiles you placed earlier.  It should create a small, gray rectangle where you clicked.  Now, you should right click the rectangle, and click Object Properties.  It should bring up a little popup box.  Now type in the name of the prefab you want to create in the type box (I'm going to use researchlab so it stands out).  BE CAREFUL: if you type it in the name box, it WON'T WORK, so make sure to type it in the TYPE box.  I speak from experience, don't make that mistake.  After you've typed the name of your prefab in, press OK.  You can add as many objects as you like but for the sake of simplicity, I'll leave mine at one.

Once you're done with that, you're finally done (finally).  You should definitely save your work so you can modify it later, but the most important part is exporting it:

post-343838-0-77199100-1394487183_thumb.

This will export the file into code.  MAKE SURE it is set to .lua when you export it.  You need to export it to /yourmod/scripts/map/static_layouts/

That is where your setpieces will go.  I'm going to call mine rl (research lab).  At last, we are done.  With most of it.

 

Now all you need is to add a little bit of code to initialize it.  To finish, I'm going to show you how to add your setpiece to a biome (won't be making the biome).  Here's the code:

local Layouts = GLOBAL.require("map/layouts").Layoutslocal StaticLayout = GLOBAL.require("map/static_layout")Layouts["ResearchLab"] = StaticLayout.Get("map/static_layouts/rl")AddRoomPreInit("Forest", function(room)	if not room.contents.countstaticlayouts then		room.contents.countstaticlayouts = {}	end	room.contents.countstaticlayouts["ResearchLab"] = 1end)

This code should go into your modworldgenmain, a file in the same location as your modmain.  If you do all of that, you should get something like this:

post-343838-0-11415700-1394488587_thumb.

And voila!  You should have a working setpiece!  I apologize if this tutorial was hard to follow, but please tell me in the comments if you think I can edit it or make it better.  Thank you for reading!

setpiecemod.zip

  • Like 11
  • Big Ups 1
  • Potato Cup 1
Link to comment
Share on other sites

Hey, I know it's been a while, but can you break down the code you wrote in the tutorial for making set pieces?

 

1
2
3
4
5
6
7
8
9
10
11
local Layouts = GLOBAL.require("map/layouts").Layouts
local StaticLayout = GLOBAL.require("map/static_layout")
 
Layouts["ResearchLab"] = StaticLayout.Get("map/static_layouts/rl")
 
AddRoomPreInit("Forest", function(room)
    if not room.contents.countstaticlayouts then
        room.contents.countstaticlayouts = {}
    end
    room.contents.countstaticlayouts["ResearchLab"] = 1
end)

 

What is the "ResearchLab" in line four? What other biomes can I write in place of "forest". Would "Marsh" work?

What would you write instead if you had a set piece of 4 Pig Houses, named "ph" set to appear in the deciduous forest? Rockyland?

 

I'm new at this and really just want to add more set pieces to the game. Is there a way of forcing the spawn of a particular set piece, in the way you did for your screenshot?

  • Health 1
Link to comment
Share on other sites

Hey, I know it's been a while, but can you break down the code you wrote in the tutorial for making set pieces?

 

local Layouts = GLOBAL.require("map/layouts").Layouts
local StaticLayout = GLOBAL.require("map/static_layout")
 
Layouts["ResearchLab] = StaticLayout.Get("map/static_layouts/rl")
 
AddRoomPreInit("Forest", function(room)
    if not room.contents.countstaticlayouts then
        room.contents.countstaticlayouts = {}
    end
    room.contents.countstaticlayouts["ResearchLab] = 1
end)

 

What is the "ResearchLab" in line four? It's the name of the setpiece in the world generator. rl is the actual file, without extra information. What other biomes can I write in place of "forest". Would "Marsh" work? It should, try it out.

What would you write instead if you had a set piece of 4 Pig Houses, named "ph" set to appear in the deciduous forest? Rockyland?

 

Layouts["MyPigClan] = StaticLayout.Get("map/static_layouts/ph")
 
AddRoomPreInit("WhateverThatForestIsCalledInTheGame", function(room)
    if not room.contents.countstaticlayouts then
        room.contents.countstaticlayouts = {}
    end
    room.contents.countstaticlayouts["MyPigClan] = 1
end)

 

I'm new at this and really just want to add more set pieces to the game. Is there a way of forcing the spawn of a particular set piece, in the way you did for your screenshot? It's already forced I think It spawns as often as you set it.

 

I wrote in green. Any questions?

Also, did you know you can instead add an entire biome with random layout, but fixed prefabs? If that'd be better to you, send me a message and I send you a sample code back.

  • Like 1
Link to comment
Share on other sites

Line four defines researchlab as a static layout that uses the file rl as the base (rl is the Tiled file stored in map/static_layouts).  To get the setpiece to spawn in a different biome, just change "Forest" to the name of the other biome.  For the names of biomes, I would dig around in map/rooms as that is where they're stored.  Hope this helps!

Link to comment
Share on other sites

Hey, thanks for your awesome tutorial!!

 

I had two questions regarding it - first, if you wanted a prefab to spawn in the cave or ruins layer of the world, where could you specify that? or would that just be decided by the first argument to AddRoomPreInit, the biome?

secondly, does the 'tileset' image you provided include the underground turfs? and if not, would you have any idea how to define them for the program? thanks a lot!!!


Hey, thanks for your awesome tutorial!!

 

I had two questions regarding it - first, if you wanted a prefab to spawn in the cave or ruins layer of the world, where could you specify that? or would that just be decided by the first argument to AddRoomPreInit, the biome?

secondly, does the 'tileset' image you provided include the underground turfs? and if not, would you have any idea how to define them for the program? thanks a lot!!!

Link to comment
Share on other sites

To get it to appear in the underground biomes, you just have to specify an underground room.  As for the underground turfs, I'll look into it if I have time.  I actually got these from one of the DS mods, Cheerio I believe, so I didn't actually put them together.  I'll try though.

Link to comment
Share on other sites

No intent to step on toes or anything, but I had to patch the StaticLayout to support custom tiles a few weeks ago so thought I should chime in. The transformation between tiled's ids (and in effect, tiled.png images) and the ground types is being managed by StaticLayout.Get (which is actually ConvertStaticLayoutToLayout). Instead of directly using GROUND numbers, it uses separate ids, that are dependent on the order in ground_types table in said function.

 

Now, what it all means is, to add cave tiles you would just need to add more 64x64 tiles into the tiles.png (or whatever the other one is called, I used that one coz its easier to edit) in the same order as the ground_types order.

 

That also means that, to add DLC ones, or custom tiles, you need to override the table itself (which is luckily returned as ref too from ConvertStaticLayoutToLayout so that's not much of an issue). Doing so is subject of same (collision) issues as adding custom ground types in general, but that's another story.

Link to comment
Share on other sites

thanks! in that case, is downloading/referencing tiles.png,as seen on this line in  mysetpiece.lua, even required?

image = "../../../layout_source/dont_starve/tiles.png", 

because if all that's needed is the index of the ground type i want, why bother referencing an external .png anyway? as far as i can see, the 11 64x64 tiles in the tiles.png file provided with this tut don't have the same texture as their in-game counterparts anyway, so what does referencing them actually do?

any help with increasing my understanding of all this is greatly, greatly appreciated :)

Link to comment
Share on other sites

haha ok i probably should have done a little more of my own experimentation before asking that - turns out that yes, if you use a tile index that would be out of range for the tiles.png file provided, dont starve will still accept and place it.

 

my next question, which i believe was asked and unresolved by somebody else in another thread, is how would one ensure only a single of their custom set pieces spawned in each world? as awesome as your code is, it spawn an extremely large amount of the pieces.... im trying to mod an item similar to chester's bone or glommer's statue into the world. 

 

thank you very much for any help!! :)

Link to comment
Share on other sites

Referencing is tmx files is necesary for one reason only - tiled itself doesnt work without the file, it is using the 64x64 to let you place the 'reference' to ingame ids. Wether the images are appropriate, tiled doesnt know or care. Technically, you could use e.g. dirt in tiled (id=4) and export to lua and just replace all 4s with i guess 12 is the default cave one inside lua itself. It would be suboptimal (and highly annoying if you want to change it in the future) but certainly possible.

 

As for spawning just single one, you should probably just change level, e.g. what I do with my set pieces is tie them to particular tasks - in which you want them to spawn, if you want just 1 then id make sure that at least one task is mandatory.  Or you could add it to ordered_story_setpieces, that 'should' enforce it spawns just once, but then it can spawn anywhere which might or might not be what you want. In both cases, you may want to use SURVIVAL_DEFAULT and SURVIVAL_DEFAULT_PLUS so that if someone fires plus mode he doesn't end up left out.

 

Or you can make a room, put set piece in room, then add room to AddTaskPreInit into a mandatory task - or make a task for it, whatever, depending on how/where you want to position the thing.

 

 

  • Like 1
Link to comment
Share on other sites

JackSlender, hi.

I'm new here, started to develop and see multiple posts regarding this pop-up. I though I rather ask in here than around.
Could you please confirm, that you'r "mod" actually do spawn multiple instances of this in your world?
I did follow but I see my setpiece everywhere! (20-30 times).

Could any of you guys, explain to me if this static layout contra layout has anything to do with how it does appearance ? (random sampled or "perfect" as comitted in tiles).

I'm having a hard time figuring out if they spawn random generated to the world around or if I can prevent that and do it more "static".
Sorry if im mixing up terms here, please enlight my world. :-)

Thanks !

Link to comment
Share on other sites

Hey, IPO, welcome to the forums!  What this tutorial helps you do is create a little, pre-defined area of land that you can scatter through your world (think of the touchstones).  If you want to create something more like the teleportato piece locations (only one spawns throughout your world), you'll need to add a levelpreinit or a levelpreinitany based on whether or not you want it only to appear in one level or not.  What are you trying to do?  I could give you code, but it may be easier to tell you exactly what you need to do and why.  Thanks, JackSlender

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