Scriptable Drones
This mod adds drones which can be scripted in lua to do things that you need. Think computercraft turtles, but in Factorio.
Forum post: https://forums.factorio.com/viewtopic.php?f=93&t=52695
Command Line Usage
The help
command should give you all the info you need. The command line simulates a basic shell, with a few utility functions. Feel free to request new command line features.
API
Your gateway from Lua to the Factorio world is the bot
object. The bot object provides these functions:
bot:get_pos()
= Gets drone position objectbot:get_marker_pos(marker_name)
= Gets marker position objectbot:move(pos_object,[callback])
= Move to position object, [optional] run callback when donebot:move_offset(offx,offy,[callback])
= Move to offset, [optional] run callback when donebot:move_to_marker(marker_name,[callback])
= Moves to marker position, [optional] run callback when donebot:wait(callback,timeout_secs)
= Run callback after certain amount of timebot:update(callback)
= Run callback every tickbot:print(text)
= Runs print with text, will automatically convert tables to readable strings for debugging purposes :)bot:input(prompt, callback)
= Prints prompt, and then runs callback with the input parameter when input is enteredbot:select(index)
= Selects index in drone inventory (1 - 5)bot:get_stack()
= Gets what is in a stack at the index in the SimpleItemStack formatbot:drop_item(count)
= Drops count of what is at index in inventory to the groundbot:place_item()
= Places one of the items at index (if placeable)bot:destroy(object_name)
= Destroys the object if it is below the dronebot:retrieve_item(object_name)
= Picks up the object if it is below the dronebot:detect_entities()
= Detects what entities are below the bot, returns an array of namesbot:detect_range(range)
= Detects entities in a range up to 20, returns a table with name as key, and a table with apos
attribute with the objects position as the value, ex.{player={pos={x=10,y=10}},otherentity={pos={...}}}
bot:container_insert(container_name, count, [inventory_type])
= Inserts count of item at index into the container of container-name if it is below the bot, [optional] specify container type, see defines container typesbot:container_retrieve(container_name, item_name, count, [inventory_type])
= Retrieves count of item_name from container_name if it is below the bot, [optional] specify container type, see defines container typesbot:get_item_prod_data()
= Gets item production data, returns an array with the format{inputs=[name=value,name2=value2], outputs=[...]}
bot:get_fluid_prod_data()
= Same as get_item_prod_data, but for fluid productionbot:get_electric_data()
= Same as get_item_prod_data, but requires the bot to be above an electric pole, (I actually do not understand the format that electric poles return for production data, but I will update this when I do)bot:register_net_call(name, callback)
= Registers a callback on the drone network, can be called with the next functionbot:get_net_call(name)
= Returns the callback named name, which you can then runbot:mine(ore_name, callback)
= Mines the ore. Runs callback when the ore is done being mined. Callback is REQUIRED or ore will not be mined.bot:nfc_copy_file(source_file, [run_on_copy])
= Copies the source file to the closest drone (1 tile away range). [optional] If run_on_copy is true, it will automatically start the file on the bot that it is copied to.
An example script with a usage for many of these functions is provided here.
Marker usage
Simply craft a marker, and click on it to set it's position name.
TODO
What should be done in the future:
- Bot networking
- Displays that bots can connect to
- Power and charging system
- Lower tier coal power bots
- Suggestions welcome
Things to be wary about
Problems that need to be fixed:
- Multiplayer has not been tested, don't expect it to work consistently. Please report any desyncs/errors you get in multiplayer to the forum post.
- Sometimes when running, the game will exit due to code errors, if you run into this, please take a screenshot and send it to me along with a description of what you were doing
Version History
v0.4.5 - Compatibility patch for multiplayer
v0.4.0 - Stability fixes, api fixes, changed from using construction bot entity to using simple entity, added bot rotation, added nfc_copy_file, mine, added computer-position-markers, added move_to_marker. note: NOT COMPATIBLE WITH PREVIOUS RELEASES, please destroy and replace drones in old saves
v0.3.0 - Added network callbacks, detect_range, new run gui, and input
v0.2.0 - Fixed crashing on malformed scripts, cleaned code, added production and inventory management bot api functions
v0.1.0 - Initial release