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.
Spawn resources on_init
Re: Spawn resources on_init
How to spawn new ores on old map?Rseding91 wrote:Yes.
Re: Spawn resources on_init
You can use a migration script and call http://lua-api.factorio.com/latest/LuaG ... ate_entity with the entities you want to regenerate.darkfrei wrote:How to spawn new ores on old map?Rseding91 wrote:Yes.
If you want to get ahold of me I'm almost always on Discord.
Re: Spawn resources on_init
It works!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.
Code: Select all
script.on_init(function()
game.regenerate_entity("ice-ore")
end)
Re: Spawn resources 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.darkfrei wrote:It works!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.Why migration script is better than just control.lua - on_init?Code: Select all
script.on_init(function() game.regenerate_entity("ice-ore") end)
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.
Re: Spawn resources on_init
So, new ore will be never added to the old map, only one at first start? It sounds perfect for this situation.Rseding91 wrote: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
That already happens when you generate any mapdarkfrei wrote:So, new ore will be never added to the old map, only one at first start? It sounds perfect for this situation.Rseding91 wrote: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.