Page 1 of 1

Spawn resources on_init

Posted: Mon Nov 27, 2017 7:34 am
by darkfrei
Hi all!
Is it possible to spawn resources (ores and oil patches) with on_init event? So, like it was be added by vanilla spawn preferences.

New mod adds new ore and it will be nice to have ore patches on already explored map.

Re: Spawn resources on_init

Posted: Mon Nov 27, 2017 11:54 am
by Rseding91
Yes.

Re: Spawn resources on_init

Posted: Mon Nov 27, 2017 7:37 pm
by darkfrei
Rseding91 wrote:Yes.
How to spawn new ores on old map?

Re: Spawn resources on_init

Posted: Mon Nov 27, 2017 8:00 pm
by Rseding91
darkfrei wrote:
Rseding91 wrote:Yes.
How to spawn new ores on old map?
You can use a migration script and call http://lua-api.factorio.com/latest/LuaG ... ate_entity with the entities you want to regenerate.

Re: Spawn resources on_init

Posted: Mon Nov 27, 2017 8:37 pm
by darkfrei
Rseding91 wrote:You can use a migration script and call http://lua-api.factorio.com/latest/LuaG ... ate_entity with the entities you want to regenerate.
It works!

Code: Select all

script.on_init(function()
	game.regenerate_entity("ice-ore")
end)
Why migration script is better than just control.lua - on_init?

Re: Spawn resources on_init

Posted: Mon Nov 27, 2017 9:08 pm
by Rseding91
darkfrei wrote:
Rseding91 wrote:You can use a migration script and call http://lua-api.factorio.com/latest/LuaG ... ate_entity with the entities you want to regenerate.
It works!

Code: Select all

script.on_init(function()
	game.regenerate_entity("ice-ore")
end)
Why migration script is better than just control.lua - on_init?
Because migration scripts are run once on a save file only if they've never been run before on that save. on_init will run any time you make a new save or add the mod to a given save.

Once on_init has run for a mod it won't ever be run again when that mod exists in the save.

Re: Spawn resources on_init

Posted: Mon Nov 27, 2017 9:38 pm
by darkfrei
Rseding91 wrote:Once on_init has run for a mod it won't ever be run again when that mod exists in the save.
So, new ore will be never added to the old map, only one at first start? It sounds perfect for this situation.

Re: Spawn resources on_init

Posted: Mon Nov 27, 2017 11:10 pm
by Rseding91
darkfrei wrote:
Rseding91 wrote:Once on_init has run for a mod it won't ever be run again when that mod exists in the save.
So, new ore will be never added to the old map, only one at first start? It sounds perfect for this situation.
That already happens when you generate any map :) That's the point of the settings in the generate-map screen.