diff options
Diffstat (limited to 'clientmods/mapbot')
-rw-r--r-- | clientmods/mapbot/api.lua | 41 | ||||
-rw-r--r-- | clientmods/mapbot/init.lua | 10 | ||||
-rw-r--r-- | clientmods/mapbot/mod.conf | 3 | ||||
-rw-r--r-- | clientmods/mapbot/simple_bots.lua | 30 |
4 files changed, 84 insertions, 0 deletions
diff --git a/clientmods/mapbot/api.lua b/clientmods/mapbot/api.lua new file mode 100644 index 000000000..8d7398b56 --- /dev/null +++ b/clientmods/mapbot/api.lua @@ -0,0 +1,41 @@ +mapbot.bots = {} + +mapbot.paramtypes = { + ["pos"] = { + "<X>,<Y>,<Z>", + function (param) + local _, pos = minetest.parse_relative_pos(param) + return pos + end + }, + ["nodes"] = { + "<node1> [<node2>] ...", + function (param) + return param:split(" ") + end + }, +} + +function mapbot.register_bot(name, description, paramtype, func) + local pt = mapbot.paramtypes[paramtype] + if not pt then return end + minetest.register_chatcommand(name, { + param = pt[1], + description = description .. " Empty parameter to stop.", + func = function(param) + mapbot.storage:set_string(name, param) + return true, "Changed " .. name .. " config." + end + }) + table.insert(mapbot.bots, {name, pt, func}) +end + +function mapbot.loop() + for _, bot in pairs(mapbot.bots) do + local param = mapbot.storage:get_string(bot[1]) + param = (param == "") and nil or bot[2][2](param) + if param and bot[3](param) end + end +end + +minetest.register_on_connect(mapbot.loop) diff --git a/clientmods/mapbot/init.lua b/clientmods/mapbot/init.lua new file mode 100644 index 000000000..4b2a73fe4 --- /dev/null +++ b/clientmods/mapbot/init.lua @@ -0,0 +1,10 @@ +mapbot = {} + +local modname = minetest.get_modname() +local modpath = minetest.get_modpath(modname) +mapbot.storage = minetest.get_mod_storage() + +dofile(modpath .. "/api.lua") +dofile(modpath .. "/simple_bots.lua") + + diff --git a/clientmods/mapbot/mod.conf b/clientmods/mapbot/mod.conf new file mode 100644 index 000000000..63c81f480 --- /dev/null +++ b/clientmods/mapbot/mod.conf @@ -0,0 +1,3 @@ +name = misc +author = Fleckenstein +description = An API to create simple bots, optimized for map interaction diff --git a/clientmods/mapbot/simple_bots.lua b/clientmods/mapbot/simple_bots.lua new file mode 100644 index 000000000..30b44f81b --- /dev/null +++ b/clientmods/mapbot/simple_bots.lua @@ -0,0 +1,30 @@ +mapbot.register_bot("place_into", "Automatically place wielditem into specified nodes.", "nodes", function(nodes) + local pos = minetest.find_node_near(minetest.localplayer:get_pos(), 5, nodes, true) + if pos then + minetest.place_node(pos) + end +end) + +mapbot.register_bot("dig_nodes", "Automatically dig specified nodes.", "nodes", function(nodes) + local pos = minetest.find_node_near(minetest.localplayer:get_pos(), 5, nodes, true) + if pos then + minetest.dig_node(pos) + end +end) + +mapbot.register_bot("place_into_pos", "Automatically place wielditem at specified pos.", "pos", minetest.place_node) + +mapbot.register_bot("dig_pos", "Automatically dig node at specified pos.", "pos", minetest.dig_node) + +mapbot.register_bot("dig_place_nodes", "Automatically dig specified nodes and immediately place wielditem there.", "nodes", function (nodes) + local pos = minetest.find_node_near(minetest.localplayer:get_pos(), 5, nodes, true) + if pos then + minetest.dig_node(pos) + minetest.place_node(pos) + end +end) + +mapbot.register_bot("dig_place_pos", "Automatically dig node at specified pos and immediately place wielditem there.", "pos", function (pos) + minetest.dig_node(pos) + minetest.place_node(pos) +end) |