Lua command to edit modded resource density?

Place to post guides, observations, things related to modding that are not mods themselves.
Post Reply
DudebroPyro
Burner Inserter
Burner Inserter
Posts: 17
Joined: Wed Nov 21, 2018 10:34 pm
Contact:

Lua command to edit modded resource density?

Post by DudebroPyro »

I wanted to edit the resource frequency on a map I'm currently playing (and then use a mod to delete empty chunks and regenerate them). Using the script given in the wiki here, I was able to edit all the vanilla resource setting successfully (at least, I assume so - it didn't signal any error upon executing the commands). However, I'm playing a modded game (using Krastorio), and while I found the lua file defining the modded resources (e.g. "gold-ore"), "autoplace[resource]" seems to be nil for them.

I've tried looking at the various Lua APIs and experimenting in the console, but without any prior experience with the Factorio internal environment I couldn't find anything useful.

Is it possible to change the map generation parameters for modded resources, and if so, how?

Adamo
Filter Inserter
Filter Inserter
Posts: 479
Joined: Sat May 24, 2014 7:00 am
Contact:

Re: Lua command to edit modded resource density?

Post by Adamo »

Edit: I was wrong.
Last edited by Adamo on Fri Sep 20, 2019 11:56 am, edited 1 time in total.

DudebroPyro
Burner Inserter
Burner Inserter
Posts: 17
Joined: Wed Nov 21, 2018 10:34 pm
Contact:

Re: Lua command to edit modded resource density?

Post by DudebroPyro »

This sounds odd to me, so to make sure I'm understanding this right - I'd need to edit the lua files of the mod itself (manually or through a tiny dependant mod), in order to change resource generation density settings in my save file? The reason I'm a bit confused is because I'm not sure how that would affect things if, say, I created a new game (using the same mod(s)), and played around with the sliders before generating the map. Would it force using the settings I edited in the mod files, or would the sliders override that? If it's the latter, why wouldn't the sliders I set in my current save file at game start override whatever I edit in the files - if it's the former, why would the sliders work in the first place?

Intuitively, I'd have imagined the settings to just be some variable saved in the file, and a console command could just edit that value in the save file. And I wouldn't have imagined there being a significant difference between base and modded resources. Thanks for your help, this is more involved than I thought it would.

Also, does what you said apply to modded resources only, or are you saying the script from the wiki is plain wrong?

Bilka
Factorio Staff
Factorio Staff
Posts: 3128
Joined: Sat Aug 13, 2016 9:20 am
Contact:

Re: Lua command to edit modded resource density?

Post by Bilka »

You can change the map generation settings during runtime, they just don't affect existing terrain. Easiest vanilla way to do that is /editor -> surface tab -> edit map generation -> change settings -> save -> /editor. Alternatively, the command you posted above works if you find the internal name of the ores (can be hard). Another option would be https://mods.factorio.com/mod/ChangeMapSettings
I'm an admin over at https://wiki.factorio.com. Feel free to contact me if there's anything wrong (or right) with it.

DudebroPyro
Burner Inserter
Burner Inserter
Posts: 17
Joined: Wed Nov 21, 2018 10:34 pm
Contact:

Re: Lua command to edit modded resource density?

Post by DudebroPyro »

Oh, the /editor works for that? I messed around with it briefly but didn't notice that option. Cool! I'll try it out when I get home later today.
Out of curiosity though - what's the internal name, and where on earth could it be defined? As I mentioned in my post, I looked through the lua files of the mod. I found the entity definition, the autoplace addition, even the noise layer setting thingy which I'm vaguely aware is necessary for new ore types. All of them specified "name: 'gold-ore'" as a field - yet, running the command with 'gold-ore' told me an object was nil. If that's not the internal name, what is?

DudebroPyro
Burner Inserter
Burner Inserter
Posts: 17
Joined: Wed Nov 21, 2018 10:34 pm
Contact:

Re: Lua command to edit modded resource density?

Post by DudebroPyro »

EDIT: I somehow completely forgot I was using RSO, which changes how frequency works. My bad completely. Original post for posterity:

Update: I tried both the /editor and the suggested mod, but it seems like changing the frequency doesn't affect anything. I'm using this mod https://mods.factorio.com/mod/DeleteEmptyChunks to delete chunks, but every time I do and they get regenerated the exact same ore patches appear at the exact same locations. Using the /editor to fly around and generate completely new chunks always yeilds very similar looking results. I've tried setting the frequency to both extremes and even intermediate values, giving the exact same outcome. I've even tried changing the seed (which would have been a horrible solution had it worked, due to the jarring boundary between old and new chunks), but while the ore patches changed location the frequency still didn't change at all.

Changes to patch size apply perfectly fine, but not frequency: I've successfully gotten tiny patches to generate as opposed to my current giant ones (still in the same exact spots, of course). But since my goal is to retroactively make my game more train-worldy, with rare but large patches, that doesn't help me.

Does someone have any idea why this could be? Is this somehow expected? This is affecting all resources, including vanilla ones (so let me know if I should be posting this question in another part of the forums). (EDIT: as mentioned above, this was due to RSO.)

User avatar
BlueTemplar
Smart Inserter
Smart Inserter
Posts: 2420
Joined: Fri Jun 08, 2018 2:16 pm
Contact:

Re: Lua command to edit modded resource density?

Post by BlueTemplar »

Also, RSO has a command (IIRC /rso-regenerate or something) that allows you to regenerate the terrain (& ores & nests) without the need of deleting chunks or other mods (well, except maybe for Change Map Settings... for some of the values ?)
BobDiggity (mod-scenario-pack)

Post Reply

Return to “Modding discussion”