Page 1 of 1
Help creating a tutorial (creating maps/entities for each step)
Posted: Wed May 29, 2019 12:02 pm
by mrvn
I want to create a tutorial for the Logistic Train Network mod that goes a few iteration going from simple setups to complex ones. For that a lot of infrastructure should be pre-set by the tutorial for each iteration.
I've already discovered that I can create a map in the map editor and copy the blueprints.zip to get an initial landscape. But how do I best add stuff as the user makes progress?
I saw that the base tutorials (eg the train one) have a table of ghost rails that they want to place and then a section in the story script places that table. Is that the best way to do this? And if so how do I create such a table without having to type it all out by hand? Is there a blueprint -> table tool or something? I need a lot of entities with circuit connections and programming. I really don't want to hand write that.
What if I want to change the terrain? Add some ore deposits for example. Or make the map larger?
Re: Help creating a tutorial (creating maps/entities for each step)
Posted: Wed May 29, 2019 12:12 pm
by Bilka
Take a look at the NPE map expansions. Afaik it has a "template" surface and just clones the chunks to the playing surface when the map expands. That way you can have even complex structures without writing long lua code to place them.
If you still want to go the table way, have a look at using some external script to decode blueprint strings and generating code for entities from there.
Re: Help creating a tutorial (creating maps/entities for each step)
Posted: Wed May 29, 2019 12:20 pm
by eradicator
LuaItemStack.import_stack(blueprint_string)
LuaItemStack.build_blueprint{}
Works for machines, etc.
Not sure if you can (or should) abuse that to place whole regions of tiles for map extension.
And it definetly won't work for resources.
Re: Help creating a tutorial (creating maps/entities for each step)
Posted: Wed May 29, 2019 12:31 pm
by DaveMcW
Code: Select all
local blueprint_string = "0eNqVkcsKwjAQRf/lrlOIqVjJr4hIH0MdaNOSpGIp+XfTFETQRV3OzL1nXguqbqLRsvHQC7gejIO+LHDcmrJbc34eCRrsqYeAKfs1siV3CAJsGnpCH8JVgIxnz7T5UzDfzNRXZKPg7XQ+etu7zxJCYBxcdA1mbRVJUmCGzlQI4gui9kIylSgyDtiwpXorqR/IfC9yN/H436Zx0Xi6dFz98QuBB1mXxEUuD4U6KXnOQ3gBvbGPPQ=="
local chest = game.surfaces[1].create_entity{
name = "wooden-chest",
position = {0,0},
force = game.forces.player,
}
local inventory = chest.get_inventory(defines.inventory.chest)
inventory.insert("blueprint")
local blueprint = inventory.find_item_stack("blueprint")
blueprint.import_stack(blueprint_string)
local ghosts = blueprint.build_blueprint{
surface = game.surfaces[1],
force = game.forces.player,
position = {0,0},
force_build = true,
}
for _, ghost in pairs(ghosts) do
ghost.revive()
end
chest.destroy()
Re: Help creating a tutorial (creating maps/entities for each step)
Posted: Wed May 29, 2019 1:39 pm
by eradicator
Code: Select all
local function build_blueprint_string(blueprint_string,surface,position,force)
local bp = surface.create_entity{
name="item-on-ground",
position=position,
stack='blueprint'}.stack
if bp.import_stack(blueprint_string) ~= 0 then
error('Invalid or outdated blueprint string')
end
for _,entity in pairs(bp.build_blueprint{
surface = surface,
force = force,
position = position,
skip_fog_of_war = false,
force_build = true,
}) do
entity.silent_revive()
if entity.valid then entity.destroy() end
end
bp.clear()
end
Re: Help creating a tutorial (creating maps/entities for each step)
Posted: Wed May 29, 2019 3:32 pm
by mrvn
I just had a thought. Can't I create a map with multiple surfaces in the map editor and then teleport the player to each surface as needed?