[Help] Check for item in TruckRobbery

Hello, i’m trying to figure out how i can make this script check for item WEAPON_STICKYBOMB in player inventory. Basically the player need the Sticky Bomb in his inventory in order to start the robbery but i just cant figure it out

RegisterServerEvent(‘esx_TruckRobbery:missionAccepted’)
AddEventHandler(‘esx_TruckRobbery:missionAccepted’, function()
local policeOnline = 0
local Players = ESX.GetPlayers()
local _source = source
local xPlayer = ESX.GetPlayerFromId(_source)
local accountMoney = 0
accountMoney = xPlayer.getAccount(‘bank’).money

if not CheckCooldownTimer(GetPlayerIdentifier(source)) then

	if accountMoney <= Config.MissionCost then
		TriggerClientEvent('esx:showNotification', source, Config.NotEnoughMoney)
	else
		for i = 1, #Players do
			local xPlayer = ESX.GetPlayerFromId(Players[i])
			if xPlayer["job"]["name"] == Config.PoliceDatabaseName then
				policeOnline = policeOnline + 1
			end
		end

		if policeOnline >= Config.RequiredPoliceOnline then
			TriggerEvent("esx_TruckRobbery:missionCooldown",source)
			TriggerClientEvent("esx_TruckRobbery:HackingMiniGame",source)
		
			ESX.RegisterServerCallback("esx_TruckRobbery:StartMissionNow",function(source,cb)
			local _source = source
			local xPlayer = ESX.GetPlayerFromId(_source)
			cb()
			TriggerClientEvent("esx_TruckRobbery:startMission",source,0)
			end)
			xPlayer.removeAccountMoney('bank', Config.MissionCost)
		else
			TriggerClientEvent('esx:showNotification', source, Config.NotEnoughPolice)
		end
	end
else
	TriggerClientEvent("esx:showNotification",source,string.format(Config.CooldownMessage,GetCooldownTimer(GetPlayerIdentifier(source))))
end

end)

Hi there!

Since you are using ESX, I’d recommend utilizing the xPlayer.hasWeapon() function.

if xPlayer.hasWeapon('WEAPON_STICKYBOMB') then
    -- Do whatever you need (in this case I think start the robbery?)
else
    -- The player doesn't have sticky bomb, therefore send a notification.
end

Hope it helps.

Yes this helped!

Thank you very much :smiley:

Well actually since the weapons go as “items” and not at “weapons” you have to hold the stickybomb for it to work, is there an option to check for it as an item and not as a weapon?

do you have script “esx_TruckRobbery” ?