Scenario. Remove the resource in a certain radius

Don't know how to use a machine? Looking for efficient setups? Stuck in a mission?
User avatar
WIZ4
Fast Inserter
Fast Inserter
Posts: 209
Joined: Thu Apr 07, 2016 1:36 pm
Contact:

Scenario. Remove the resource in a certain radius

Post 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
Last edited by WIZ4 on Fri Sep 08, 2017 7:21 pm, edited 1 time in total.
My native language is russian. Sorry if my messages are difficult to read.
User avatar
prg
Filter Inserter
Filter Inserter
Posts: 947
Joined: Mon Jan 19, 2015 12:39 am
Contact:

Re: Scenario. Remove the resource in a certain radius

Post by prg »

Because there's no "cooper-ore" in the game...
Automatic Belt (and pipe) Planner—Automate yet another aspect of constructing your factory!
User avatar
WIZ4
Fast Inserter
Fast Inserter
Posts: 209
Joined: Thu Apr 07, 2016 1:36 pm
Contact:

Re: Scenario. Remove the resource in a certain radius

Post 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
Attachments
Screenshot_6.png
Screenshot_6.png (49.19 KiB) Viewed 3513 times
My native language is russian. Sorry if my messages are difficult to read.
torne
Filter Inserter
Filter Inserter
Posts: 342
Joined: Sun Jan 01, 2017 11:54 am
Contact:

Re: Scenario. Remove the resource in a certain radius

Post 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.
User avatar
WIZ4
Fast Inserter
Fast Inserter
Posts: 209
Joined: Thu Apr 07, 2016 1:36 pm
Contact:

Re: Scenario. Remove the resource in a certain radius

Post 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
Screenshot_6.png (105.1 KiB) Viewed 3506 times
My native language is russian. Sorry if my messages are difficult to read.
User avatar
DaveMcW
Smart Inserter
Smart Inserter
Posts: 3716
Joined: Tue May 13, 2014 11:06 am
Contact:

Re: Scenario. Remove the resource in a certain radius

Post 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.
Last edited by DaveMcW on Fri Sep 08, 2017 7:57 pm, edited 1 time in total.
User avatar
WIZ4
Fast Inserter
Fast Inserter
Posts: 209
Joined: Thu Apr 07, 2016 1:36 pm
Contact:

Re: Scenario. Remove the resource in a certain radius

Post 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
My native language is russian. Sorry if my messages are difficult to read.
Theverat
Manual Inserter
Manual Inserter
Posts: 1
Joined: Thu Sep 14, 2017 7:38 am
Contact:

Re: Scenario. Remove the resource in a certain radius

Post 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).
Post Reply

Return to “Gameplay Help”