hello, I’m learning to program in lua for fivem and I’m making a script almost from scratch where I want to do some sql queries.
I get the following problem
SCRIPT ERROR: Execution of native 000000002f7a49e6 in script host failed: Argument at index 1 was null.
the code is this
RegisterServerEvent('duty:off')
AddEventHandler('duty:off', function(job)
local _source = source
local xPlayer = ESX.GetPlayerFromId(_source)
local trabajo = xPlayer.job.name
local grade = xPlayer.job.grade
if isInService(_source) then
local job = Services[_source].job
local actual_time = os.time()
local difference = actual_time - Services[_source].time
local identifier = Services[_source].identifier
Services[_source] = nil
MySQL.query('SELECT * FROM services WHERE identifier = @identifier AND job = @job',
{
['@identifier'] = identifier,
['@job'] = job,
},
function(result)
if result[1] then
totaltime = result[1].time + difference
timework = result[1].totaltime + difference
print ('horas: ' ..tostring(totaltime))
MySQL.update('UPDATE services SET time = @time, totaltime = @totaltime WHERE identifier = @identifier AND job = @job', {
['@identifier'] = identifier,
['@time'] = totaltime,
['@job'] = job,
['@totaltime'] = timework
})
else
MySQL.insert('INSERT INTO services (identifier, job, time, totaltime) VALUES (@identifier, @job, @time, @totaltime)',{
['identifier'] = identifier,
['job'] = job,
['time'] = difference,
['@totaltime'] = difference
})
end
TriggerClientEvent('esx:showNotification', source, Locales.leftService)
end)
else
TriggerClientEvent('esx:showNotification', source, Locales.youArentInService)
end
end)
sorry for the english and for the redundant code but i’m learning ![]()
using: oxmysql
