Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
- Code: Select all
local players = {}
minetest.register_on_joinplayer(function(player)
table.insert(players, player)
end)
minetest.register_on_leaveplayer(function(player)
table.remove(players, player)
end)
minetest.register_globalstep(function(dtime)
for i,player in ipairs(players) do
local items = minetest.env:get_objects_inside_radius(player:getpos(),1)
for j,item in ipairs(items) do
if not item:is_player() and item:get_luaentity().itemstring ~= nil then
player:get_inventory():add_item("main", ItemStack(item:get_luaentity().itemstring))
item:remove()
end
end
end
end)
The problem is that everytime I walk over one item in the inventory appears a random number (>1) of the item.
Has anybody an idea how to change the code that only one item appears in the inventory?