How to Read Resource Richnesses

Place to get help with not working mods / modding interface.
Twisted6
Burner Inserter
Burner Inserter
Posts: 13
Joined: Wed Dec 14, 2016 11:17 pm
Contact:

How to Read Resource Richnesses

Post by Twisted6 »

Does anyone know how to read the map settings for resource richness for each of the resources (iron, copper, coal ect)?

Solved, answer:

Code: Select all

game.surfaces['nauvis'].map_gen_settings.autoplace_controls["iron-ore"].richness
Last edited by Twisted6 on Thu Dec 15, 2016 12:13 am, edited 1 time in total.
Nexela
Smart Inserter
Smart Inserter
Posts: 1828
Joined: Wed May 25, 2016 11:09 am
Contact:

Re: How to Read Resource Richnesses

Post by Nexela »

game.print(game.player.surface.map_gen_settings.autoplace_controls["iron-ore"].richness)
Twisted6
Burner Inserter
Burner Inserter
Posts: 13
Joined: Wed Dec 14, 2016 11:17 pm
Contact:

Re: How to Read Resource Richnesses

Post by Twisted6 »

Nexela wrote:game.print(game.player.surface.map_gen_settings.autoplace_controls["iron-ore"].richness)
That throws a nil value error on player, however game.print(game.surfaces['nauvis'].map_gen_settings.autoplace_controls["iron-ore"].richness) works. Thanks for the pointer.
Nexela
Smart Inserter
Smart Inserter
Posts: 1828
Joined: Wed May 25, 2016 11:09 am
Contact:

Re: How to Read Resource Richnesses

Post by Nexela »

Sorry the example was for console use.


Also not sure where you are collecting this data at but using hard coded surfaces (i.e. surfaces['nauvis']) can cause undesired behavior on other surfaces from mods.
Twisted6
Burner Inserter
Burner Inserter
Posts: 13
Joined: Wed Dec 14, 2016 11:17 pm
Contact:

Re: How to Read Resource Richnesses

Post by Twisted6 »

I'm unfamiliar with how the surfaces work but 'nauvis' is used in the base mod files. Maybe game.surfaces[1] would also work.
Nexela
Smart Inserter
Smart Inserter
Posts: 1828
Joined: Wed May 25, 2016 11:09 am
Contact:

Re: How to Read Resource Richnesses

Post by Nexela »

game.surfaces[1] and surfaces['nauvis'] do the same thing (both refer to the nauvis surface)

How to handle it would be determined on where and how the code to get the data is used and or accessed.

I.E if you are getting the data during an event with a player or entity you can retrieve the surface from them.

script.on_event(defines.events.on_built_entity, function(event)
-- for the surface of the event entity
game.print(event.entity.surface.map_gen_settings.autoplace_controls["iron-ore"].richness)

-- for the surface of the player that built the entity
game.print(game.players[event.player_index].surface.map_gen_settings.autoplace_controls["iron-ore"].richness)
end)
Post Reply

Return to “Modding help”