you're using it wrongthanks
can you little explain how to use?
i use tfs 1.2
so if player:getItemCount(itemid) == 2000,10 then
do something
end
doesnt work showing error expect near '.'
thanks0.x: getPlayerItemCount(cid, itemid)
1.x: player:getItemCount(itemid)
you're using it wrongthanks
can you little explain how to use?
i use tfs 1.2
so if player:getItemCount(itemid) == 2000,10 then
do something
end
doesnt work showing error expect near '.'
thanks my mistakeyou're using it wrong
player:getItemCount(itemid) you're supposed to replace itemid with 2000 (assuming that's the id you're checking)
then the function returns the item count as it says
you need to check if the value returned is equal to 10
so
if player:getItemCount(itemid) == 10 then
but if you want to make it so they have at least 10, not exactly 10 you use >= (greater than or equal to)
-- Remove 1 gold coin
player:removeItem(2148, 1)
-- Remove 10 gold coins
player:removeItem(2148, 10)
-- Remove all gold coins the player has
player:removeItem(2148, player:getItemCount(2148))
Should've made a new post ...Sorry for posting this late, but is there a way to ignore the player equipments in the count function? Thanks!
Do you mean for example if the player has 5 demon armors in backpack and 1 in armor slot exclude the one they have in the armor slot?ignore the player equipments in the count function
Exactly!Do you mean for example if the player has 5 demon armors in backpack and 1 in armor slot exclude the one they have in the armor slot?
Exactly!
local countItems = TalkAction("/countitem")
function countItems.onSay(player, word, param)
itemId = tonumber(param)
if not itemId then
player:sendCancelMessage("Invalid parameter.")
return false
end
local excludeAmount = 0
for i = CONST_SLOT_HEAD, CONST_SLOT_AMMO do
-- skip checking backpack (?)
if i ~= CONST_SLOT_BACKPACK then
local slotItem = player:getSlotItem(i)
if slotItem and slotItem:getId() == itemId then
excludeAmount = excludeAmount + 1
end
end
end
if slotItem and slotItem:getId() == itemId then
excludeAmount = excludeAmount + 1
end
local itemcount = player:getItemCount(itemId) - excludeAmount
player:sendTextMessage(MESSAGE_STATUS_CONSOLE_ORANGE, "player has " .. itemcount .. "x of ".. ItemType(itemId):getName())
return false
end
countItems:separator(" ")
countItems:register()
function onUse(player, item, fromPosition, target, toPosition, isHotkey)
local targetItemId = 2494 --Demon Armor ID
local totalItemCount = player:getItemCount(targetItemId)
local equipedItemCount = 0
for slot = CONST_SLOT_HEAD, CONST_SLOT_AMMO do
local itemInSlot = player:getSlotItem(slot)
if itemInSlot and itemInSlot:getId() == targetItemId then
equipedItemCount = equipedItemCount + 1
end
end
local desiredCount = totalItemCount - equipedItemCount
print("Player have: "..totalItemCount.." in total.")
print("Player have: "..equipedItemCount.." equiped.")
print("Player have: "..desiredCount.." in backpack.")
return true
end
it looks likelocal totalItemCount = player:getItemById(targetItemId, true)
player:getItemById(id)
returns an Item object. player:getItemCount(itemId)
?