• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

Solved Proper way to check Item

Ramirow

Veteran OT User
Joined
Aug 22, 2009
Messages
584
Solutions
15
Reaction score
301
Location
Argentina
YouTube
ramirogrant
What function should I use if I need to search if player has x item?
I've seen a lot of getItem functions but I don't see a way to use them properly as I'm constantly getting errors when trying to use them :/
I'm guessing the one I need is: container:getItemCountById

Thanks!
 
Code:
local player = Player(cid)
if player:getItemCount(itemid) < itemAmount then
Looked through this thread and found an example.
I don't work with 1.x, but I'm fairly sure this is the method your looking for.
For your specific use case, to check if a player has item X within their inventory, do this
Code:
if player:getItemCount(1111) > 0 then
 
Thanks guys! Managed to do the same thing but with a different method.
Like this:
Code:
if player:removeItem(xxxx, 1) then
  --Player has the item
else
  --He/She didn't
end
It's not the same as the check item, but It was what I needed since I wanted to remove the item afterwards!
 
Thanks guys! Managed to do the same thing but with a different method.
Like this:
Code:
if player:removeItem(xxxx, 1) then
  --Player has the item
else
  --He/She didn't
end
It's not the same as the check item, but It was what I needed since I wanted to remove the item afterwards!
Code:
local item = ItemType("boots of haste")
if item then
    -- do something
end
 
Back
Top