64 lines
		
	
	
	
		
			2.2 KiB
		
	
	
	
		
			Lua
		
	
	
	
	
	
			
		
		
	
	
			64 lines
		
	
	
	
		
			2.2 KiB
		
	
	
	
		
			Lua
		
	
	
	
	
	
local vehicleDefaults = {}
 | 
						|
 | 
						|
local function ApplyVehicleRoofboxHandling(vehicle)
 | 
						|
    if not Config.handling.enabled then
 | 
						|
        return
 | 
						|
    end
 | 
						|
    
 | 
						|
    local vecCentreOfMassOffset = GetVehicleHandlingVector(vehicle, 'CHandlingData', 'vecCentreOfMassOffset')
 | 
						|
    local fInitialDragCoeff = GetVehicleHandlingFloat(vehicle, 'CHandlingData', 'fInitialDragCoeff')
 | 
						|
    
 | 
						|
    Entity(vehicle).state.kq_roofbox_handling = {
 | 
						|
        vecCentreOfMassOffset = vecCentreOfMassOffset,
 | 
						|
        fInitialDragCoeff = fInitialDragCoeff,
 | 
						|
    }
 | 
						|
    
 | 
						|
    SetVehicleHandlingVector(vehicle, 'CHandlingData', 'vecCentreOfMassOffset', vecCentreOfMassOffset + vector3(0, 0, 1))
 | 
						|
    SetVehicleHandlingFloat(vehicle, 'CHandlingData', 'fInitialDragCoeff', math.min(120, fInitialDragCoeff + 6))
 | 
						|
    
 | 
						|
    -- This seems necessary to refresh vehicle handling
 | 
						|
    ModifyVehicleTopSpeed(vehicle, 0.0)
 | 
						|
    
 | 
						|
    Debug('Applied handling data')
 | 
						|
end
 | 
						|
 | 
						|
 | 
						|
local function ResetVehicleRoofboxHandling(vehicle)
 | 
						|
    if not Config.handling.enabled then
 | 
						|
        return
 | 
						|
    end
 | 
						|
    
 | 
						|
    local state = Entity(vehicle).state.kq_roofbox_handling
 | 
						|
    SetVehicleHandlingVector(vehicle, 'CHandlingData', 'vecCentreOfMassOffset', state.vecCentreOfMassOffset)
 | 
						|
    SetVehicleHandlingFloat(vehicle, 'CHandlingData', 'fInitialDragCoeff', state.fInitialDragCoeff)
 | 
						|
    
 | 
						|
    -- This seems necessary to refresh vehicle handling
 | 
						|
    ModifyVehicleTopSpeed(vehicle, 0.0)
 | 
						|
    
 | 
						|
    Entity(vehicle).state.kq_roofbox_handling = nil
 | 
						|
    
 | 
						|
    Debug('Reset handling data')
 | 
						|
end
 | 
						|
 | 
						|
if Config.handling.enabled then
 | 
						|
    Citizen.CreateThread(function()
 | 
						|
        
 | 
						|
        while true do
 | 
						|
            local sleep = 5000
 | 
						|
            
 | 
						|
            local playerPed = PlayerPedId()
 | 
						|
            local vehicle = GetVehiclePedIsUsing(playerPed)
 | 
						|
            if vehicle > 0 then
 | 
						|
                if ShouldVehicleHaveRoofbox(vehicle) then
 | 
						|
                    if not Entity(vehicle).state.kq_roofbox_handling then
 | 
						|
                        ApplyVehicleRoofboxHandling(vehicle)
 | 
						|
                    end
 | 
						|
                elseif Entity(vehicle).state.kq_roofbox_handling then
 | 
						|
                    ResetVehicleRoofboxHandling(vehicle)
 | 
						|
                end
 | 
						|
            end
 | 
						|
            
 | 
						|
            Citizen.Wait(sleep)
 | 
						|
        end
 | 
						|
    end)
 | 
						|
end
 |