Space Engineers

Space Engineers

Rdav's AI Autominer Script
jfullernz 9 Apr, 2019 @ 10:12pm
Code update to recharge Battery
Ive been having the same problem as many, with my ship being stranded and lost between roids when it runs out of power, so I got to working on it (Sorry rdav I did edit the code below the line).
First, the display:
In Mining Logic, underneath Echo("Version: " + VERSION + "\n"); add the following...
var batteries = new List<IMyTerminalBlock>();
GridTerminalSystem.GetBlocksOfType<IMyBatteryBlock>(batteries);
IMyBatteryBlock thisBattery = batteries[0] as IMyBatteryBlock;
BatteryLevel.Val = thisBattery.CurrentStoredPower*100;
Echo("Battery Level: " + Math.Round(BatteryLevel.Val)+ "%\n");


At //If Empty And Docked And Want To Go Mine, Undock (stage 2)
change if (COORD_ID.Val != 0 && MININGSTATUS.Val == "MINE")
to if (COORD_ID.Val != 0 && MININGSTATUS.Val == "MINE" && BatteryLevel.Val>80.00)
the 80.00 can be adjusted to whatever percentage battery level you want to have before takeoff.

In RC Manager Add the following with the similiar types:
Savable_Double BatteryLevel = new Savable_Double();

The Full copy/paste script here for those not wanting to modify the code directly https://pastebin.com/GPgTMKUg

Rdav, maybe you could include this (or a tidier code) into the next release since people have been asking for it since last year?
Last edited by jfullernz; 9 Apr, 2019 @ 11:43pm
< >
Showing 1-15 of 19 comments
Rdav  [developer] 10 Apr, 2019 @ 2:37am 
Nice implementation, truth be told I've been sitting on the next script release for some time now just getting some time to make the artwork/video to release it, hence also why I've been holding back for some time on updates to this version, but the next version will be including a battery monitor, amongst many other things,

The implementation is good however I'd have to wiggle some things around to make it work,
As a general rule for ingame programming GridTerminalSystem Calls are very performance intensive, so Id be reluctant to put them in the Main method where it would be called every 6th tick, instead I'd probably find and cache the batteries in a startup operation,

But thanks for the effort, I'm likely going to release the new one soon, so hold tight until then!
It should be incorperating a lot better feature set too
jfullernz 10 Apr, 2019 @ 3:35am 
Thanks Rdav, to be honest it was a quick slap together, because it annoyed the hell out of me. I had seen the last release was nearly a year ago so wasnt sure if you were actively updating it anymore.
I knew the code needed refining and optimizing but a quick fix for those who were as desperate as I was helps :) Always difficult modifying someone elses source code though as the styles are completely different to what I am familiar with.
Rdav  [developer] 10 Apr, 2019 @ 4:01am 
Originally posted by jfullernz:
Thanks Rdav, to be honest it was a quick slap together, because it annoyed the hell out of me. I had seen the last release was nearly a year ago so wasnt sure if you were actively updating it anymore.
I knew the code needed refining and optimizing but a quick fix for those who were as desperate as I was helps :) Always difficult modifying someone elses source code though as the styles are completely different to what I am familiar with.
No worries!
Mine is no exception, being self taught I've tended to adopt some uh, less than conventional bad habits at times, heh,
Either way, sit tight, it should be very soon!
Kitsu Shadow 20 Jul, 2019 @ 6:59pm 
@jfullernz i am using the pastebin you have of the code but its not returning to base when the batteries are low. any idea what to look for?
jfullernz 21 Jul, 2019 @ 3:27am 
@spikespiegel19 return to base I am unsure on where to look, the code was origionally produced by rdav. My own code was a modification to keep the ship docked until recharged rather than a return sequence. I halted any further work on it since rdav mentioned above that he was going to be releasing a new release.
Blue64 6 Jan, 2020 @ 7:43am 
looking forward to it Rdav, glad to hear you've been wanting to stay on top of this, and I gotta give you props on being self taught in C# cause that's super rough.
b2198 27 Apr, 2020 @ 10:31pm 
So, since I had the same battery issues mentioned here, I modified jfullernz's code a bit:

instead of
GridTerminalSystem.GetBlocksOfType<IMyBatteryBlock>(batteries);
I used
GridTerminalSystem.GetBlocksOfType<IMyBatteryBlock>(batteries, b => b.CubeGrid == Me.CubeGrid);
So that it only checks the batteries on the same grid, not on all connected grids.

instead of
BatteryLevel.Val = thisBattery.CurrentStoredPower*100;
I used
BatteryLevel.Val = thisBattery.CurrentStoredPower*100 / thisBattery.MaxStoredPower;
To get the percentage of the battery

And I added the following lines:
//If Low Battery Go And Recharge
if (BatteryLevel.Val<20.00 && ISNOTBURIED.Val)
{
DockingIterator(true, DOCK_ROUTE, GYRO, CONNECTOR, RC);
Echo("Status: Docking To Recharge");
return;
}
to MiningLogic, between
//If Full Go And Free Dock (stage 1)
if (MININGSTATUS.Val == "FULL" && ISNOTBURIED.Val)
{
DockingIterator(true, DOCK_ROUTE, GYRO, CONNECTOR, RC);
Echo("Status: Docking To Offload");
return;
}
and
//If Empty And Docked And Want To Go Mine, Undock (stage 2)

So that it checks the battery while mining and goes back if the battery has less than 20% of the power left
Rdav  [developer] 28 Apr, 2020 @ 2:33am 
nice edit, I very much enjoy that the code has spawned community made edits like these!
IntrinsicVoid 29 May, 2020 @ 11:19am 
@Rdav when can we expect the updated version? Are you still working on it or is it up somewhere else?
Last edited by IntrinsicVoid; 29 May, 2020 @ 11:19am
Blue64 6 Jun, 2020 @ 3:00pm 
Originally posted by IntrinsicVoid:
@Rdav when can we expect the updated version? Are you still working on it or is it up somewhere else?
hell, I'd be happy with just it getting that script addition for now, that's probably causing many a user heartache.
Taegost 16 Jun, 2020 @ 11:21am 
I created a GitHub gist with code updates from jfullernz and b2198. I did not include the code to stop mining if the battery level gets too low because I don't use it at the moment and didn't want to mess around with it. Here's the link: https://gist.github.com/Taegost/b4434a8533a4297227764cc7a2a9a1ed
Rdav - If you'd like to create a GitHub repo for it, I'd be more than happy to help with script updates to include some of these ideas in a more configurable and less hard-coded way, so you won't have to do all the work.
Last edited by Taegost; 4 Jul, 2020 @ 6:53am
miku567 3 Jul, 2020 @ 12:13pm 
Can you post the link to that github repo?
Taegost 4 Jul, 2020 @ 6:53am 
Originally posted by miku567:
Can you post the link to that github repo?
Sorry, thought that I had included it, I updated my comment to have it.
Dude 19 Feb, 2021 @ 9:38pm 
I've tried using the updated code on github seems to be continuously flipping collision avoidance on and off. It works for the first run but after dropping ore/stone it just continuously flips and doesn't mine.
jfullernz 20 Feb, 2021 @ 12:59am 
Originally posted by Dude:
I've tried using the updated code on github seems to be continuously flipping collision avoidance on and off. It works for the first run but after dropping ore/stone it just continuously flips and doesn't mine.
Unfortunately this code update is years old so it wouldnt suprise me if it no longer works :)
I havent played SE in awhile so havent actually tested in a long time if it still works
< >
Showing 1-15 of 19 comments
Per page: 1530 50