How check itemname = (quantity)

i made a script where when the player get 10 item named: exp_job
the player job level up.

i need to know how to do that
ex:
xPlayer.(itenname) = 10 then xPlayer.job_grade == 2

end

You have to take 2 locals.
First is local for player inventory
Second is for count of item

local inventory = ESX.GetPlayerData().inventory
local count = 0
for i=1, #inventory, 1 do
if inventory[i].name == ‘YOUR ITEM’ then
count = inventory[i].count
end

when i use

local inventory = ESX.GetPlayerData().inventory

the script bug… doesnt work anymore…

it seem to be: local inventory =ESX.GetPlayerData().inventory the problem…

1 Like

here’s what i tried

Citizen.CreateThread(function ()


local inventory = ESX.GetPlayerData().inventory
local count = 0
for i=1, #inventory, 1 do
if inventory[i].name == 'lockpick' then
count = inventory[i].count

endtype or paste code here

i doesnt work something’s wrong

it seems to be the == ‘lockpick’ the problem i tried “” too but still doesnt work.

its working the code works thank you

function NAME:Get.itemCount (source)
local xPlayer = ESX.GetPlayerFromId(source)
while not xPlayer do Citizen.Wait(0); xPlayer = ESX.GetPlayerFromId(source); end
local item = xPlayer.getInventoryItem(‘litemname’)
return item.count or 0

You can define how many of a certain item a player has in their inventory by using count.

local itemQuantity = xPlayer.getInventoryItem('bread).count

if itemQuantity >= 10 then
…codehere…

^example

1 Like

where i need to put this code to? i tried on the client file.
here:

local menuIsShowed, hintIsShowed, hintToDisplay, hasAlreadyEnteredMarker, isInMarker, vehicleObjInCaseofDrop, vehicleInCaseofDrop, vehicleMaxHealth
local PlayerData, Blips, JobBlips, myPlate, onDuty, spawner = {}, {}, {}, {}, false, 0



local blips = {
    -- Example {title="", colour=, id=, x=, y=, z=},

     {title="Example 1", colour=5, id=446, x = -347.291, y = -133.370, z = 38.009},
     {title="Example 2", colour=30, id=108, x = 260.130, y = 204.308, z = 109.287}
  }



RegisterNetEvent('esx:playerLoaded')
AddEventHandler('esx:playerLoaded', function(xPlayer)






end)

function NAME:Get.itemCount(source)
local xPlayer = ESX.GetPlayerFromId(source)
while not xPlayer do Citizen.Wait(0); xPlayer = ESX.GetPlayerFromId(source); end
local item = xPlayer.getInventoryItem("bread")
return item.count or 0

if its not good explain to me where i need to put those codes please…

1 Like