Need help with modding

Place to get help with not working mods / modding interface.
Kaban4ik
Burner Inserter
Burner Inserter
Posts: 10
Joined: Wed Aug 20, 2025 12:59 pm
Contact:

Need help with modding

Post by Kaban4ik »

I want to create mod, that replaces standart ore drops with random item. Right now the single prolem that i have is: list of all recipes with items (valid_recipes) is empty, and I can't figure out why. Everything else seems to work properly. Can anyone help me? Thank you in advance for your assistance.
Attachments
data.lua
(10 Bytes) Downloaded 14 times
info.json
(364 Bytes) Downloaded 8 times
control.lua
(1.67 KiB) Downloaded 15 times
User avatar
EvilPLa
Inserter
Inserter
Posts: 49
Joined: Sat Nov 14, 2020 7:26 am
Contact:

Re: Need help with modding

Post by EvilPLa »

your second script.on_load () overwrites the first one, you can implement those methods only once.

Also read here:
https://lua-api.factorio.com/latest/cla ... ml#on_load

hope that helps
Wise men speak because they have something to say Fools because they have to say something. (Plato)
Kaban4ik
Burner Inserter
Burner Inserter
Posts: 10
Joined: Wed Aug 20, 2025 12:59 pm
Contact:

Re: Need help with modding

Post by Kaban4ik »

The second function was made only to debug first one and it does nothing useful for mod purpose. After removing second function and moving it's code to first one, I've faced a problem: no items was given and nothing was printed into chat. I still have no idea what is wrong with my code. Anyway, thanks for the idea.
User avatar
EvilPLa
Inserter
Inserter
Posts: 49
Joined: Sat Nov 14, 2020 7:26 am
Contact:

Re: Need help with modding

Post by EvilPLa »

Well I recommend going thru the tutorials and installing vscode with fmtk, hopping thru the code with a debugger makes life soo much easier.
Last hint: table[0] isn't going to work, since arrays start with 1 in lua
Wise men speak because they have something to say Fools because they have to say something. (Plato)
Kaban4ik
Burner Inserter
Burner Inserter
Posts: 10
Joined: Wed Aug 20, 2025 12:59 pm
Contact:

Re: Need help with modding

Post by Kaban4ik »

Thanks for your help. That extension for vs code really solved all my code problems.
EvilPLa wrote: Thu Aug 21, 2025 11:59 am Well I recommend going thru the tutorials and installing vscode with fmtk, hopping thru the code with a debugger makes life soo much easier.
Last hint: table[0] isn't going to work, since arrays start with 1 in lua
I have, as I hope the last, question: How can I filter all "creative" items from the list?
Right now I am using recipes to filter items without them, but recycling makes recipes for all items, including ceative, I guess.

Code: Select all

local recipes = prototypes.get_recipe_filtered{{filter = "has-product-item"}}
I think, I could filter items by group or subgroup of an item, but I can't find a list of all available groups and subgroups in Factorio docs. Also this solution may have problems with modded groups and subgroups. Is there is a better apporoach for such filtering?
User avatar
EvilPLa
Inserter
Inserter
Posts: 49
Joined: Sat Nov 14, 2020 7:26 am
Contact:

Re: Need help with modding

Post by EvilPLa »

With ctrl-shift-e you can open the prototype explorer, here you can find your recipe-categroies and a lot more.
08-21-2025, 20-20-33.png
08-21-2025, 20-20-33.png (103.49 KiB) Viewed 315 times
Wise men speak because they have something to say Fools because they have to say something. (Plato)
Kaban4ik
Burner Inserter
Burner Inserter
Posts: 10
Joined: Wed Aug 20, 2025 12:59 pm
Contact:

Re: Need help with modding

Post by Kaban4ik »

Thanks again for your help. Right now my mod works as intended.
But I am curious, is there a way to replace results of mining ore with a drill with random items in real time?
For player it is pretty simple: use event "defines.events.on_player_mined_entity", but there is no such easy way for drills. Right now, the only ideas that I have are: to replace ores with random one, but it will need to automatically create all ores for all random items and then randomly replace existing ones after they were mined once, so I guess it will affect performance a lot; the second idea is to somehow replace dill's function, but as I've noticed drills are pretty the same with ores in case of functions - both are being "baked" into unchangable prototypes during prototypes stage, so maybe the second option will not work.
Xorimuth
Filter Inserter
Filter Inserter
Posts: 731
Joined: Sat Mar 02, 2019 9:39 pm
Contact:

Re: Need help with modding

Post by Xorimuth »

You can do random mine results in data stage only without having to touch control scripting. That way, it will affect player mining and drill mining equally, and not have any script performance overhead. The downside is it isn’t dynamic so you can’t adjust the probabilities based on time, unlocks, drill type, etc.

You can do this by modifying each resource entity’s minable property: remove .result and add .results to be a list of all the things you want it to drop, with ‘probability’ set to whatever you like.

https://lua-api.factorio.com/latest/pro ... otype.html
https://lua-api.factorio.com/latest/typ ... rties.html
https://lua-api.factorio.com/latest/typ ... otype.html
My mods
Content: Lunar Landings | Freight Forwarding | Spidertron Patrols | Spidertron Enhancements | Power Overload
QoL: Factory Search | Module Inserter Simplified | Wire Shortcuts X | Ghost Warnings
Kaban4ik
Burner Inserter
Burner Inserter
Posts: 10
Joined: Wed Aug 20, 2025 12:59 pm
Contact:

Re: Need help with modding

Post by Kaban4ik »

Thank you very much for your help. This solution is much simpler than previous one. Right now my mod is fully complete and works as intended.
Post Reply

Return to “Modding help”