Need help with modding
Need help with modding
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
Re: Need help with modding
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
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)
Re: Need help with modding
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.
Re: Need help with modding
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
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)
Re: Need help with modding
Thanks for your help. That extension for vs code really solved all my code problems.
Right now I am using recipes to filter items without them, but recycling makes recipes for all items, including ceative, I guess.
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?
I have, as I hope the last, question: How can I filter all "creative" items from the list?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
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"}}
Re: Need help with modding
With ctrl-shift-e you can open the prototype explorer, here you can find your recipe-categroies and a lot more.
Wise men speak because they have something to say Fools because they have to say something. (Plato)
Re: Need help with modding
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.
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.
Re: Need help with modding
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
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
Content: Lunar Landings | Freight Forwarding | Spidertron Patrols | Spidertron Enhancements | Power Overload
QoL: Factory Search | Module Inserter Simplified | Wire Shortcuts X | Ghost Warnings
Re: Need help with modding
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.