I’ve been trying to make an event that gives you a random amont of money 3500, 5000 as item, but is not working, when i TriggerEvent(gogoto:rewarditem) nothing happens
QBCore = exports['qb-core']:GetCoreObject()
RegisterNetEvent('gogoto:rewarditem')
AddEventHandler('gogoto:rewarditem', function(listKey)
local src = source
local Player = QBCore.Functions.GetPlayer(src)
local item = Config.Items
Player.Functions.AddMoney(item, math.random(3500, 5000))
TriggerClientEvent('inventory:client:ItemBox', src, QBCore.Shared.Items[item], 'add')
end)
where do you execute your TriggerEvent('gogoto:rewarditem') on client or serverside? Have you ever debugged your code to find out if the problem is in the event code or the event’s call?
Player.Functions.AddMoney('cash', math.random(3500, 5000)) -- Just make it cash
If you want the config to work you can do this
Config = {}
Config.Items = {
"cash",
}
Then in client you can do
QBCore = exports['qb-core']:GetCoreObject()
RegisterNetEvent('gogoto:rewarditem')
AddEventHandler('gogoto:rewarditem', function()
local src = source
local Player = QBCore.Functions.GetPlayer(src)
-- Selecting the first array in the Config
local item = Config.Items[1]
if item then
local cashAmount = math.random(3500, 5000)
Player.Functions.AddMoney(item, cashAmount)
TriggerClientEvent('inventory:client:ItemBox', src, QBCore.Shared.Items[item], 'add')
end
end)
If you want the money to be bank you can use this
Config = {}
Config.Items = {
"cash",
"bank"
}
Then in your client you can do this
QBCore = exports['qb-core']:GetCoreObject()
RegisterNetEvent('gogoto:rewarditem')
AddEventHandler('gogoto:rewarditem', function()
local src = source
local Player = QBCore.Functions.GetPlayer(src)
-- Selecting the second array in the Config since bank is the second array
local item = Config.Items[2]
if item then
local cashAmount = math.random(3500, 5000)
Player.Functions.AddMoney(item, cashAmount)
TriggerClientEvent('inventory:client:ItemBox', src, QBCore.Shared.Items[item], 'add')
end
end)