Spawn resources on_init

Place to get help with not working mods / modding interface.
User avatar
darkfrei
Smart Inserter
Smart Inserter
Posts: 2905
Joined: Thu Nov 20, 2014 11:11 pm
Contact:

Spawn resources on_init

Post 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.
Rseding91
Factorio Staff
Factorio Staff
Posts: 16016
Joined: Wed Jun 11, 2014 5:23 am
Contact:

Re: Spawn resources on_init

Post by Rseding91 »

Yes.
If you want to get ahold of me I'm almost always on Discord.
User avatar
darkfrei
Smart Inserter
Smart Inserter
Posts: 2905
Joined: Thu Nov 20, 2014 11:11 pm
Contact:

Re: Spawn resources on_init

Post by darkfrei »

Rseding91 wrote:Yes.
How to spawn new ores on old map?
Rseding91
Factorio Staff
Factorio Staff
Posts: 16016
Joined: Wed Jun 11, 2014 5:23 am
Contact:

Re: Spawn resources on_init

Post 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.
If you want to get ahold of me I'm almost always on Discord.
User avatar
darkfrei
Smart Inserter
Smart Inserter
Posts: 2905
Joined: Thu Nov 20, 2014 11:11 pm
Contact:

Re: Spawn resources on_init

Post 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?
Rseding91
Factorio Staff
Factorio Staff
Posts: 16016
Joined: Wed Jun 11, 2014 5:23 am
Contact:

Re: Spawn resources on_init

Post 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.
If you want to get ahold of me I'm almost always on Discord.
User avatar
darkfrei
Smart Inserter
Smart Inserter
Posts: 2905
Joined: Thu Nov 20, 2014 11:11 pm
Contact:

Re: Spawn resources on_init

Post 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.
Rseding91
Factorio Staff
Factorio Staff
Posts: 16016
Joined: Wed Jun 11, 2014 5:23 am
Contact:

Re: Spawn resources on_init

Post 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.
If you want to get ahold of me I'm almost always on Discord.
Post Reply

Return to “Modding help”