Hello, I’ve tried finding this feature myself, but haven’t found it. I was wondering if it was possible and how to change a vehicle engine sound on the fly. I’ve seen RSM Freeroam and Nopixel do it and want to figure it out for myself and the rest of the community.
local vehicle_sounds = {}
RegisterNetEvent("engine:sound")
AddEventHandler("engine:sound", function(name,plate)
if vehicle_sounds[plate] == nil then
vehicle_sounds[plate] = {}
end
vehicle_sounds[plate].plate = plate
vehicle_sounds[plate].name = name
end)
Citizen.CreateThread(function()
while true do
local mycoords = GetEntityCoords(PlayerPedId())
for k,v in pairs(GetGamePool('CVehicle')) do
if #(mycoords - GetEntityCoords(v, false)) < 50 then
local plate = string.gsub(GetVehicleNumberPlateText(v), "%s+", "")
if vehicle_sounds[plate] ~= nil and vehicle_sounds[plate].plate ~= nil and plate == vehicle_sounds[plate].plate and vehicle_sounds[plate].current ~= vehicle_sounds[plate].name then
ForceVehicleEngineAudio(v,vehicle_sounds[plate].name)
vehicle_sounds[plate].current = vehicle_sounds[plate].name
end
end
end
Wait(2000)
end
end)
Server side
RegisterCommand("changesound", function(source, args, rawCommand)
local veh = GetVehiclePedIsIn(GetPlayerPed(source))
if args[1] ~= nil and veh ~= 0 then
plate = string.gsub(GetVehicleNumberPlateText(veh), "%s+", "")
TriggerClientEvent("engine:sound", -1, tostring(args[1]),plate)
end
end, false)