Page 1 of 1
Scenario. Remove the resource in a certain radius
Posted: Fri Sep 08, 2017 6:07 pm
by WIZ4
How do I write a script in a scenario so that when I start the game, I remove the resource in a certain radius?
Something like this, but it does not work
Code: Select all
function clear(player)
for key, entity in pairs(game.surfaces[1].find_entities_filtered({ area={{x = -2500, y = -2500}, {x = 2500, y = 2500}}, name="copper-ore"})) do entity.destroy() end;
end
Re: Scenario. Remove the resource in a certain radius
Posted: Fri Sep 08, 2017 6:54 pm
by prg
Because there's no "cooper-ore" in the game...
Re: Scenario. Remove the resource in a certain radius
Posted: Fri Sep 08, 2017 7:21 pm
by WIZ4
prg wrote:Because there's no "cooper-ore" in the game...
Thank you, I fixed this on copper-ore
It started to work, but some part of the copper still remains on the map
After all, the ore should be removed in the entire investigated area
Re: Scenario. Remove the resource in a certain radius
Posted: Fri Sep 08, 2017 7:34 pm
by torne
The map is only updated in the "lit up" areas: the parts surrounding players and radars, and the chunks that get scanned one at a time when the radar scans them. Everything "dark" on the map is just a snapshot of what was at that point on the map the last time it was scanned - it's RTS-style fog of war.
So, if you walk down there you will see the copper is probably actually gone, and as soon as the scan radius around your player touches it, it will also disappear from the map.
Re: Scenario. Remove the resource in a certain radius
Posted: Fri Sep 08, 2017 7:38 pm
by WIZ4
torne wrote:The map is only updated in the "lit up" areas: the parts surrounding players and radars, and the chunks that get scanned one at a time when the radar scans them. Everything "dark" on the map is just a snapshot of what was at that point on the map the last time it was scanned - it's RTS-style fog of war.
So, if you walk down there you will see the copper is probably actually gone, and as soon as the scan radius around your player touches it, it will also disappear from the map.
Copper did not disappear
- Screenshot_6.png (105.1 KiB) Viewed 3224 times
Re: Scenario. Remove the resource in a certain radius
Posted: Fri Sep 08, 2017 7:53 pm
by DaveMcW
The copper was not generated when you did the command. Only resources that have been generated can be removed.
You can use
on_chunk_generated to catch resources as they are generated.
Re: Scenario. Remove the resource in a certain radius
Posted: Fri Sep 08, 2017 7:57 pm
by WIZ4
DaveMcW wrote:The copper was not generated when you did the command. Only resources that have been generated can be removed.
I'll have to look for a way to reproduce the script after a certain time
Re: Scenario. Remove the resource in a certain radius
Posted: Thu Sep 14, 2017 7:43 am
by Theverat
How about you use on_chunk_generated like this (pseudo code)?
Code: Select all
on_chunk_generated():
if chunk_coordinates in area:
remove_all_copper_in_chunk()
Then you wouldn't need to run the script at startup or periodically, just attach this function to the event handler.
(Note that I don't know Lua or how to code for factorio specifically, so some details may be wrong).