ozkur wrote:can the list "pos" be broken into x, y, and z coordinates?
Edit:nevermind, found out how.
how do you detect if something is in your inventory?
For the first question, in case other users have the same issue, once you have a "position" table let's say `pos` (e.g. from `someobject:getpos()` or from a callback), you get the coordinates with `pos.x`, `pos.y`, and `pos.z`. The vector math functions (see `lua_api.txt`) can be used on these tables.
For your second question, you have to have a reference to the inventory (let's say `inv`), then you do something like this:
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 inv = get_inventory_from_somewhere()
if inv:contains_item("main", ItemStack("default:dirt 42")) then
-- do something here
end
Replace "main" with the inventory list name. "main" is generally used for the main list, e.g. the player inventory, chest contents. Other known lists are "craft" (for the player crafting grid), "craftresult" (guess what).
Also, replace the "default:dirt 42" with the (internal) name and count of the item you're looking for. You may omit the `42` if you are just looking for the item (implicit count of 1). Don't recall if groups work here.