diff --git a/HOLD/formspec.lua b/HOLD/formspec.lua deleted file mode 100644 index 00668c3..0000000 --- a/HOLD/formspec.lua +++ /dev/null @@ -1,135 +0,0 @@ - - -local function highlight(item,line,w,h,r,g,b) - local item = item - 0.09 - local line = line - 0.07 - return "box[" .. item .. "," .. line .. ";" .. w .. "," .. h .. ";#" .. - r..r .. g..g .. b..b .."90]" -end - -local function button(x,y,image,name,exit) - if not exit then - return "image_button["..x..","..y..";1,1;"..image..";"..name..";]" - else - return "image_button_exit["..x..","..y..";1,1;"..image..";"..name..";]" - end -end - -local function cbutton(x,y,name) - return "image_button["..x..","..y..";1,1;vbots_"..name..".png;"..name..";]" -end - -local function panel_playerinv() - return "list[current_player;main;0,5;8,4;]" - .."listring[current_player;main]" - --..highlight(0,5,8,4,"a","f","a") -end - -local function panel_botinv(pos) - return "list[nodemeta:" .. pos .. ";main;0,1;8,4;]" - .."listring[nodemeta:" .. pos .. ";main]" - ..highlight(0,1,8,4,"a","a","f") -end - -local function panel_commands() - return cbutton(0,1,"move_forward") - ..cbutton(1,1,"move_backward") - ..cbutton(2,1,"move_left") - ..cbutton(3,1,"move_right") - ..cbutton(4,1,"move_up") - ..cbutton(5,1,"move_down") - - ..cbutton(0,2,"turn_clockwise") - ..cbutton(1,2,"turn_anticlockwise") - ..cbutton(2,2,"turn_random") - ..cbutton(3,2,"climb_up") - ..cbutton(4,2,"climb_down") - - ..cbutton(0,3,"number_1") - ..cbutton(1,3,"number_2") - ..cbutton(2,3,"number_3") - ..cbutton(3,3,"number_4") - ..cbutton(4,3,"number_5") - ..cbutton(5,3,"number_6") - - ..cbutton(0,4,"case_repeat") - ..cbutton(1,4,"case_test") - ..cbutton(2,4,"case_yes") - ..cbutton(3,4,"case_no") - ..cbutton(4,4,"case_success") - ..cbutton(5,4,"case_failure") - ..cbutton(6,4,"case_end") - - ..cbutton(0,5,"mode_pause") - ..cbutton(1,5,"mode_wait") - ..cbutton(2,5,"mode_dig") - ..cbutton(3,5,"mode_build") - ..cbutton(4,5,"mode_examine") - ..cbutton(5,5,"mode_walk") - ..cbutton(6,5,"mode_fly") - - ..cbutton(0,8,"run_1") - ..cbutton(1,8,"run_2") - ..cbutton(2,8,"run_3") - ..cbutton(3,8,"run_4") - ..cbutton(4,8,"run_5") - ..cbutton(5,8,"run_6") - - ..highlight(0,1,7,8,"a","a","f") -end - -local function panel_main(pos,mode) - local panel - if mode == 0 then - panel = panel_commands() - else - panel = panel_playerinv() - ..panel_botinv(pos) - end - return panel - ..button(0.5,0,"vbots_gui_commands.png","commands") - ..button(1.5,0,"vbots_location_inventory.png","player_inv") - ..highlight(0.5+mode,0,1,1,"a","a","f") -end - -local function panel_code(pos,program) - return button(8,0,"vbots_gui_run.png","run",true) - ..button(9,0,"vbots_gui_check.png","check") - ..button(10,0,"vbots_gui_load.png","load") - ..button(11,0,"vbots_gui_save.png","save") - ..highlight(8,0,4,1,"5","5","f") - - ..button(15,0,"vbots_gui_exit.png","exit",true) - ..highlight(15,0,1,1,"f","0","0") - - .."list[nodemeta:" .. pos .. ";p"..program..";8,1;7,8;]" - ..highlight(8,1,7,8,"f","a","f") - ..highlight(8,1,1,1,"f","f","f") - .."listring[nodemeta:" .. pos .. ";p"..program.."]" - - ..button(15,1.5,"vbots_program_0.png","sub_0") - ..button(15,2.5,"vbots_program_1.png","sub_1") - ..button(15,3.5,"vbots_program_2.png","sub_2") - ..button(15,4.5,"vbots_program_3.png","sub_3") - ..button(15,5.5,"vbots_program_4.png","sub_4") - ..button(15,6.5,"vbots_program_5.png","sub_5") - ..button(15,7.5,"vbots_program_6.png","sub_6") - ..highlight(15,1.5+program,1,1,"f","a","f") -end - -function vbots.get_formspec(pos,meta) - local bot_key = meta:get_string("key") - local bot_owner = meta:get_string("owner") - local bot_name = meta:get_string("name") - local bot_pos = pos.x .. "," .. pos.y .. "," .. pos.z - local fs_panel = meta:get_int("panel") - local fs_program = meta:get_int("program") - --print(dump(meta:to_table().fields)) - --print("Panel:"..fs_panel) - --print("Program:"..fs_program) - local formspec = "size[16,9]" - .."label[3,0;\"" .. bot_name .. "\" (" .. bot_owner .. ")]" - ..panel_main(bot_pos,fs_panel) - ..panel_code(bot_pos,fs_program) - return formspec -end diff --git a/HOLD/held b/HOLD/held deleted file mode 100644 index 90d7166..0000000 --- a/HOLD/held +++ /dev/null @@ -1,16 +0,0 @@ ------------------------------------------------------------------------------ --- function vbots.form_handle(bot_key,meta) --- local inventory = meta:get_inventory() --- for key, list in pairs(inventory:get_lists()) do --- local size = #list --- print("inv:" .. key .. "(" .. size .. ")") --- for i = 1, size do --- local stack = list[i] --- if not stack:is_empty() then --- print( "at PC:".. i .. " - " .. stack:get_name() .. --- " (" .. stack:get_count() .. ")") --- end --- end --- print(dump(vbots.bot_info)) --- end --- end diff --git a/HOLD/init.hold b/HOLD/init.hold deleted file mode 100644 index ac479d3..0000000 --- a/HOLD/init.hold +++ /dev/null @@ -1,114 +0,0 @@ ---[[ - Visual Bots v0.1 - - Modified & (heavily) extended from example code for safe formspecs which is - Copyright (C) 2017 - Auke Kok. - Modifications are (c)2019 Nigel Garnett. - - Permission to use, copy, modify, and/or distribute this software for - any purpose with or without fee is hereby granted, provided that the - above copyright notice and this permission notice appear in all copies. - - THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL - WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED - WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR - BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES - OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, - WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, - ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS - SOFTWARE. - - Starting point code for safer formspecs is available here: https://github.com/sofar/tele - with it's attendant excelent description here: https://forum.minetest.net/viewtopic.php?f=47&t=19129# -]]-- - - -local form_context = {} -minetest.register_on_leaveplayer(function(player) - local name = player:get_player_name() - if name and form_context[name] then - form_context[name] = nil - end -end) - -minetest.register_node("vbots:bot", { - description = "A vbots bot node", - tiles = { - "drogna_block_triangle_green.png", - "drogna_block_circle_red.png", - "drogna_block_circle_red.png", - "drogna_block_circle_red.png", - "drogna_block_circle_red.png", - "drogna_block_circle_red.png" - }, - is_ground_content = false, - groups = {cracky = 3}, - on_construct = function(pos) - local meta = minetest.get_meta(pos) - local inv = meta:get_inventory() - inv:set_size("main", 16) - meta:from_table({ - inventory = { - main = {[1] = "vbots:bot", [2] = "", [3] = "", [4] = "", - [5] = "", [6] = "", [7] = "", [8] = "", - [9] = "",[10] = "", [11] = "", [12] = "", - [13] = "", [14] = "", [15] = "", [16] = "vbots:bot" - } - }, - }) - end, - after_place_node = function(pos, placer) - local meta = minetest.get_meta(pos) - meta:set_string("owner", placer:get_player_name() or "") - meta:set_string("infotext", "Visualbot owned by "..meta:get_string("owner")) - end, - on_rightclick = function(pos, node, clicker, itemstack, pointed_thing) - local name = clicker:get_player_name() - local meta = minetest.get_meta(pos) - local inv = meta:get_inventory() - if meta:get_string("owner")=="" then - meta:set_string("owner", name) - end - if meta:get_string("target")=="" then - meta:set_string("target", minetest.pos_to_string(pos)) - end - local tpos = meta:get_string("target") - - if name~="" then - local formspec = "size[10,10]" - if minetest.check_player_privs(clicker, "server") or meta:get_string("owner")==name then - formspec = formspec.."field[1,1;4,1;target;target;"..tpos.."]button_exit[5,0.8;1,1;set;set]" - formspec = formspec.."list[inventory_location;main;1,4;8,2;]" - end - formspec = formspec.."button[1,2;6,1;teleport;teleport]" - form_context[name] = minetest.pos_to_string(pos) - minetest.show_formspec(name, "vbotform", formspec) - end - end -}) - -minetest.register_on_player_receive_fields(function(player, formname, fields) - local name = player:get_player_name() - local pos = form_context[name] - if not pos then - return true - end - pos = minetest.string_to_pos(pos) - local node = minetest.get_node(pos) - local meta = minetest.get_meta(pos) - if node.name ~= "vbots:bot" then - form_context[name] = nil - return true - end - if fields.target and fields.set and (minetest.check_player_privs(player, "server") or meta:get_string("owner")==name) then - local meta = minetest.get_meta(pos) - meta:set_string("target", fields.target) - end - if fields.teleport then - local meta = minetest.get_meta(pos) - local target = meta:get_string("target") - player:set_pos(minetest.string_to_pos(target)) - end - - form_context[name] = nil -end) diff --git a/HOLD/items.lua b/HOLD/items.lua deleted file mode 100644 index d99d6ed..0000000 --- a/HOLD/items.lua +++ /dev/null @@ -1,62 +0,0 @@ -local register_command = function(itemname,description,image) - minetest.register_craftitem("vbots:"..itemname, { - description = description, - inventory_image = image, - wield_image = "wieldhand.png", - stack_max = 1, - groups = { bot_commands = 1 }, - on_place = function(itemstack, placer, pointed_thing) - return nil - end, - on_drop = function(itemstack, dropper, pos) - return nil - end, - on_use = function(itemstack, user, pointed_thing) - return nil - end - }) -end - -register_command("move_forward","Move bot forward","vbots_move_forward.png") -register_command("move_backward","Move bot backward","vbots_move_backward.png") -register_command("move_left","Move bot to it's left","vbots_move_left.png") -register_command("move_right","Move bot to it's right","vbots_move_right.png") -register_command("move_up","Move bot up","vbots_move_up.png") -register_command("move_down","Move bot down","vbots_move_down.png") - -register_command("climb_up","Climb up","vbots_climb_up.png") -register_command("climb_down","Climb down","vbots_climb_down.png") - -register_command("turn_clockwise","Turn bot 90° clockwise","vbots_turn_clockwise.png") -register_command("turn_anticlockwise","Move bot 90° anti-clockwise","vbots_turn_anticlockwise.png") -register_command("turn_random","Move bot 90° in a random direction","vbots_turn_random.png") - -register_command("case_end","End section","vbots_case_end.png") -register_command("case_failure","Last action failed","vbots_case_failure.png") -register_command("case_success","Last action succeeded","vbots_case_success.png") -register_command("case_yes","Yes","vbots_case_yes.png") -register_command("case_no","No","vbots_case_no.png") -register_command("case_test","Test","vbots_case_test.png") -register_command("case_repeat","Repeat","vbots_case_repeat.png") - -register_command("mode_build","Place a block in the direction of the next command","vbots_mode_build.png") -register_command("mode_dig","Dig a block in the direction of the next command","vbots_mode_dig.png") -register_command("mode_examine","Examine the block in the direction of the next command","vbots_mode_examine.png") -register_command("mode_fly","Enter fly mode","vbots_mode_fly.png") -register_command("mode_pause","Wait for a few seconds","vbots_mode_pause.png") -register_command("mode_wait","Wait until next event","vbots_mode_wait.png") -register_command("mode_walk","Leave fly mode","vbots_mode_walk.png") - -register_command("number_1","1","vbots_number_1.png") -register_command("number_2","2","vbots_number_2.png") -register_command("number_3","3","vbots_number_3.png") -register_command("number_4","4","vbots_number_4.png") -register_command("number_5","5","vbots_number_5.png") -register_command("number_6","6","vbots_number_6.png") - -register_command("run_1","Run sub-program 1","vbots_run_1.png") -register_command("run_2","Run sub-program 2","vbots_run_2.png") -register_command("run_3","Run sub-program 3","vbots_run_3.png") -register_command("run_4","Run sub-program 4","vbots_run_4.png") -register_command("run_5","Run sub-program 5","vbots_run_5.png") -register_command("run_6","Run sub-program 6","vbots_run_6.png") diff --git a/HOLD/registrations.lua b/HOLD/registrations.lua deleted file mode 100644 index e478160..0000000 --- a/HOLD/registrations.lua +++ /dev/null @@ -1,186 +0,0 @@ - -------------------------------------- --- Cute 'unique' bot name generator -------------------------------------- -local function bot_namer() - local first = { - "A", "An", "Ba", "Bi", "Bo", "Bom", "Bon", "Da", "Dan", - "Dar", "De", "Do", "Du", "Due", "Duer", "Dwa", "Fa", "Fal", "Fi", - "Fre", "Fun", "Ga", "Gal", "Gar", "Gam", "Gim", "Glo", "Go", "Gom", - "Gro", "Gwar", "Ib", "Jor", "Ka", "Ki", "Kil", "Lo", "Mar", "Na", - "Nal", "O", "Ras", "Ren", "Ro", "Ta", "Tar", "Tel", "Thi", "Tho", - "Thon", "Thra", "Tor", "Von", "We", "Wer", "Yen", "Yur" - } - local after = { - "bil", "bin", "bur", "char", "den", "dir", "dur", "fri", "fur", "in", - "li", "lin", "mil", "mur", "ni", "nur", "ran", "ri", "ril", "rimm", "rin", - "thur", "tri", "ulf", "un", "ur", "vi", "vil", "vim", "vin", "vri" - } - return first[math.random(#first)] .. - after[math.random(#after)] .. - after[math.random(#after)] -end - -------------------------------------- --- callback from bot node can_dig -------------------------------------- -local function interact(player,pos) - local meta = minetest.get_meta(pos) - if minetest.check_player_privs(player, "server") or - meta:get_string("owner")==player:get_player_name() then - return true - end - return false -end - -------------------------------------- --- callback from bot node on_rightclick -------------------------------------- -local function bot_restore(pos) - local meta = minetest.get_meta(pos) - local bot_key = meta:get_string("key") - local bot_owner = meta:get_string("owner") - local bot_name = meta:get_string("name") - if not vbots.bot_info[bot_key] then - vbots.bot_info[bot_key] = { owner = bot_owner, pos = pos, name = bot_name} - end -end - -------------------------------------- --- callback from bot node after_place_node -------------------------------------- -local function bot_init(pos, placer) - local bot_key = vbots.get_key() - local bot_owner = placer:get_player_name() - local bot_name = bot_namer() - vbots.bot_info[bot_key] = { owner = bot_owner, pos = pos, name = bot_name} - local meta = minetest.get_meta(pos) - meta:set_string("key", bot_key) - meta:set_string("owner", bot_owner) - meta:set_string("infotext", "Vbot " .. bot_name .. " owned by " .. bot_owner) - meta:set_string("name", bot_name) - meta:set_int("panel", 0) - meta:set_int("program", 0) - local inv = meta:get_inventory() - inv:set_size("p0", 56) - inv:set_size("p1", 56) - inv:set_size("p2", 56) - inv:set_size("p3", 56) - inv:set_size("p4", 56) - inv:set_size("p5", 56) - inv:set_size("p6", 56) - inv:set_size("main", 32) -end - -minetest.register_node("vbots:bot", { - description = "A vbots bot node", - tiles = { - "vbots_gui_up.png", - "vbots_types_node.png", - "vbots_types_node.png", - "vbots_types_node.png", - "vbots_types_node.png", - "vbots_types_node.png", - }, - stack_max = 1, - is_ground_content = false, - paramtype2 = "facedir", - legacy_facedir_simple = true, - groups = {cracky = 3, snappy = 3, crumbly = 3, oddly_breakable_by_hand = 2}, - on_blast = function() end, - can_dig = function(pos,player) - return interact(player,pos) - end, - after_place_node = function(pos, placer, itemstack, pointed_thing) - bot_init(pos, placer) - end, - on_rightclick = function(pos, node, clicker, itemstack, pointed_thing) - bot_restore(pos) - local name = clicker:get_player_name() - if name == "" then - return 0 - end - if interact(clicker,pos) then - minetest.after(0, vbots.show_formspec, clicker, pos) - end - end, - on_destruct = function(pos) - local meta = minetest.get_meta(pos) - local bot_key = meta:get_string("key") - vbots.bot_info[bot_key] = nil - end -}) - -minetest.register_on_leaveplayer(function(player) - local name = player:get_player_name() - for bot_key,bot_data in pairs( vbots.bot_info) do - if bot_data.owner == name then - minetest.remove_node(bot_data.pos) - vbots.bot_info[bot_key] = nil - end - end -end) - -local register_command = function(itemname,description,image) - minetest.register_craftitem("vbots:"..itemname, { - description = description, - inventory_image = image, - wield_image = "wieldhand.png", - stack_max = 1, - groups = { bot_commands = 1 }, - on_place = function(itemstack, placer, pointed_thing) - return nil - end, - on_drop = function(itemstack, dropper, pos) - return nil - end, - on_use = function(itemstack, user, pointed_thing) - return nil - end - }) -end - -register_command("move_forward","Move bot forward","vbots_move_forward.png") -register_command("move_backward","Move bot backward","vbots_move_backward.png") -register_command("move_left","Move bot to it's left","vbots_move_left.png") -register_command("move_right","Move bot to it's right","vbots_move_right.png") -register_command("move_up","Move bot up","vbots_move_up.png") -register_command("move_down","Move bot down","vbots_move_down.png") - -register_command("climb_up","Climb up","vbots_climb_up.png") -register_command("climb_down","Climb down","vbots_climb_down.png") - -register_command("turn_clockwise","Turn bot 90° clockwise","vbots_turn_clockwise.png") -register_command("turn_anticlockwise","Move bot 90° anti-clockwise","vbots_turn_anticlockwise.png") -register_command("turn_random","Move bot 90° in a random direction","vbots_turn_random.png") - -register_command("case_end","End section","vbots_case_end.png") -register_command("case_failure","Last action failed","vbots_case_failure.png") -register_command("case_success","Last action succeeded","vbots_case_success.png") -register_command("case_yes","Yes","vbots_case_yes.png") -register_command("case_no","No","vbots_case_no.png") -register_command("case_test","Test","vbots_case_test.png") -register_command("case_repeat","Repeat","vbots_case_repeat.png") - -register_command("mode_build","Place a block in the direction of the next command","vbots_mode_build.png") -register_command("mode_dig","Dig a block in the direction of the next command","vbots_mode_dig.png") -register_command("mode_examine","Examine the block in the direction of the next command","vbots_mode_examine.png") -register_command("mode_fly","Enter fly mode","vbots_mode_fly.png") -register_command("mode_pause","Wait for a few seconds","vbots_mode_pause.png") -register_command("mode_wait","Wait until next event","vbots_mode_wait.png") -register_command("mode_walk","Leave fly mode","vbots_mode_walk.png") - -register_command("number_1","1","vbots_number_1.png") -register_command("number_2","2","vbots_number_2.png") -register_command("number_3","3","vbots_number_3.png") -register_command("number_4","4","vbots_number_4.png") -register_command("number_5","5","vbots_number_5.png") -register_command("number_6","6","vbots_number_6.png") - -register_command("run_1","Run sub-program 1","vbots_run_1.png") -register_command("run_2","Run sub-program 2","vbots_run_2.png") -register_command("run_3","Run sub-program 3","vbots_run_3.png") -register_command("run_4","Run sub-program 4","vbots_run_4.png") -register_command("run_5","Run sub-program 5","vbots_run_5.png") -register_command("run_6","Run sub-program 6","vbots_run_6.png") - diff --git a/formspec.lua b/formspec.lua index 04ab898..f2209e3 100644 --- a/formspec.lua +++ b/formspec.lua @@ -39,18 +39,6 @@ end ------------------------------------- -- Main panel generators ------------------------------------- -local function panel_botinv(pos) - return "list[nodemeta:" .. pos .. ";main;0,1;8,4;]" - .."listring[nodemeta:" .. pos .. ";main]" - ..highlight(0,1,8,4,"a","a","f") -end - -local function panel_playerinv() - return "list[current_player;main;0,5;8,4;]" - .."listring[current_player;main]" - --..highlight(0,5,8,4,"a","f","a") -end - local function panel_commands() local commands = { {"move_forward","move_backward","move_up","move_down","move_home"}, @@ -76,7 +64,11 @@ local function panel_main(pos,mode) if mode == 0 then panel = panel_commands() else - panel = panel_playerinv() .. panel_botinv(pos) + panel = "list[current_player;main;0,5;8,4;]".. + "list[nodemeta:" .. pos .. ";main;0,1;8,4;]".. + "listring[current_player;main]".. + "listring[nodemeta:" .. pos .. ";main]".. + highlight(0,1,8,4,"a","a","f") end return panel ..button(0.5,0,"vbots_gui_commands.png","commands") @@ -100,11 +92,11 @@ local function panel_code(pos,program) ..button(6.5,0,"vbots_gui_trash.png","trash") .."list[detached:bottrash;main;7.5,0;1,1;]" - .."listring[nodemeta:" .. pos .. ";p"..program.."]" +-- .."listring[nodemeta:" .. pos .. ";p"..program.."]" ..highlight(6.5,0,2,1,"0","0","0") .."list[nodemeta:" .. pos .. ";p"..program..";8,1;7,8;]" - .."listring[nodemeta:" .. pos .. ";trash]" +-- .."listring[detached:bottrash;main]" ..highlight(8,1,7,8,"f","a","f") ..button(15,1.5,"vbots_program_0.png","sub_0") diff --git a/formspec_handler.lua b/formspec_handler.lua index 2085903..c936af5 100644 --- a/formspec_handler.lua +++ b/formspec_handler.lua @@ -15,7 +15,7 @@ minetest.register_on_player_receive_fields(function(player, bot_key, fields) local bot_data = vbots.bot_info[bot_key] -- Bot main formspec if bot_data then - print("Main Bot formspec received:") + -- print("Main Bot formspec received:") local inv=minetest.get_inventory({type="node", pos=bot_data.pos}) local meta = minetest.get_meta(bot_data.pos) local meta_bot_key = meta:get_string("key") @@ -70,7 +70,7 @@ minetest.register_on_player_receive_fields(function(player, bot_key, fields) end end end - minetest.after(0.2, vbots.show_formspec, player, bot_data.pos) + minetest.after(0, vbots.show_formspec, player, bot_data.pos) end end else @@ -81,7 +81,7 @@ minetest.register_on_player_receive_fields(function(player, bot_key, fields) bot_list[#bot_list+1] = n end if #form_parts == 2 and form_parts[1] == "loadbot" then - print("Load Bot formspec received") + -- print("Load Bot formspec received") local bot_data = vbots.bot_info[form_parts[2]] local pos=bot_data.pos local meta = minetest.get_meta(pos) @@ -96,7 +96,7 @@ minetest.register_on_player_receive_fields(function(player, bot_key, fields) end if fields.saved then local bot_name = bot_list[tonumber(string.split(fields.saved,":")[2])] - print('Loadbot '..bot_name) + -- print('Loadbot '..bot_name) local inv_list = minetest.deserialize(data.fields[bot_name]) local inv_involved = {} if inv_list then @@ -123,7 +123,7 @@ minetest.register_on_player_receive_fields(function(player, bot_key, fields) end end elseif #form_parts == 2 and form_parts[1] == "delete" then - print("Delete Bot formspec received") + -- print("Delete Bot formspec received") local bot_data = vbots.bot_info[form_parts[2]] local pos=bot_data.pos minetest.close_formspec(player:get_player_name(), bot_key) @@ -133,7 +133,7 @@ minetest.register_on_player_receive_fields(function(player, bot_key, fields) mod_storage:from_table(data) end elseif #form_parts == 2 and form_parts[1] == "rename" then - print("Rename Bot formspec received") + -- print("Rename Bot formspec received") local bot_data = vbots.bot_info[form_parts[2]] local pos=bot_data.pos minetest.close_formspec(player:get_player_name(), bot_key) @@ -142,7 +142,7 @@ minetest.register_on_player_receive_fields(function(player, bot_key, fields) vbots.load(pos,player,"renameto_"..bot_name) end elseif #form_parts == 2 and form_parts[1] == "renameto" then - print("Renameto formspec received") + -- print("Renameto formspec received") local bot_data = vbots.bot_info[form_parts[2]] local pos=bot_data.pos minetest.close_formspec(player:get_player_name(), bot_key) @@ -153,7 +153,7 @@ minetest.register_on_player_receive_fields(function(player, bot_key, fields) data.fields[oldname] = nil data.fields[newname] = hold mod_storage:from_table(data) - print("renamed "..oldname.." to "..newname) + -- print("renamed "..oldname.." to "..newname) end end end diff --git a/init.lua b/init.lua index bd95811..2e4d8d1 100644 --- a/init.lua +++ b/init.lua @@ -25,9 +25,11 @@ vbots.save = function(pos) local botname = meta:get_string("name") local inv_list = {} for i,t in pairs(meta_table.inventory) do - for _,s in pairs(t) do - if s and s:get_count()>0 then - inv_list[#inv_list+1] = i.." "..s:get_name().." "..s:get_count() + if i ~= "main" then + for _,s in pairs(t) do + if s and s:get_count()>0 then + inv_list[#inv_list+1] = i.." "..s:get_name().." "..s:get_count() + end end end end diff --git a/register_bot.lua b/register_bot.lua index ae31c09..0726145 100644 --- a/register_bot.lua +++ b/register_bot.lua @@ -193,6 +193,16 @@ end local function move_bot(pos,direction) + local meta = minetest.get_meta(pos) + local bot_owner = meta:get_string("owner") + local player = minetest.get_player_by_name(bot_owner) + -- print(bot_owner) + local ppos + if player then + ppos = player:get_pos() + -- print(dump(pos)) + -- print(dump(ppos)) + end local node = minetest.get_node(pos) local dir = minetest.facedir_to_dir(node.param2) local newpos @@ -208,6 +218,13 @@ local function move_bot(pos,direction) if newpos then position_bot(pos,newpos) end + if ppos then + if math.abs(ppos.x-pos.x)<2 and + math.abs(ppos.z-pos.z)<2 and + math.abs(ppos.y-pos.y)<2 then + player:setpos({x=newpos.x, y=newpos.y+1.1, z=newpos.z }) + end + end end @@ -225,13 +242,21 @@ local function bot_dig(pos,digy) end if not minetest.is_protected(digpos, bot_owner) then local drop = minetest.get_node(digpos) + local drops = minetest.get_node_drops(drop.name, "default:pick_diamond") if drop.name ~= "air" then local inv=minetest.get_inventory({ type="node", pos=pos }) - local leftover = inv:add_item("main", ItemStack(drop.name)) + for _, itemname in ipairs(drops) do + local leftover = inv:add_item("main", ItemStack(itemname)) + if not leftover then + minetest.sound_play("system-fault",{pos = newpos, gain = 10}) + vbots.bot_togglestate(pos,"off") + end + end minetest.set_node(digpos,{name="air"}) + --minetest.dig_node(digpos) end else minetest.sound_play("system-fault",{pos = newpos, gain = 10}) @@ -240,23 +265,24 @@ end local function bot_build(pos,buildy) local meta = minetest.get_meta(pos) + local inv = meta:get_inventory() local bot_owner = meta:get_string("owner") local node = minetest.get_node(pos) local dir = minetest.facedir_to_dir(node.param2) - local inv=minetest.get_inventory({type="node", pos=pos}) local buildpos if buildy == 0 then buildpos = {x = pos.x+dir.x, y = pos.y, z = pos.z+dir.z} else buildpos = {x = pos.x, y = pos.y+buildy, z = pos.z} end - if not minetest.is_protected(buildpos, bot_owner) then + local buildnode = minetest.get_node(buildpos) + + if not minetest.is_protected(buildpos, bot_owner) and buildnode.name == "air" then local content = inv:get_list("main") local a = 1 local found = nil if content then - while( a<57 and not found) do - + while( a<33 and not found) do if content[a] and not content[a]:is_empty() then found = content[a]:get_name() end @@ -264,7 +290,10 @@ local function bot_build(pos,buildy) end if found then -- print(found) - minetest.set_node(buildpos,{name=found}) + local got = inv:remove_item("main",ItemStack(found)) + if got:get_count() == 1 then + minetest.set_node(buildpos,{name=found}) + end end end else @@ -346,8 +375,8 @@ local function punch_bot(pos,player) end local function bot_handletimer(pos) - local inv=minetest.get_inventory({type="node", pos=pos}) local meta = minetest.get_meta(pos) + local inv = meta:get_inventory() local PC = meta:get_int("PC") local PR = meta:get_int("PR") local invname = "p"..PR @@ -436,7 +465,13 @@ local function register_bot(node_name,node_desc,node_tiles,node_groups) return bot_handletimer(pos) end, can_dig = function(pos,player) - return interact(player,pos) + local meta = minetest.get_meta(pos) + local inv = meta:get_inventory() + local i = interact(player,pos) + if inv:is_empty("main") and i then + return true + end + return false end, on_destruct = function(pos) local meta = minetest.get_meta(pos)