[ESX] Refresh all items

I made a script that on use of an item it generates a new one and gives it to the player. But the problem is that the item doesn’t load because items loads only when you join server. I want to make after the item creation in database refresh of all items.

ESX.RegisterUsableItem('ad_pack', function(source)
	local xPlayer = ESX.GetPlayerFromId(source)

    local id = math.random(1000,9999)
    local nameee = "paczka_" .. tostring(id)

    MySQL.Async.fetchAll("INSERT INTO items (name, label, weight, rare, can_remove) VALUES(@name, @label, @weight, @rare, @can_remove)",
    {["@name"] = nameee, ["@label"] = "Paczka #" .. tostring(id), ["@weight"] = 1, ["@rare"] = 0, ["@can_remove"] = 1}, 
    function(result)
        TriggerClientEvent("output", source, result)
    end
    )

    Citizen.Wait(1000)

    xPlayer.addInventoryItem(nameee, 1)

    xPlayer.removeInventoryItem('ad_pack', 1)

    xPlayer.showNotification("~b~Test")
end)

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