Good afternoon, does anyone know how to make a code with a handling in which a car switches from electric to combustion mode from a certain speed? I mean the sound of the engine.
Yes, i snooped around and found this native
Here is a little code snippet that does exactly what you are looking for, its not too complicated
local hybridVehicles = {
-- so in here you can have a whole list of vehicles that will have their engine sound changed based on their speed, idk all the engine sounds i just used the ones i can remember lol
[`zion`] = {electric = "voltic", engine = "zentorno"}
}
local lastSound = nil
CreateThread(function()
while true do
local playerPed = PlayerPedId()
local vehicle = GetVehiclePedIsIn(playerPed, false)
if vehicle ~= 0 and hybridVehicles[GetEntityModel(vehicle)] then
local speed = GetEntitySpeed(vehicle) * 3.6 -- Convert m/s to km/h
local hybridData = hybridVehicles[GetEntityModel(vehicle)]
local newSound = speed > 30 and hybridData.engine or hybridData.electric
if lastSound ~= newSound then
ForceUseAudioGameObject(vehicle, newSound)
lastSound = newSound
end
end
Wait(500) -- Adjust update interval if needed, but 500ms should be fine
end
end)
And a quick video if you want to see how it sounds like
Of course, you would still need to sync this with all other players, thats maybe 4/5 extra lines in the server side
1 Like
hey i just made a hybrid script if you would like it i will provide the github link