Inventory:hasItem

From Nutscript Developer Wiki
Jump to navigation Jump to search


   Inventory:hasItem(uniqueID, data)

This function returns whether the inventory has specific item or not.

For finding how many items are in an inventory, use Inventory:getItemCount

Arguments[edit]

  • string uniqueID

Return Values[edit]

  • Item

The Item in the inventory.

Examples[edit]

Prints the table of inventory data on that item if player has skull item in their inventory.

    for k,v in pairs(player.GetAll()) do
         if v:getChar():getInv():hasItem("skull") != false then
              PrintTable(v:getChar():getInv():hasItem("skull"))
         end
    end

Table can also be used as a true statement. If player has a skull then print their name.

    for k,v in pairs(player.GetAll()) do
         if v:getChar():getInv():hasItem("skull") then
              print(v:Name())
         end
    end