JackSlender

[TUTORIAL] Making a Custom SetPiece

Recommended Posts

DaSi14    0

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?

Share this post


Link to post
Share on other sites
Mobbstar    13,390

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

Share this post


Link to post
Share on other sites
JackSlender    17

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!

Share this post


Link to post
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!!!

Share this post


Link to post
Share on other sites
JackSlender    17

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.

Share this post


Link to post
Share on other sites
DeathDisciple    291

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.

Share this post


Link to post
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 :)

Share this post


Link to post
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!! :)

Share this post


Link to post
Share on other sites
DeathDisciple    291

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

Share this post


Link to post
Share on other sites
JackSlender    17

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.

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites
IPO    0

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 !

Share this post


Link to post
Share on other sites
JackSlender    17

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

Share this post


Link to post
Share on other sites

Looked around the whole thread, what does the number at the end do?

room.contents.countstaticlayouts["ResearchLab"] = 1

I wish to make a setpiece that only spawns once in the world, much like the pigking.

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