Factorio

Factorio

View Stats:
Chunk Generation
In the map editor I need to generate a large area for what I'm planning, but going around and sweeping it is obnoxious. Can I click and drag an area on the map and it'll just generate it for me?
< >
Showing 1-1 of 1 comments
This will generate chunks in a rectangle selected by map pings. It uses a technique where map pings can be entered directly into a script, which it will understand as part of its own text.

1. paste the script into chat, without hitting Enter to finish it
2. ping the map twice (Shift + Left-Click) with the chat open
3. type a closing quote " to end the script
4. hit Enter

/c --[[ generate chunks ]] local function box_on_surface(s) local a,b,c,d,m,M,n=1/0,1/0,-1/0,-1/0,math.min,math.max for x,y,z in s:gmatch("%[gps=([+-]?[%d%.]+),([+-]?[%d%.]+),?([^%]]*)%]")do a=m(a,x+0)b=m(b,y+0)c=M(c,x+0)d=M(d,y+0)n=z end return{left_top={x=a,y=b},right_bottom={x=c,y=d}}, game.get_surface(#n>0 and n or 1) end local function go(s) local box, surface = box_on_surface(s) --[[ nudge left_top corner to match a chunk boundary --]] box.left_top.x = 32 * math.floor(box.left_top.x / 32) box.left_top.y = 32 * math.floor(box.left_top.y / 32) --[[ looping through 32 tiles at a time will hit each chunk once --]] for x = box.left_top.x, box.right_bottom.x, 32 do for y = box.left_top.y, box.right_bottom.y, 32 do surface.request_to_generate_chunks({x=x, y=y}, 0) end end surface.force_generate_chunk_requests() game.player.force.chart(surface, box) end go "

The script ends in an unterminated quote, and is not valid Lua. You are supposed to complete it before hitting Enter.

I unfortunately lost the original version of the 'box_on_surface' function that parses map pings into a bounding box, and only have the "compressed" version which looks like an obfuscated mess. But it works. If I ever posted the idea to reddit I would redo it.
< >
Showing 1-1 of 1 comments
Per page: 1530 50

Date Posted: Jan 2, 2023 @ 1:50pm
Posts: 1