So Hello there 
I had the problem that npc-traders couldn't reach my stations, since too many asteroids were blocking the way. But what to do ? Farm 2000+ asteroids yourself, since your npc ships are too lazy doing this ? No mods around there for doing this
at least none I found.
Good thing though I'm a software developer IRL, so I gave this a try, let me introduce you to my very first mod
Caution: These are my very first experiences with lua !! Create backups before using this! I might have done some mistakes I'm not aware of yet! Lua is an entirely new coding-language for me!1. What does this mod exactly do?Pretty simple to explain.
Normal behaviour of commanding your ship to mine: It starts mining ressource asteroids and once there are no more, it tells you "Yo captain, everything is mined. I'll get a cup of coffee and relax. Peace!"
Changed behaviour by using my mod:Regular mining behaviour still entirely happens as before. Means: Miners will look out for resource asteroids (also using all the same AI as it did before). Once all ressource asteroids are gone, it will tell you the message:
"Sir, we can't find any more asteroids in (sector)! We continue farming normal asteroids."
They continue as said. Once, ALL asteroids are gone, it will post you the message:
"All asteroids in (sector) are gone."
Any reactivation or new order has to be done by the player himself. Ship is set to idle. Ofc this whole thing does also work when there aren't any resource asteroids right in the beginning. You just get the insta message, no more resource asteroids are there to mine, continueing with the normal ones
2. Requirements:2.1 Game Version "Beta 0.17.1 r12316 a186915a28c6" or "Beta 0.18.3 r12783 a1770b4cb86e"
Other game versions might malfunction this mod, since there could be changes to farming behaviour !
2.2 No other mods installed that influence the mining-behaviour
It depends, which stuff changed - but if this mod gets in touch with another mod it could be that it won't live in harmony together. I will post 2 ways to implement it, way 1 download file and put in, way 2 implement it yourself using my posted source code (advanced)
3. Implementing the mod3.1 Referring to 2.2, this is the "easy" way, make sure all the described conditions are met, just go ahead, download the file "mine.zip", unzip it, and place the included "mine.lua" into "Steam\steamapps\common\Avorion\data\scripts\entity\ai". Replace it with the existing file.
IMPORTANT: Create a Backup of the original file inbefore, if anything goes wrong!
3.2 Referring to 2.2, this is the "advanced" way of implementing the code yourself.
Find the file mine.lua, as mentioned in the path above.
HINT: Use a program for making the change of code easier for yourself. I suggest Notepad++
HINT2: As I already said above, one more reminder, Create a backup of this file!!
First of all, the "vanilla" untouched main function I touched is this one (Starting at line 85, ending at line 133):
-- check the sector for an asteroid that can be mined
-- if there is one, assign minedAsteroid
function AIMine.findMinedAsteroid()
local radius = 20
local ship = Entity()
local sector = Sector()
minedAsteroid = nil
local mineables = {sector:getEntitiesByComponent(ComponentType.MineableMaterial)}
local nearest = math.huge
for _, a in pairs(mineables) do
if a.type == EntityType.Asteroid then
local resources = a:getMineableResources()
if resources ~= nil and resources > 0 then
local dist = distance2(a.translationf, ship.translationf)
if dist < nearest then
nearest = dist
minedAsteroid = a
end
end
end
end
if minedAsteroid then
noAsteroidsLeft = false
broadcastInvokeClientFunction("setMinedAsteroid", minedAsteroid.index)
else
if noAsteroidsLeft == false then
noAsteroidsLeft = true
local player = Player(Entity().factionIndex)
if player then
local x, y = Sector():getCoordinates()
local coords = tostring(x) .. ":" .. tostring(y)
player:sendChatMessage(ship.name or "", ChatMessageType.Error, "Your mining ship in sector %s can't find any more asteroids."%_T, coords)
player:sendChatMessage(ship.name or "", ChatMessageType.Normal, "Sir, we can't find any more asteroids in \\s(%s)!"%_T, coords)
end
ShipAI(ship.index):setPassive()
ship:invokeFunction("craftorders.lua", "setAIAction")
end
end
end
What you gotta do, is first involve local variables. Right on top in the first few lines, you will find the line:
local noAsteroidsLeft = true
Create a new line right after this. Then insert these here:
local firstmsg = false
local check1 = false
local check2 = false
local check3 = false
After that, head for the line:
function AIMine.findMinedAsteroid()
(you will find it in about the middle)
When you found the beginning, you have to find the end of it, since you will have to replace this whole function with mine.
You will find the end tag of it just above the starting of the function "function AIMine.updateMining(timeStep)", THIS LINE ITSELF NOT INCLUDED! So just head for the "function AIMine.findMinedAsteroid()" to "end" and replace it with this function:
function AIMine.findMinedAsteroid()
if check3 == false then
local radius = 20
local ship = Entity()
local sector = Sector()
local player = Player(Entity().factionIndex)
local x, y = Sector():getCoordinates()
local coords = tostring(x) .. ":" .. tostring(y)
local mineables
local nearest
local resources
minedAsteroid = nil
if check1 == false then -- Fange mit Resourcen-Asteroiden an
mineables = {sector:getEntitiesByComponent(ComponentType.MineableMaterial)}
nearest = math.huge
for _, a in pairs(mineables) do
if a.type == EntityType.Asteroid then
resources = a:getMineableResources()
if resources ~= nil and resources > 0 then
local dist = distance2(a.translationf, ship.translationf)
if dist < nearest then
nearest = dist
minedAsteroid = a
end
end
end
end
if minedAsteroid then
broadcastInvokeClientFunction("setMinedAsteroid", minedAsteroid.index)
else
check1 = true
end
end
if check1 == true and check2 == false then -- Keine Resourcen-Asteroiden sind mehr vorhanden. Mache mit normalen weiter.
if firstmsg == false then
player:sendChatMessage(ship.name or "", ChatMessageType.Error, "No more asteroids in sector %s. We continue farming normal asteroids."%_T, coords)
player:sendChatMessage(ship.name or "", ChatMessageType.Normal, "Sir, we can't find any more asteroids in \\s(%s)! We continue farming normal asteroids."%_T, coords)
firstmsg = true
end
mineables = {sector:getEntitiesByType(EntityType.Asteroid)}
nearest = math.huge
for _, a in pairs(mineables) do
if a.type == EntityType.Asteroid then
dist = distance2(a.translationf, ship.translationf)
if dist < nearest then
nearest = dist
minedAsteroid = a
end
end
end
if minedAsteroid then
noAsteroidsLeft = false
broadcastInvokeClientFunction("setMinedAsteroid", minedAsteroid.index)
else
noAsteroidsLeft = true
check2 = true
end
end
if check1 == true and check2 == true then -- Garkeine Asteroiden sind mehr vorhanden. Lege Arbeit nieder.
player:sendChatMessage(ship.name or "", ChatMessageType.Error, "All asteroids in %s are gone."%_T, coords)
player:sendChatMessage(ship.name or "", ChatMessageType.Normal, "All asteroids in \\s(%s) are gone."%_T, coords)
ShipAI(ship.index):setPassive()
ship:invokeFunction("craftorders.lua", "setAIAction")
check3 = true
end
end
end
4. A few wordsAs I said, this is my first one. Big shoutout to the user "Laserzwei", he assisted me a little bit with the creation of the mod and some help of lua in general.
If you find anything to improve, feel free to share it with me, since I like the game and want to improve my lua skills fast. There is for example 1 thing I don't understand yet - these lines seem to not work at all:
ShipAI(ship.index):setPassive()
ship:invokeFunction("craftorders.lua", "setAIAction")
Why?

As I understand, it should set the ship to passive mode. I did a workaround by just using "check3" to bypass the mine-command.
Any feedback about this mod is deeply appreciated, I do, as everyone like props for my work

Feel free to use this mod for your very own creation of mods, a referral of this mod here would be nice though.
Sincerely, DestroNK