--[Error]--
None Outputting
--[Call to server]--
ESX.RegisterServerCallback('RR-MileagSystem:getVehiclesPlease', function(source, cb)
MySQL.ready(function ()
local result = (MySQL.Sync.fetchScalar('SELECT * FROM owned_vehicles'))
local _source = source
local xPlayer = ESX.GetPlayerFromId(_source)
local vehicles = {}
for i=1, #result, 1 do
local vehicle = result[i]
table.insert(vehicles, {vehicle = vehicle})
end
cb(vehicles)
end)
end)
--[Problem Code From Client]--
Citizen.CreateThread(
function()
while true do
Citizen.Wait(60000) -- 1 Minute
local player = GetPlayerPed(-1)
local vehicleS = GetVehiclePedIsIn(player, false)
local vehicleT = ESX.Game.GetVehicleProperties(vehicleS)
local plate = GetPlateFromList(vehicleT.plate)
local miles = GetMilesFromList(plate)
if IsPedInAnyVehicle(player, true) then
if GetPedInVehicleSeat(vehicleS, -1) then
if IsVehicleEngineOn(vehicleS) and plate == plate then
Citizen.Wait(Config.UpdateTime)
miles = miles + 1
TriggerServerEvent('RR:UpdateMiles', VehicleT.plate, miles)
end
end
end
end
end
)
-- Does Not Update to the database
--- Heres the trigger from server
RegisterServerEvent('RR:UpdateMiles')
AddEventHandler('RR:UpdateMiles', function(plate, miles)
local _source = source
local xPlayer = ESX.GetPlayerFromId(_source)
MySQL.Async.fetchAll('SELECT * FROM owned_vehicles WHERE @plate = plate, @miles = miles', {
['@plate'] = plate,
['@miles'] = miles
}, function (result)
if result[1] ~= nil then
MySQL.Sync.execute("UPDATE owned_vehicles SET miles=@miles WHERE plate=@plate",{
['@miles'] = result[1].miles + miles,
['@plate'] = plate
})
end
end
)
end)
Goal Is To Track Miles When vehicle is moving and then to update it every x Minutes
ik this seems simple and it is logically but I simply cannot get this correct I have received help correcting the callback error and I kinda
understand it but if someone who uses esx or knows how to achieve this please explain to me the logic
thank you for your time and patience!