How to save original handling values in script for later re-use?

Hi!

I am playing with SetVehicleHandlingFloat functions and I am trying to be able to set it back when requested (simply by pressing a button for now) by GetVehicleHandlingFloat native.

I am not sure, how should I tell to script I want to save car’s original value for switching it back later.

Any ideas? :slight_smile:

Here’s an example…

RegisterCommand("sethandlingfloat", function(source, args, raw) -- or your method
    local vehicle = GetVehiclePedIsUsing(PlayerPedId())
    if vehicle ~= 0 then
        originalValue = GetVehicleHandlingFloat(vehicle, "CHandlingData", "fSteeringLock")
        SetVehicleHandlingFloat(vehicle, "CHandlingData", "fSteeringLock", 5.0)
    end   
end)

RegisterCommand("sethandlingfloattoorigin", function(source, args, raw)
    local vehicle = GetVehiclePedIsUsing(PlayerPedId())
    if vehicle ~= 0 then
        SetVehicleHandlingFloat(vehicle, "CHandlingData", "fSteeringLock", originalValue)
    end
end)

I was trying to create toggle button for this thing, but can’t revert the change once I will make it :frowning:

It says “No such entity”, when exiting vehicle and does not change. Any ideas?

Citizen.CreateThread( function()
	
	while true do
	Wait(1)
		toggle = false
		ped = PlayerPedId()
		vehicle = GetVehiclePedIsUsing( ped )
		--lastveh	= GetPlayersLastVehicle(ped, 1)
		if DoesEntityExist( ped ) and not IsEntityDead( ped ) and DoesEntityExist(vehicle) and GetPedInVehicleSeat(vehicle, -1) == ped then
			originalValuefInitialDragCoeff = GetVehicleHandlingFloat(vehicle, "CHandlingData", "fInitialDragCoeff")
			if IsControlJustReleased(0, control) then
			toggle = not toggle
				if toggle then
					SetVehicleHandlingFloat(vehicle, 'CHandlingData', 'fInitialDragCoeff', 5.22)
				else
					SetVehicleHandlingFloat(vehicle, 'CHandlingData', 'fInitialDragCoeff', originalValuefInitialDragCoeff)
				end
			end			
        else 
              SetVehicleHandlingFloat(lastveh, 'CHandlingData', 'fInitialDragCoeff', originalValuefInitialDragCoeff)
		end
	end	
	
end )

Edit.: When I’ve tried commands you’ve suggested here, it said “no script guide for vehicle” instead…

That’s not exactly performance friendly, calling PlayerPedId() and GetVehiclePedIsUsing() and other unnecessary things every other tick.

I’m in the process of rewriting it to be less performance heavy, what’s control defined as?

I understand. I just wanted to test, if it will even work. Optimization would be next step.

Control has been set on F5. I wonder, if I called wrong value for character or it just doesn’t communicate with each other for some reason.

I am still unable to figure out how to tell the server this is the very vehicle I want to set the original values to. Something like vehicleId or something.

Still gives me No such entity.