JackSlender Posted March 10, 2014 Share Posted March 10, 2014 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: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.zipNow (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.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: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: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: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:And click up here on this little rectangle thingy.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: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: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 11 1 1 Link to comment Share on other sites More sharing options...
UnderwearApp Posted March 11, 2014 Share Posted March 11, 2014 Nice tutorial, will be using this in the future. Link to comment Share on other sites More sharing options...
Desblat Posted March 11, 2014 Share Posted March 11, 2014 Good job, even if Idk where to use it. Link to comment Share on other sites More sharing options...
EmielRegis Posted March 11, 2014 Share Posted March 11, 2014 Thx, its very usefull. Link to comment Share on other sites More sharing options...
Dryicefox Posted March 12, 2014 Share Posted March 12, 2014 Can we get this stickied? @Ipsquiggle Link to comment Share on other sites More sharing options...
JackSlender Posted March 15, 2014 Author Share Posted March 15, 2014 Thank you for the good feedback. If there's anything I can do to make this better, feel free to tell me and I'll try to fix it. Link to comment Share on other sites More sharing options...
DaSi14 Posted July 17, 2014 Share Posted July 17, 2014 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? Link to comment Share on other sites More sharing options...
Mobbstar Posted July 17, 2014 Share Posted July 17, 2014 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").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) 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] = 1end) 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. 1 Link to comment Share on other sites More sharing options...
JackSlender Posted July 17, 2014 Author Share Posted July 17, 2014 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 More sharing options...
MigratoryCoconuts Posted October 5, 2014 Share Posted October 5, 2014 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 More sharing options...
MigratoryCoconuts Posted October 5, 2014 Share Posted October 5, 2014 sorry, that appeared twice for some reason....... i cant find the edit button anywhere either, i probably need to have posted more to unlock it? Link to comment Share on other sites More sharing options...
JackSlender Posted October 5, 2014 Author Share Posted October 5, 2014 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 More sharing options...
DeathDisciple Posted October 5, 2014 Share Posted October 5, 2014 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 More sharing options...
MigratoryCoconuts Posted October 5, 2014 Share Posted October 5, 2014 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 More sharing options...
MigratoryCoconuts Posted October 5, 2014 Share Posted October 5, 2014 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 More sharing options...
DeathDisciple Posted October 5, 2014 Share Posted October 5, 2014 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. 1 Link to comment Share on other sites More sharing options...
JackSlender Posted October 6, 2014 Author Share Posted October 6, 2014 Thanks, DeathDisciple. I knew how the tile to png conversion worked, but I had no motivation to add the cave tiles as my mods have nothing to do with caves. Thanks for answering the question, though. Link to comment Share on other sites More sharing options...
MigratoryCoconuts Posted October 6, 2014 Share Posted October 6, 2014 yeah, thank you to both of you! you've been extremely helpful i'll admit DeathDisciple's advice on single spawns went over my head a bit, but with some mucking round i should be able to figure some stuff out Link to comment Share on other sites More sharing options...
IPO Posted October 12, 2014 Share Posted October 12, 2014 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 More sharing options...
JackSlender Posted October 14, 2014 Author Share Posted October 14, 2014 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 More sharing options...
seronis Posted February 16, 2015 Share Posted February 16, 2015 Curious if this tutorial is still accurate or not. Link to comment Share on other sites More sharing options...
Kzisor Posted February 20, 2015 Share Posted February 20, 2015 @seronis, yeah it's still accurate. However, it's missing a lot of information. Link to comment Share on other sites More sharing options...
JadeKnightblazer Posted February 25, 2015 Share Posted February 25, 2015 Looked around the whole thread, what does the number at the end do?room.contents.countstaticlayouts["ResearchLab"] = 1I wish to make a setpiece that only spawns once in the world, much like the pigking. Link to comment Share on other sites More sharing options...
Kzisor Posted February 25, 2015 Share Posted February 25, 2015 @JadeKnightblazer, that makes it spawn once per room. Link to comment Share on other sites More sharing options...
JadeKnightblazer Posted February 25, 2015 Share Posted February 25, 2015 (edited) So leaving it at 1 will do the trick then? Nope, it spawns quite a bit T_T... hmm. Edited February 25, 2015 by JadeKnightblazer Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now