Hey there, new to posting here so sorry If I mess something up
I’ve been bugfixing/developing for a server for about a month now and picked up some things, I mainly worked on other peoples scripts to adapt them or fix them.
But anyway, I recently decided to make my own mining script to test my own knowledge
It’s base is QBCore but I’m running into some annoying issues. It uses bt-target for selecting points and nh-context for choosing options.
Basically my issues are based in the server.lua, whenever I try to grab the item by name “GetItemByName” it claims its a nil value. Which is painfully anying when you need to grab item amounts for selling.
Other commands like additem and removeitem work, but if i try and pull information it throws out errors.
I’ve tried many different ways and it won’t work…so I assume I’m missing something glaringly obvious
can anyone take a look and let me know how to fix it and let it grab inventory info?
The code mainly in question is:
RegisterNetEvent('jim-mining:SellOre')
AddEventHandler('jim-mining:SellOre', function(data)
local src = source
local Player = QBCore.Functions.GetPlayer(source)
if data.id == 1 then
local Ore = Player.Functions.GetItemByName("copperore")
if data.id == 2 then
local Ore = Player.Functions.GetItemByName("ironore")
if data.id == 3 then
local Ore = Player.Functions.GetItemByName("goldore")
if data.id == 4 then
local Ore = Player.Functions.GetItemByName("carbon")
end
TriggerClientEvent("inventory:client:ItemBox", source, QBCore.Shared.Items[Ore], "remove", Ore.amount)
TriggerNetEvent('jim-mining:SellAnim')
end)
When it goes to show the item box it claims it returns a nil value in the server log
But the data.id does seem to be called correctly