[Scripting Assistance] Help identifying mining drill functions
[Scripting Assistance] Help identifying mining drill functions
Hello all. This is my first post here, and I'm quite new to .lua and scripts using it. I'm trying to make mining drills which have no mineable resources continue to mine up basic stone as if they were on a stone patch. However, I have tried studying scripts and looking up relevant functions on lua-api.factorio.com, and I can't make heads or tails of accomplishing my goal.
I have two ideas on how to go about it. One is to grab the position of the mining drill upon resource depletion, then spawn a single stone tile under it. However, I still wish to use mods like prospector, which already spawns depleted ores when a tile is depleted, so I don't fancy overwriting those with stone tiles. My alternative idea was to make miners with no mineable resources continue playing their sounds and animations, and simply spawn stone at their output position based on their mining speed. This one seems optimal to me, although likely more complex to pull off. After trying and getting nowhere in particular, I wanted to turn to you all and ask about ideas, opinions, or perhaps lua scripting advice on the subject.
I have two ideas on how to go about it. One is to grab the position of the mining drill upon resource depletion, then spawn a single stone tile under it. However, I still wish to use mods like prospector, which already spawns depleted ores when a tile is depleted, so I don't fancy overwriting those with stone tiles. My alternative idea was to make miners with no mineable resources continue playing their sounds and animations, and simply spawn stone at their output position based on their mining speed. This one seems optimal to me, although likely more complex to pull off. After trying and getting nowhere in particular, I wanted to turn to you all and ask about ideas, opinions, or perhaps lua scripting advice on the subject.
Re: [Scripting Assistance] Help identifying mining drill functions
So you want a machine that
- Plays animations like a mining drill
- Outputs a resource
- Requires no resource under it
The last requirement is impossible with a mining drill, even a modded one. I would use an assembling machine and change the graphics to look a like mining drill.
- Plays animations like a mining drill
- Outputs a resource
- Requires no resource under it
The last requirement is impossible with a mining drill, even a modded one. I would use an assembling machine and change the graphics to look a like mining drill.
-
- Smart Inserter
- Posts: 2530
- Joined: Tue Apr 25, 2017 2:01 pm
- Contact:
Re: [Scripting Assistance] Help identifying mining drill functions
Is there a function that could be monitored for when a mining drill removes a piece of resource from a tile or a resource tile is depleted that the OP could then use to replace depleted resource tiles with a stone resource tile?DaveMcW wrote: ↑Sun Dec 05, 2021 4:47 pmSo you want a machine that
- Plays animations like a mining drill
- Outputs a resource
- Requires no resource under it
The last requirement is impossible with a mining drill, even a modded one. I would use an assembling machine and change the graphics to look a like mining drill.
My Mods: Classic Factorio Basic Oil Processing | Sulfur Production from Oils | Wood to Oil Processing | Infinite Resources - Normal Yield | Tree Saplings (Redux) | Alien Biomes Tweaked | Restrictions on Artificial Tiles
Re: [Scripting Assistance] Help identifying mining drill functions
There's https://lua-api.factorio.com/latest/eve ... e_depleted that would work - it'd have to catch the resource depleting then make sure nothing like prospector was activating, then if there's still nothing he could either spawn stone ore or change the miner to an assembler with miner graphics.
Keep in mind AFAIK there's no way to make an assembler auto-output like a miner does. You can fake it with an inserter but it's not going to work the same.
Keep in mind AFAIK there's no way to make an assembler auto-output like a miner does. You can fake it with an inserter but it's not going to work the same.
Re: [Scripting Assistance] Help identifying mining drill functions
Thanks for the advice. If auto-output with no resources isn't possible, I suppose I'll have to go with spawning stone tiles under. I've been trying to make a script for that, but I'm still fumbling a lot with it. I'm starting to learn how some functions work through both the wiki and studying other opensource mods, but as far as making a script to detect drills running out of resources and then making a stone tile...well, I tried and got something that didn't *crash* the game, but it didn't really work either. Just didn't do anything. The things I know I'd need are as follows, please do add on or correct me if I'm wrong:
-The location of the particular drill that runs out of resources
-The event on_resource_depleted, to actually trigger the resupply
-A variable to reference mining drills, which I assume would run under the on_resource_depleted function to then call for and locate the corresponding drill entities
-Not all sure what else. I'm a doof, and still very green to the whole lua scripting thing. I'll keep trying and studying mods that look up drills with depleted resources, and hopefully get something functional up. By any chance, for the sake of development, is there a good way to have each function run a message in the chat so I can verify that each command is, in fact, getting run properly?
-The location of the particular drill that runs out of resources
-The event on_resource_depleted, to actually trigger the resupply
-A variable to reference mining drills, which I assume would run under the on_resource_depleted function to then call for and locate the corresponding drill entities
-Not all sure what else. I'm a doof, and still very green to the whole lua scripting thing. I'll keep trying and studying mods that look up drills with depleted resources, and hopefully get something functional up. By any chance, for the sake of development, is there a good way to have each function run a message in the chat so I can verify that each command is, in fact, getting run properly?
- Stringweasel
- Filter Inserter
- Posts: 315
- Joined: Thu Apr 27, 2017 8:22 pm
- Contact:
Re: [Scripting Assistance] Help identifying mining drill functions
How I would do it is the following:DwarfTech wrote: ↑Wed Dec 08, 2021 7:21 am-The location of the particular drill that runs out of resources
-The event on_resource_depleted, to actually trigger the resupply
-A variable to reference mining drills, which I assume would run under the on_resource_depleted function to then call for and locate the corresponding drill entities
-Not all sure what else. I'm a doof, and still very green to the whole lua scripting thing. I'll keep trying and studying mods that look up drills with depleted resources, and hopefully get something functional up. By any chance, for the sake of development, is there a good way to have each function run a message in the chat so I can verify that each command is, in fact, getting run properly?
- Listen to on_resource_depleted as you mentioned. For a start add a simple "print" to the handler and see if it's called. The rest of the steps will all happen in this event handler.
- This function gives you "local drill = event.entity", which is the mining drill that was depleted. You will have to check here that it's indeed a mining drill though, and not a pumpjack for example. You could do this by simply "if event.entity.type ~= "mining-drill" then return end"
- Make sure that there is no resources left that this drill can mine. I haven't tested this, but a drill can reach like 25 resource tiles? And this handler will fire when any one of those tiles get depleted. You could probably check this with "if drill.active then return end", because if the drill is still active then it likely still has resources to mine. (See Point 5.)
- Add the stone resource at "drill.position"
- Reactivate the drill. When drills run out of resources they go sleep IIRC, so you would need to "drill.active = true" again. Otherwise the drill won't notice the new resource.
Alt-F4 Author | Factorio Modder
Mods: Hall of Fame | Better Victory Screen | Fluidic Power | Biter Power | Space Spidertron | Spidertron Dock | Weasel's Demolition Derby
Mods: Hall of Fame | Better Victory Screen | Fluidic Power | Biter Power | Space Spidertron | Spidertron Dock | Weasel's Demolition Derby
Re: [Scripting Assistance] Help identifying mining drill functions
Pumpjacks are mining drills, just with a different category. A better option here would be to check the entity's prototype mining category(ies) to see if it can mine stone.Stringweasel wrote: ↑Wed Dec 08, 2021 7:53 amThis function gives you "local drill = event.entity", which is the mining drill that was depleted. You will have to check here that it's indeed a mining drill though, and not a pumpjack for example. You could do this by simply "if event.entity.type ~= "mining-drill" then return end"
- Stringweasel
- Filter Inserter
- Posts: 315
- Joined: Thu Apr 27, 2017 8:22 pm
- Contact:
Re: [Scripting Assistance] Help identifying mining drill functions
Haha oops I probably meant to type <entity.name == "mining-drill">, but PFQNiet's way is much more resiliant.
Alt-F4 Author | Factorio Modder
Mods: Hall of Fame | Better Victory Screen | Fluidic Power | Biter Power | Space Spidertron | Spidertron Dock | Weasel's Demolition Derby
Mods: Hall of Fame | Better Victory Screen | Fluidic Power | Biter Power | Space Spidertron | Spidertron Dock | Weasel's Demolition Derby
Re: [Scripting Assistance] Help identifying mining drill functions
I believe the entity in the event is the RESOURCE ENTITY that was depleted, not a mining drill/pumpjack. You couldn't rely on that anyway, since one resource can be mined by several miners, so it could result in more than one being out of resources. You'd have to search the area, and you'd have to ensure the area is large enough that any miner in reach is found.Stringweasel wrote: ↑Wed Dec 08, 2021 7:53 am
- Listen to on_resource_depleted as you mentioned. For a start add a simple "print" to the handler and see if it's called. The rest of the steps will all happen in this event handler.
-
- Smart Inserter
- Posts: 2530
- Joined: Tue Apr 25, 2017 2:01 pm
- Contact:
Re: [Scripting Assistance] Help identifying mining drill functions
Which, considering mod miners, may be more trouble than it's worth. That said, if you're replacing the resource tiles with stone as they are depleted, then unless that was the only tile the miner could reach, then it should never enter the disabled state anyway? So leaving it up to the player to replace the edge case miners may not be a huge deal.Silari wrote: ↑Wed Dec 08, 2021 11:38 pmI believe the entity in the event is the RESOURCE ENTITY that was depleted, not a mining drill/pumpjack. You couldn't rely on that anyway, since one resource can be mined by several miners, so it could result in more than one being out of resources. You'd have to search the area, and you'd have to ensure the area is large enough that any miner in reach is found.Stringweasel wrote: ↑Wed Dec 08, 2021 7:53 am
- Listen to on_resource_depleted as you mentioned. For a start add a simple "print" to the handler and see if it's called. The rest of the steps will all happen in this event handler.
My Mods: Classic Factorio Basic Oil Processing | Sulfur Production from Oils | Wood to Oil Processing | Infinite Resources - Normal Yield | Tree Saplings (Redux) | Alien Biomes Tweaked | Restrictions on Artificial Tiles
- Stringweasel
- Filter Inserter
- Posts: 315
- Joined: Thu Apr 27, 2017 8:22 pm
- Contact:
Re: [Scripting Assistance] Help identifying mining drill functions
Ah yes of course. So what I'd do is wait for the depletion event, and then on the event search for miners that can reach that resource. Then for each of those miners you will have to check if it still has access to any other resourse tiles. And if it doesn't, then continue creating the stone patch.Silari wrote: ↑Wed Dec 08, 2021 11:38 pmI believe the entity in the event is the RESOURCE ENTITY that was depleted, not a mining drill/pumpjack. You couldn't rely on that anyway, since one resource can be mined by several miners, so it could result in more than one being out of resources. You'd have to search the area, and you'd have to ensure the area is large enough that any miner in reach is found.Stringweasel wrote: ↑Wed Dec 08, 2021 7:53 am
- Listen to on_resource_depleted as you mentioned. For a start add a simple "print" to the handler and see if it's called. The rest of the steps will all happen in this event handler.
I don't really agree that it's too much trouble. You only need to find the maximum miner size once on startup by going through the prototypes. And nobody likes babysitting miners That's the entire idea of this mod.FuryoftheStars wrote: ↑Thu Dec 09, 2021 2:34 amWhich, considering mod miners, may be more trouble than it's worth. That said, if you're replacing the resource tiles with stone as they are depleted, then unless that was the only tile the miner could reach, then it should never enter the disabled state anyway? So leaving it up to the player to replace the edge case miners may not be a huge deal.
The initial functionality sounds a lot like Auto Deconstruct, which will likely need to follow these exact steps. Only difference is your mod will not mark it for deconstruction, but rather spawn your stone patch. You can check out how Auto Deconstruct does it.
Alt-F4 Author | Factorio Modder
Mods: Hall of Fame | Better Victory Screen | Fluidic Power | Biter Power | Space Spidertron | Spidertron Dock | Weasel's Demolition Derby
Mods: Hall of Fame | Better Victory Screen | Fluidic Power | Biter Power | Space Spidertron | Spidertron Dock | Weasel's Demolition Derby