currently I'm working on a little mod that places a mts schem when the player reaches a certain location and has a specific item in his inventory.
I read the inventory in the following section:
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
minetest.register_globalstep(function(dtime)
timer = timer + dtime;
if timer >= 5 and built == 0 then
local players = minetest.get_connected_players()
for i, player in ipairs(players) do
inv = player:get_inventory()
if inv:contains_item("main", build_item) then
minetest.chat_send_all("yep")
local pos = player:getpos()
minetest.chat_send_all(minetest.pos_to_string(pos))
local dist = ((pos.x-target.x)^2 + (pos.z-target.z)^2)^0.5
minetest.chat_send_all(dist)
if dist < 10 then
spawn_cave(pos)
set_built()
display_message(player)
end
else
minetest.chat_send_all("nope")
end
end
timer = 0
end
end)
My problem is, that even if the build_item is removed from inventory ("itemstack:take_item();return itemstack"), the
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
if inv:contains_item("main", build_item)
still returns "true".
What am I doing wrong?
Meanwhile I have a workaround by checking "itemstack == 0" but what if the player has more then one stack?