[MOD 0.15] Scriptable Drones v0.4.0

Topics and discussion about specific mods
Post Reply
tesseractcat
Burner Inserter
Burner Inserter
Posts: 5
Joined: Sun Sep 17, 2017 8:33 pm
Contact:

[MOD 0.15] Scriptable Drones v0.4.0

Post by tesseractcat »

Scriptable Drones
This mod adds drones which can be scripted in lua to do things that you need. Think computercraft turtles, but in Factorio.


Details
Type: Mod
Name: Scriptable Drones
Description: Adds drones scriptable in lua
License: MIT
Version: 0.4.0
Release: 2017-09-something
Tested-With-Factorio-Version: 0.15.21
Category: New Entity
Tags: Bots
Download-Url: https://mods.factorio.com/mods/tesserac ... ble-drones

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. Check out the mod portal page for the API documentation!

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
  • Miscellaneous crashing
Version History
Last edited by tesseractcat on Fri Sep 22, 2017 2:03 am, edited 5 times in total.

abordoli
Fast Inserter
Fast Inserter
Posts: 131
Joined: Thu May 25, 2017 1:19 am
Contact:

Re: [MOD 0.15] Scriptable Drones v0.1.0

Post by abordoli »

Can we see an example of a "script" that does something neat?

...and how would you edit the script, etc.?

tesseractcat
Burner Inserter
Burner Inserter
Posts: 5
Joined: Sun Sep 17, 2017 8:33 pm
Contact:

Re: [MOD 0.15] Scriptable Drones v0.1.0

Post by tesseractcat »

Well, I haven't actually made anything substantial yet, but I did make this one script that makes the robot move in a small square: https://pastebin.com/tAuVPfpy. To edit scripts, just make a bot, click on it to open the shell, and then write "edit [scriptname]".

abordoli
Fast Inserter
Fast Inserter
Posts: 131
Joined: Thu May 25, 2017 1:19 am
Contact:

Re: [MOD 0.15] Scriptable Drones v0.1.0

Post by abordoli »

I feel it has great potential and you've given alot of great script commands. Can't wait to see what others create.

Airat9000
Smart Inserter
Smart Inserter
Posts: 1418
Joined: Fri Mar 28, 2014 12:32 am
Contact:

Re: [MOD 0.15] Scriptable Drones v0.1.0

Post by Airat9000 »

A good mod! just allows many to learn programming through the game

:roll:

User avatar
Adil
Filter Inserter
Filter Inserter
Posts: 945
Joined: Fri Aug 15, 2014 8:36 pm
Contact:

Re: [MOD 0.15] Scriptable Drones v0.1.0

Post by Adil »

Hi, it's nice to see such mod done.
However, I did a peek into the code and there are some things I don't quite understand and some that I want to object to:
1
2
3
4
5
6
7
7a
I do mods. Modding wiki is friend, it teaches how to mod. Api docs is friend too...
I also update mods, some of them even work.
Recently I did a mod tutorial.

tesseractcat
Burner Inserter
Burner Inserter
Posts: 5
Joined: Sun Sep 17, 2017 8:33 pm
Contact:

Re: [MOD 0.15] Scriptable Drones v0.2.0

Post by tesseractcat »

Thanks for the suggestions! With version 0.2.0 I believe I have fixed everything mentioned :)

hreintke
Fast Inserter
Fast Inserter
Posts: 115
Joined: Mon Sep 04, 2017 6:52 pm
Contact:

Re: [MOD 0.15] Scriptable Drones v0.2.0

Post by hreintke »

Nice functionality.

First questions :

- Is there a possibility to update the speed of the bot ?
- Is thee a possibility to provide the bot a scripts without manually typing a run command ?

Relik
Burner Inserter
Burner Inserter
Posts: 14
Joined: Tue Sep 19, 2017 3:49 pm
Contact:

Re: [MOD 0.15] Scriptable Drones v0.2.0

Post by Relik »

Good mod but you must add some functionality.
I was a fan of the computercraft mod of Minecraft, but in factorio there are already systems to automate almost everything. So we have to do more than is already possible ;)

I might have some ideas:
- A flying robot for fast travel and transport
- A ground robot to defend (patrol), slow movement but has a grid with the possibility of using the weapon that is given to him (gun, flamethrower, etc.)

Add a feature to scan an area around the robot, and identify: resources, enemies and more (a array of type ?)

Of course, nothing magic but input signals and programming
Maybe it could also listen / send a wifi signal on a network (using the network identifier) ?

If this can give you ideas, I would be delighted :)


_________
Sorry if my English is not very good, I speak fluently 2 languages: French and some programming languages ^^

tesseractcat
Burner Inserter
Burner Inserter
Posts: 5
Joined: Sun Sep 17, 2017 8:33 pm
Contact:

Re: [MOD 0.15] Scriptable Drones v0.2.0

Post by tesseractcat »

Although I was not able to implement everything suggested, here are some of the features suggested that I added for version 0.3.0:
- For wifi, I added the register_net_call and get_net_call functions, to allow intrabot communication
- For input signals, I added the input function, which allows registering an input callback, along with a new run menu
- For detecting ores and enemies, I added the detect_range function, which allows detecting entities in a range up to 20

For defense drones, it can already be implemented by simply placing down a turret and then loading it with ammo, using a script such as:

Code: Select all

bot:select(1)
bot:place_item()
bot:select(2)
bot:container_insert("gun-turret", 10, defines.inventory.turret_ammo)
And here's a gif of it in action:


For speed, right now I am happy with the speed, however I may consider adding support for alternative fuel types in the future.

For running scripts without the run command, hopefully this should be possible in the near future, I am hoping to implement some sort of disk drive that can be used to transfer programs.

That's all for v0.3.0 :) !

Relik
Burner Inserter
Burner Inserter
Posts: 14
Joined: Tue Sep 19, 2017 3:49 pm
Contact:

Re: [MOD 0.15] Scriptable Drones v0.3.0

Post by Relik »

Cool, and fast :)

But, I have a small bug on my side: When I place the drone, it seems to be changing in construction bot (graphic) and goes in the nearest roboport :(
(No other mod installed)

tesseractcat
Burner Inserter
Burner Inserter
Posts: 5
Joined: Sun Sep 17, 2017 8:33 pm
Contact:

Re: [MOD 0.15] Scriptable Drones v0.4.0

Post by tesseractcat »

With v0.4.0, that bug should have been fixed, along with that, here is the changelog for 0.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.
Nfc file copy should fullfill the need of running scripts without using the "run" command. One thing to note: this version is incompatible with older versions of the mods. This means that you need to destroy and replace bots from old mod versions.

Relik
Burner Inserter
Burner Inserter
Posts: 14
Joined: Tue Sep 19, 2017 3:49 pm
Contact:

Re: [MOD 0.15] Scriptable Drones v0.4.0

Post by Relik »

Hello,
I tested a small mining program and at the end of an ore I have the following error, while there is still 1 ore and not 0.
Image
I have tested different variants and I have not found how to bypass the error (the example given also causes the error)
The ideal would be to have a function to know the remaining quantity in the resource field under the bot. (bot: get_field_data (ore_name, range)? range would also be able to evaluate the richness of an entire field of resources and emit signals when it is impoverished)

It was also good to have a listing of the functions available from the bot's interface. man / help bot?
Attachments
Capture.JPG
Capture.JPG (38.23 KiB) Viewed 7596 times

Relik
Burner Inserter
Burner Inserter
Posts: 14
Joined: Tue Sep 19, 2017 3:49 pm
Contact:

Re: [MOD 0.15] Scriptable Drones v0.4.0

Post by Relik »

Hello,
Out of curiosity, I look at the mod code.
I propose some modifications:

In the "detect_range" function, replace:

Code: Select all

out_arr[v.name] = {pos = v.position}
By :

Code: Select all

if out_arr[v.name] == nill then
    out_arr[v.name] = {}
end
if v.type == "resource" then
    out_arr[v.name][#out_arr[v.name] + 1] = {pos = v.position, amount = v.amount}
else
    out_arr[v.name][#out_arr[v.name] + 1] = {pos = v.position}
end
For fix mining process bug, replace :

Code: Select all

v.amount = v.amount - 1
By :

Code: Select all

if v.amount == 1 then
    v.destroy()
else
    v.amount = v.amount - 1
end
In "help" function :

Code: Select all

if params == "bot" then
    return [[Available bot functions:
bot:get_pos() = Gets drone position object
bot:get_marker_pos(marker_name) = Gets marker position object
bot:move(pos_object,[callback]) = Move to position object, [optional] run callback when done
bot:move_offset(offx,offy,[callback]) = Move to offset, [optional] run callback when done
bot:move_to_marker(marker_name,[callback]) = Moves to marker position, [optional] run callback when done
bot:wait(callback,timeout_secs) = Run callback after certain amount of time
bot:update(callback) = Run callback every tick
bot: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 entered
bot:select(index) = Selects index in drone inventory (1 - 5)
bot:get_stack() = Gets what is in a stack at the index in the SimpleItemStack format
bot:drop_item(count) = Drops count of what is at index in inventory to the ground
bot:place_item() = Places one of the items at index (if placeable)
bot:destroy(object_name) = Destroys the object if it is below the drone
bot:retrieve_item(object_name) = Picks up the object if it is below the drone
bot:detect_entities() = Detects what entities are below the bot, returns an array of names
bot:detect_range(range) = Detects entities in a range up to 20, returns a table with name as key, and a table with a pos 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 types
bot: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 types
bot: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 production
bot: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 function
bot:get_net_call(name) = Returns the callback named name, which you can then run
bot: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.
]]
else
    return [[Available commands:
ls - List files and directories
mkdir <dir name> - Create directory
edit <file name> - Edit file
remove <file/dir name> - Remove file or directory
cls - Clear the screen (not implemented yet)
lua <code> - Runs a line of lua code
run <file name> - Runs a script file
stop - Stops all running scripts
debug - Prints debug info (position, unit_number, etc.)
credits - Prints mod developer credits
help bot - Prints bot functions
]]
    end

tomr-r
Manual Inserter
Manual Inserter
Posts: 1
Joined: Tue Nov 07, 2017 3:04 pm
Contact:

Re: [MOD 0.15] Scriptable Drones v0.4.0

Post by tomr-r »

hi
can anyone help me I want to put a program on more bots is there a way to do this without having to copy and paste it.

if anyone can help me I will be grateful

Post Reply

Return to “Mods”