TanguyOrtegat / esx_jb_eden_garage2

41 stars 50 forks source link

Fuel Level When Car Stored #94

Closed DonKKijotE closed 4 years ago

DonKKijotE commented 4 years ago

Hello guys,

I'm trying to get esx_jb_eden_garage2 working with LegacyFuel. The issue I'm having is that when I store the vehicle in the garage it gets stored with a new random fuelLevel amount. To get to this error I do the following:

I get the car out of the garage, I check in the database and the car status is changed to 0 and the fuelLevel is X. Then store it again and a random fuelLevel amount is stored.

I checked my es_extended/client/functions.lua to see ESX.Game.GetVehicleProperties and it has:

fuelLevel = ESX.Math.Round(GetVehicleFuelLevel(vehicle), 1),

Then ESX.Game.SetVehicleProperties has

if props.fuelLevel then SetVehicleFuelLevel(vehicle, props.fuelLevel + 0.0) end

I am assuming the code before is OK since it does store the fuel levels along the other vehicle properties.

I check esx_jb_eden_garage2 to see where the cars get stored and see this:

local vehicleProps  = GetVehicleProperties(vehicle)
                if vehicleProps ~= nil then
                    ESX.TriggerServerCallback('eden_garage:stockv',function(valid)
                        if(valid) then
                            for k,v in pairs (carInstance) do
                                if ESX.Math.Trim(v.plate) == ESX.Math.Trim(vehicleProps.plate) then
                                    table.remove(carInstance, k)
                                end
                            end
                            DeleteEntity(vehicle)
                            TriggerServerEvent('eden_garage:modifystate', vehicleProps.plate, true)
                            TriggerServerEvent("esx_eden_garage:MoveGarage", vehicleProps.plate, garage_name)
                            ESX.ShowNotification(_U('vehicle_in_garage'))
                        else
                            ESX.ShowNotification(_U('cannot_store_vehicle'))
                        end
                    end,vehicleProps, KindOfVehicle, garage_name, vehicle_type)

It also looks good since it's based on GetVehicleProperties(vehicle), so I see maybe eden_garage:stockv could be problematic?

I looked at the eden_garage:stockv and saw this:

local vehprop = json.encode(vehicleProps)
            local originalvehprops = json.decode(result[1].vehicle)
            if originalvehprops.model == vehiclemodel then
                MySQL.Async.execute("UPDATE owned_vehicles SET vehicle =@vehprop WHERE plate=@plate",{
                    ['@vehprop'] = vehprop,
                    ['@plate'] = vehplate
                }, function(rowsChanged)
                    cb(true)
                end)

It doesn't seem problematic to me but the fact is that I don't know why everytime I store the car the fuelLevel gets randomised.

Does anyone know why this might be happening? I don't think it has to do with LegacyFuel but I will also look that code.

Any help will much be appreciated, thanks and good job with eden_garage_2 :)

DonKKijotE commented 4 years ago

Sorry guys, I was investigating and it apparently is a LegacyFuel issue, I'm really sorry for opening this ticket. Please feel free to delete it and once again greate job!

TanguyOrtegat commented 4 years ago

yes indeed, legcy fuel issue. You need to sync legacy with when getting out the car