Looking for a lua way to delete all nuclear scorch marks
Posted: Sun Nov 29, 2020 9:28 pm
by Diablo
Hi,
Like the title says, i'm Looking for a lua way to delete all nuclear scorch marks.
I have had the need to clear out large specific sections of forests and the nuclear bomb was the best way to do this.
I know there is a way to remove trees via lua but I really didn't want to rely on lua to play the game.
I now realize the black scorch marks never go away. (like all other damage or dead entities)
Does anyone know a way?
Thank you.
Re: Looking for a lua way to delete all nuclear scorch marks
Posted: Sun Nov 29, 2020 9:40 pm
by darkfrei
Diablo wrote: ↑Sun Nov 29, 2020 9:28 pm
Like the title says, i'm Looking for a lua way to delete all nuclear scorch marks.
/c
for i, surface in pairs (game.surfaces) do
local entities = surface.find_entities_filtered{name="huge-scorchmark"}
for j, entity in pairs (entities) do
entity.destroy()
end
end
Re: Looking for a lua way to delete all nuclear scorch marks
Posted: Sun Nov 29, 2020 10:10 pm
by ptx0
didn't wanna use lua, but now you're using lua
Re: Looking for a lua way to delete all nuclear scorch marks
Posted: Sun Nov 29, 2020 10:11 pm
by Diablo
ptx0 wrote: ↑Sun Nov 29, 2020 10:10 pm
didn't wanna use lua, but now you're using lua
Yup, sometimes you just gotta.
Re: Looking for a lua way to delete all nuclear scorch marks
/c
for i, surface in pairs (game.surfaces) do
local entities = surface.find_entities_filtered{name="huge-scorchmark"}
for j, entity in pairs (entities) do
entity.destroy()
end
end
Thanks for the fast responds, awesome!
Unless I missed something, this, unfortunately, didn't work.
I copied everything and just pasted it.
No error messages or anything just nothing happend.
It looks like the huge scorch mark is not what is being used for the nuclear scorch marks.
If I use the editor to look for the scorch mark, the huge scorch marks are not the same marks.
In fact I can not find the scorch marks used for the nuclear explosion.
Re: Looking for a lua way to delete all nuclear scorch marks
Posted: Sun Nov 29, 2020 11:42 pm
by ptx0
it's because it actually changes the tile, there's no way to remove them without cloning the area around the scorch marks using lua.
Screenshot_20201129_154122.png (39.71 KiB) Viewed 5315 times
Re: Looking for a lua way to delete all nuclear scorch marks
Posted: Mon Nov 30, 2020 8:06 am
by darkfrei
ptx0 wrote: ↑Sun Nov 29, 2020 11:42 pm
it's because it actually changes the tile, there's no way to remove them without cloning the area around the scorch marks using lua.
Re: Looking for a lua way to delete all nuclear scorch marks
Posted: Mon Nov 30, 2020 1:41 pm
by eradicator
Diablo wrote: ↑Sun Nov 29, 2020 9:28 pm
Does anyone know a way?
Damn, got nerd-sniped. Here you go.
Description
Uses partial surface cloning to restore original tiles overwritten by nuclear scorch marks. Applies only to the surface that you are currently on. The game will run extremely slow until fixing is completed. A chat message will be printed when completed. Will probably take a few minutes on really large maps. DO NOT SAVE/LOAD DURING THE PROCESS.
/c
local Nth, chunks_per_cycle = 3, 100
local s1 = game.player.surface
local s2 = game.create_surface(tostring(math.random()),s1.map_gen_settings)
local C = (function(r) for c in s1.get_chunks() do r[#r+1]=c end return r end){}
s1.destroy_decoratives{name='nuclear-ground-patch'}
for _,ent in pairs(s1.find_entities_filtered{name='huge-scorchmark'}) do
ent.destroy()
end
script.on_nth_tick(Nth,function()
if #C > 0 then
for i = #C, math.max(#C-chunks_per_cycle, 1), -1 do
local c = C[i]; C[i] = nil
local T = s1.find_tiles_filtered{area=c.area,name='nuclear-ground'}
if #T > 0 then
s2.request_to_generate_chunks({c.x*32, c.y*32}, 0)
s2.force_generate_chunk_requests()
for i, t in pairs(T) do
local pos = t.position
T[i] = {name = s2.get_tile(pos.x, pos.y).name, position = pos}
end
s1.set_tiles(T, true, false, false, true)
end
end
else
script.on_nth_tick(Nth, nil)
game.delete_surface(s2)
game.print('Nuclear scorch mark removal: Completed!')
end
end)
Re: Looking for a lua way to delete all nuclear scorch marks
Posted: Mon Nov 30, 2020 5:03 pm
by Diablo
eradicator wrote: ↑Mon Nov 30, 2020 1:41 pm
[snip]
Thank you, this worked perfectly.
If I could upvote I would, again Thank you.
Re: Looking for a lua way to delete all nuclear scorch marks
Posted: Mon Nov 30, 2020 6:38 pm
by eradicator
Diablo wrote: ↑Mon Nov 30, 2020 5:03 pm
Thank you, this worked perfectly.
If I could upvote I would, again Thank you.
Np. If you ever see someone with the same problem just link them here ;).
[Edit: Also on second thought it's probably better if you remove the code-quote from your post so in the unlikely case that i need to "bugfix" my original post yours doesn't continue to show the old code.]
Re: Looking for a lua way to delete all nuclear scorch marks
Posted: Mon Nov 30, 2020 8:08 pm
by Koub
eradicator wrote: ↑Mon Nov 30, 2020 6:38 pm
[Edit: Also on second thought it's probably better if you remove the code-quote from your post so in the unlikely case that i need to "bugfix" my original post yours doesn't continue to show the old code.]
Took the liberty to do it myself, as I walked by.
Re: Looking for a lua way to delete all nuclear scorch marks
eradicator wrote: ↑Mon Nov 30, 2020 6:38 pm
[Edit: Also on second thought it's probably better if you remove the code-quote from your post so in the unlikely case that i need to "bugfix" my original post yours doesn't continue to show the old code.]