Help with some code please

Hey guys, I am trying to fix this code, it is working but also giving me an error.

This is the code:

RegisterNetEvent('a5-AxonText:client:ToggleAxon', function() -- you can use this trigger to enable or disable the text (for example in HUD cinema mode)
    QBCore.Functions.TriggerCallback('QBCore:HasItem', function(result)
        if result then
            if toghud == true then
                toghud = false
            else
                toghud = true
            end
        end
    end, "youritem")
end)

And this is the error:

QBCore:HasItem is deprecated, please use QBCore.Functions.HasItem, it can be used on both server- and client-side and uses the same arguments.

Thx :slight_smile:

It’s not the error it’s the solution in the form of error. Use QBCore.Functions.HasItem instead of what you are doing.

I thought that, but I am not sure if it is right, so it would be like this then:

RegisterNetEvent('a5-AxonText:client:ToggleAxon', function() -- you can use this trigger to enable or disable the text (for example in HUD cinema mode)
    QBCore.Functions.TriggerCallback('QBCore.Functions.HasItem', function(result)
        if result then
            if toghud == true then
                toghud = false
            else
                toghud = true
            end
        end
    end, "youritem")
end)

That’s what I am wanting help with, I know that is the answer but (how to implement it) lol, I am still learning scripting, sorry.

Edit: nope, that what I didn’t work.

local theitem = QBCore.Functions.hasItem(“itemname”)

if theitem then
– do things
end

I still don’t get it, sorry. I am really new to this. Mind using the code I put in the original post and fix it with what you have above?!? thanks :slight_smile:

Edit: this notice: (QBCore:HasItem is deprecated, please use QBCore.Functions.HasItem, it can be used on both server- and client-side and uses the same arguments.) doesn’t seem to help a lot, there is a lot more than just changing one for the other, confusing people like me lol.

RegisterNetEvent('a5-AxonText:client:ToggleAxon', function()
  local item = QBCore.Functions.hasItem('youritem')
  if item then togud = not toghud end
end)

Hey mate, thanks for the help, this didn’t work though, what I am trying to do - the code I had before worked though gave an error too about the code being changed by qbcore now. This is for an Axon Bodycam to work only when you have the item, also only if you are police, and if you enable it via the Radialmenu, was all working before.

This is what I have in the radial menu:

            id = 'axonbc',
            title = 'Axon Bodycam',
            icon = 'video',
            type = 'client',
            event = 'axoncam:client:ToggleAxon',
            shouldClose = true

Then the code you gave me start line 38:

local QBCore = exports['qb-core']:GetCoreObject()
local PlayerJob = QBCore.Functions.GetPlayerData().job
local toghud = true


local function formatTime(data)
	for i=1, #data do
		local v = data[i]
		if v <= 9 then
			data[i] = "0"..v
		end
	end
	return data
end

local function GetPoliceData()
	local PlayerData = QBCore.Functions.GetPlayerData()
	local first = string.sub(PlayerData.charinfo.firstname, 1, 1)
	local second = PlayerData.charinfo.lastname
	local badge = PlayerData.metadata["callsign"]
	return string.upper(first.."."..second.."  	"..badge)
end

RegisterNetEvent("QBCore:Client:OnPlayerUnload", function()
	toghud = false
end)

RegisterNetEvent('QBCore:Client:OnJobUpdate', function(JobInfo)
    PlayerJob = JobInfo
	
end)

RegisterNetEvent('QBCore:Client:OnPlayerLoaded', function()
    PlayerJob = QBCore.Functions.GetPlayerData().job
	toghud = false
end)

RegisterNetEvent('axoncam:client:ToggleAxon', function()
  local item = QBCore.Functions.hasItem('axonbc')
  if item then togud = not toghud end
end)


--Threads
Citizen.CreateThread(function()
	while true do
		local sleep = 300
		if LocalPlayer.state.isLoggedIn then
			if (PlayerJob) and (PlayerJob.name == "police" and PlayerJob.onduty) and toghud then
				local data = GetPoliceData()
				Wait(250)
				SendNUIMessage({
					action  = 'changeJob',
					data = data
				})
			else
				SendNUIMessage({
					action  = 'changeJob',
					data = 'none'
				})
			end	
		end
		Wait(sleep)
	end
end)

Citizen.CreateThread(function()
	while true do
		local sleep = 5000
		if LocalPlayer.state.isLoggedIn then
			if (PlayerJob) and (PlayerJob.name == 'police') then
				sleep = 1000
				local hour = GetClockHours()
				local minute = GetClockMinutes()
				local month = GetClockMonth() + 1
				local dayOfMonth = GetClockDayOfMonth()	  
				local AP = 'AM'

				if hour == 0 or hour == 24 then
				hour = 12
				AP = 'AM'
				elseif hour >= 13 then
				hour = hour - 12
				AP = 'PM'
				end
				minute, month, dayOfMonth, hour = table.unpack(formatTime({minute, month, dayOfMonth, hour}))
				local formatted = "AXON BODYCAM "..dayOfMonth..':'..month..' T:'..hour..':'..minute..AP

				SendNUIMessage({
					action  = 'changeTime',
					data = formatted
				})
			end
		end
		Wait(sleep)
	end
end)

But when I press the (Radialmenu) option, nothing happens and I get this error:

Imgur

Try this:

RegisterNetEvent('axoncam:client:ToggleAxon', function()
  local item = QBCore.Functions.HasItem('axonbc')
  if item then togud = not toghud end
end)

We are getting somewhere, it doesn’t work still (it won’t start or show the axoncam like before) but at least no errors this time :laughing:

Here is the whole file (link removed), maybe you can try your end, save us going back and forth then :slight_smile:

1 Like

My bad try this:

RegisterNetEvent('axoncam:client:ToggleAxon', function()
  local item = QBCore.Functions.HasItem('axonbc')
  if item then toghud = not toghud end
end)

Great! works, thanks so much man, lol I should have noticed the missing (h - togud) in the typo myself :joy:

Do you mind seeing if you know the problem for this one too, a similar issue.

Thanks again :slight_smile:

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.