Jump to content

Spawn Set Piece with 100% chance

Recommended Posts


I'm working on mod and all almost done, but I stuck with problem - how to spawn Set Piece with 100% chance anywhere in the world? (e.g. like Pig King, but without special room)

My Set Piece "my_set_piece" static layout:


local StaticLayout = require("map/static_layout")
return {
            type = LAYOUT.STATIC,
            args = nil,
            defs = {},
            ground_types = {GROUND.CARPET, GROUND.CHECKER},
            ground = {
                    {1, 1, 1, 1, 1},
                    {1, 2, 2, 2, 2},
                    {1, 2, 1, 1, 1},
                    {1, 2, 2, 2, 1},
                    {1, 1, 1, 1, 1},
            --desctibe object which ones Set Piece should contain        
            layout = {
                    --pass Prefab name itself
                    pigtorch = {
                                     {x=-3, y=-3}, {x=3, y=3},
                    mermhead = {
                                     {x=-3, y=3}, {x=3, y=-3}
                    my_new_item = {
                                    {x=0, y=0}
            scale = 0.5

As was mentioned at this comment it is possible to use ordered_story_setpieces at modworldgenmain.lua and it should do the job - generate Set Piece with 100% chance, so I've done

local Layouts = GLOBAL.require("map/layouts").Layouts
Layouts["my_set_piece"] = GLOBAL.require("map/layouts/my_set_piece")
Layouts["my_set_piece"].start_mask = GLOBAL.PLACE_MASK.IGNORE_IMPASSABLE_BARREN
Layouts["my_set_piece"].fill_mask = GLOBAL.PLACE_MASK.IGNORE_IMPASSABLE_BARREN
Layouts["my_set_piece"].layout_position = GLOBAL.LAYOUT_POSITION.CENTER

and added code with AddLevelPreInitAny ordered_story_setpieces

        if level.location ~= "forest" then -- only in overworld
        if level.ordered_story_setpieces == nil then -- if ordered_story_setpieces does not exist already, create it
            level.ordered_story_setpieces = {}
        table.insert(level.ordered_story_setpieces, "my_set_piece")

But this didn't working for my Set Piece. Chances are around 50%.
At Teleportato mod source code I found usage of AddTaskSetPreInitAny so I've done

    if tasksetdata.location ~= "forest" then
	tasksetdata.set_pieces["my_set_piece"] = { count = 1, tasks={"Make a pick", "Dig that rock", "Great Plains", "Beeeees!", "Speak to the king", "Forest hunters", "For a nice walk", "The hunters", "Magic meadow", "Frogs and bugs","Oasis","Badlands","Lightning Bluff"}}

And looks like it's working for 100% chances, but I don't know if it is good solution or no - have no idea what 'Task' is.

Looking forward to suggestions how it should be done.

Edited by zyxerdima
Link to comment
Share on other sites

A task basically means all the bits of worldgen (you can see it there in the examples like "speak to the king" is the pig king area), so attaching your set piece mod to a task is a legit way to do it. If you seem to have made it work 100% just give it some testing - regen a bunch of worlds, check your log files for errors etc.

Edited by justjasper
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

  • Create New...