JamesSc0tt / FiveM-FSN-Framework

Public Roleplay Framework for FiveM.
56 stars 47 forks source link

Vehicle odometer #33

Closed bringrainfire closed 3 years ago

bringrainfire commented 3 years ago

I added vehicle odometer for vehicles, tested to work accurately and is performance oriented. It will only make one database call every 1 mile/km or if the driver leaves the seat. The only bug found -> Storing the vehicle in the garage whilst still in the driver's seat results in null license plate. I couldn't figure out a way around it yet and since it doesn't hurt anything I'm going ahead with the pull request.

iTzCrutchie commented 3 years ago

How is the license plate being set to null not hurt anything? That's literally what fsn_cargarage uses to set vehicle details.

As well as for impounding and setting the vehicles status to whether it's out or not.

Fix that and I might consider merging. And 1 minute is a lot of db saves. How much Ms does this add onto vehiclecontrol? There are a lot of natives that don't necessarily need to be run every second in the thread.

bringrainfire commented 3 years ago

"How is the license plate being set to null not hurt anything? That's literally what fsn_cargarage uses to set vehicle details." Answer: I'm not using car garage for anything,

local currentPlate = GetVehicleNumberPlateText(GetVehiclePedIsIn(GetPlayerPed(-1), false)) is what I'm using and local currentPlate = GetVehicleNumberPlateText(GetVehiclePedIsIn(GetPlayerPed(-1), true)) is what is used when the driver is no longer in the seat, except that doesn't work when the vehicle is stored in the garage while the driver is still in it as it return null for both methods.

These natives are also only called when needed, not all the time.


"And 1 minute is a lot of db saves." It doesn't save every one minute.

It gets the distance the vehicle has gone in 1 second, then adds that to a buffer "distanceTraveled = ((Speed0.000278)timeAB)/1000 -- distance = ((speed converted to seconds) * time difference) / divided by 1000 to normalize" Only when the buffer reaches 1 MILE/KILOMETER(unit of measure is not relevant in this formula) does it save it to the database. this value can be increased or decreased. Or when the driver leaves the driver's seat.

"How much Ms does this add onto vehiclecontrol?" very negligible, runs in a separate thread on the client anyways and not in the fsn_vehiclecontrol's main thread. Database calls are made from the server's side.

Anyways, I've got plenty of comments in the code that covers all these questions. Please let me know if there's more.

iTzCrutchie commented 3 years ago

You said it nulls the plate when saving it to the database when you store the car? If the plate is null in the database then fsn cargarage won't have a plate to update the things I mentioned.

Unless I'm misunderstanding this:

"The only bug found -> Storing the vehicle in the garage whilst still in the driver's seat results in null license plate"

Unless you just mean this passes a null plate so it doesn't update the vehicle database with the correct milage.

bringrainfire commented 3 years ago

It doesn't null the database value this native "GetVehicleNumberPlateText(GetVehiclePedIsIn(GetPlayerPed(-1), true))" returns nothing. I'm guessing it's because the car is deleted from fivem's scope when storing the vehicle so it has nothing to find.

the sql just updates the odometer value in db using the plate to find it. with no plate to find no value is updated.

sorry for the confusion, I should have worded that better.

iTzCrutchie commented 3 years ago

It doesn't null the database value this native "GetVehicleNumberPlateText(GetVehiclePedIsIn(GetPlayerPed(-1), true))" returns nothing. I'm guessing it's because the car is deleted from fivem's scope when storing the vehicle so it has nothing to find.

the sql just updates the odometer value in db using the plate to find it. with no plate to find no value is updated.

sorry for the confusion, I should have worded that better.

Gotcha. Yea just confusion on my part it's late. Was thinking it was nulling the database as well 😖 I think your guess on why the plate might be null is right. I'll review the rest and get it merged in the morning. 👍

bringrainfire commented 3 years ago

no problem, thanks!