robot: digcount increases even with dig attempt

pickup: picks up entities around robot
table of items it wont pickup
master
rnd1 2016-12-10 10:50:48 +01:00
parent 905d7025ec
commit 779f0ab40c
2 changed files with 60 additions and 8 deletions

View File

@ -82,7 +82,9 @@ basic_robot.commands.dig = function(name,dir)
local digcount = 0;
if basic_robot.maxdig~=0 then
digcount = basic_robot.data[name].digcount;
if digcount > basic_robot.maxdig then return false end
if digcount > basic_robot.maxdig then
basic_robot.data[name].digcount = digcount+1;
return false end
end
local obj = basic_robot.data[name].obj;
@ -100,7 +102,7 @@ basic_robot.commands.dig = function(name,dir)
basic_robot.give_drops(nodename, inv);
minetest.set_node(pos,{name = "air"})
basic_robot.data[name].digcount = digcount+1;
--DS: sounds
local sounds = minetest.registered_nodes[nodename].sounds
@ -111,7 +113,7 @@ basic_robot.commands.dig = function(name,dir)
end
end
basic_robot.data[name].digcount = digcount+1;
return true
end
@ -176,6 +178,42 @@ basic_robot.commands.take_item = function(name,item, inventory,dir)
end
basic_robot.no_teleport_table = {
["itemframes:item"] = true,
["signs:text"] = true,
["basic_robot:robot"] = true
}
basic_robot.commands.pickup = function(r,name)
if r>8 then return false end
local pos = basic_robot.data[name].obj:getpos();
local spos = basic_robot.data[name].spawnpos; -- position of spawner block
local meta = minetest.get_meta(spos);
local inv = minetest.get_meta(spos):get_inventory();
for _,obj in pairs(minetest.get_objects_inside_radius({x=pos.x,y=pos.y,z=pos.z}, r)) do
local lua_entity = obj:get_luaentity()
if not obj:is_player() and lua_entity and lua_entity.itemstring ~= "" then
local detected_obj = lua_entity.name or ""
if not basic_robot.no_teleport_table[detected_obj] then -- object on no teleport list
-- put item in chest
local stack = ItemStack(lua_entity.itemstring)
if inv:room_for_item("main", stack) then
inv:add_item("main", stack);
end
obj:remove();
end
end
end
return true
end
basic_robot.commands.read_node = function(name,dir)
local obj = basic_robot.data[name].obj;
@ -203,7 +241,7 @@ basic_robot.commands.place = function(name,nodename, dir)
local meta = minetest.get_meta(spos);
local inv = meta:get_inventory();
if not inv then return false end
if not inv:contains_item("main", ItemStack(nodename)) and meta:get_int("admin")~=1 then return end
if not inv:contains_item("main", ItemStack(nodename)) and meta:get_int("admin")~=1 then return false end
inv:remove_item("main", ItemStack(nodename));
--DS
@ -215,7 +253,7 @@ basic_robot.commands.place = function(name,nodename, dir)
end
end
placename = basic_robot.plant_table[nodename];
local placename = basic_robot.plant_table[nodename];
if placename then
minetest.set_node(pos,{name = placename})
tick(pos); -- needed for seeds to grow

View File

@ -84,8 +84,13 @@ function getSandboxEnv (name)
down = function(item, inventory) commands.take_item(name,item, inventory,6) end,
up = function(item, inventory) commands.take_item(name,item, inventory,5) end,
}, -- take item from inventory TODO
},
pickup = function(r) -- pick up items around robot
commands.pickup(r, name);
end,
self = {
pos = function() return basic_robot.data[name].obj:getpos() end,
spawnpos = function() return basic_robot.data[name].spawnpos end,
@ -168,6 +173,11 @@ function getSandboxEnv (name)
basic_robot.data[name].fire_pos = nil;
return fire_pos
end,
label = function(text)
local obj = basic_robot.data[name].obj;
obj:set_properties({nametag = "[" .. name .. "] " .. text});
end,
},
find_nodes =
@ -367,6 +377,8 @@ local function is_inside_string(pos,script)
i2=string.find(script,"\"",i1+1);
if i2 then
par = 1 - par;
else
return false
end
if par == 0 then
if i1<pos and pos<i2 then
@ -547,7 +559,7 @@ local function init_robot(self)
basic_robot.data[self.owner].quiet_mode = false;
self.object:set_properties({infotext = "robot " .. self.owner});
self.object:set_properties({nametag = "robot " .. self.owner,nametag_color = "LawnGreen"});
self.object:set_properties({nametag = "[" .. self.owner.."]",nametag_color = "LawnGreen"});
self.object:set_armor_groups({fleshy=0})
initSandbox ( self.owner )
@ -768,6 +780,7 @@ local on_receive_robot_form = function(pos, formname, fields, sender)
"turn.left(), turn.right(), turn.angle(45)\n"..
"dig.direction()\n place.direction(\"default:dirt\")\nread_node.direction() tells you names of nodes\n"..
"insert.direction(item, inventory) inserts item from robot inventory to target inventory\n"..
"pickup(r) picks up all items around robot in radius r<8\n"..
"take.direction(item, inventory) takes item from target inventory into robot inventory\n"..
"read_text.direction(stringname) reads text of signs, chests and other blocks, optional stringname for other meta\n"..
"**BOOKS/CODE\nbook.read(i) returns contents of book at i-th position in library \nbook.write(i,text) writes book at i-th position\n"..
@ -790,7 +803,8 @@ local on_receive_robot_form = function(pos, formname, fields, sender)
"self.spawnpos() returns position of spawner block\n"..
"self.viewdir() returns vector of view for robot\n"..
"self.fire(speed, pitch,gravity) fires a projectile from robot\n"..
"self.fire_pos() returns last hit position\n ";
"self.fire_pos() returns last hit position\n "..
"self.label(text) changes robot label";
text = minetest.formspec_escape(text);