Jump to content

hello guys aim need help


Clay

Recommended Posts

Posted (edited)

hi all 

I need help

correct this script need to repair the MTA on volume SFX Volume plizzz help me

 

 

local sound
local lastGear = nil
local lastRPM = nil
local downgrading = false
local downgradingRPM = {0,0}
local downgradingTime = 2000
local downgradingProgress = 0
local start = 0
local worked = 0

local vehiclesSounds = {
    [597] = {engine = "sounds/song1.wav",blowoff = "sounds/blowoff.wav",gear = "sounds/gear.wav", downTime = 2000, coeff = 10000, volume = 0.8, maxDistance = 20},
    [542] = {engine = "sounds/song1.wav",blowoff = "sounds/blowoff.wav",gear = "sounds/gear.wav", downTime = 2000, coeff = 10000, volume = 0.8, maxDistance = 20},
    [555] = {engine = "sounds/song2.wav",blowoff = "sounds/blowoff.wav",gear = "sounds/gear.wav", downTime = 2000, coeff = 10000, volume = 0.8, maxDistance = 20},
    [482] = {engine = "sounds/song2.wav",blowoff = "sounds/blowoff.wav",gear = "sounds/gear.wav", downTime = 2000, coeff = 10000, volume = 0.8, maxDistance = 20},
    [402] = {engine = "sounds/song3.wav",blowoff = "sounds/blowoff.wav",gear = "sounds/gear.wav", downTime = 2000, coeff = 10000, volume = 0.8, maxDistance = 20},
    [491] = {engine = "sounds/song4.wav",blowoff = "sounds/blowoff.wav",gear = "sounds/gear.wav", downTime = 2000, coeff = 10000, volume = 0.8, maxDistance = 20},
    [410] = {engine = "sounds/song4.wav",blowoff = "sounds/blowoff.wav",gear = "sounds/gear.wav", downTime = 2000, coeff = 10000, volume = 0.8, maxDistance = 20},
    [492] = {engine = "sounds/song5.wav",blowoff = "sounds/blowoff.wav",gear = "sounds/gear.wav", downTime = 2000, coeff = 10000, volume = 0.8, maxDistance = 20},
    [445] = {engine = "sounds/song6.wav",blowoff = "sounds/blowoff.wav",gear = "sounds/gear.wav", downTime = 2000, coeff = 10000, volume = 0.8, maxDistance = 20},
    [426] = {engine = "sounds/song7.wav",blowoff = "sounds/blowoff.wav",gear = "sounds/gear.wav", downTime = 2000, coeff = 10000, volume = 0.8, maxDistance = 20},
    [418] = {engine = "sounds/song8.wav",blowoff = "sounds/blowoff.wav",gear = "sounds/gear.wav", downTime = 2000, coeff = 10000, volume = 0.8, maxDistance = 20},
    [466] = {engine = "sounds/song9.wav",blowoff = "sounds/blowoff.wav",gear = "sounds/gear.wav", downTime = 2000, coeff = 10000, volume = 0.8, maxDistance = 20},
    [405] = {engine = "sounds/song10.wav",blowoff = "sounds/blowoff.wav",gear = "sounds/gear.wav", downTime = 2000, coeff = 10000, volume = 0.8, maxDistance = 20},
    [474] = {engine = "sounds/song11.wav",blowoff = "sounds/blowoff.wav",gear = "sounds/gear.wav", downTime = 2000, coeff = 10000, volume = 0.8, maxDistance = 20},
    [587] = {engine = "sounds/song12.wav",blowoff = "sounds/blowoff.wav",gear = "sounds/gear.wav", downTime = 2000, coeff = 10000, volume = 0.8, maxDistance = 20},
    [518] = {engine = "sounds/song13.wav",blowoff = "sounds/blowoff.wav",gear = "sounds/gear.wav", downTime = 2000, coeff = 10000, volume = 0.8, maxDistance = 20},
    [547] = {engine = "sounds/song14.wav",blowoff = "sounds/blowoff.wav",gear = "sounds/gear.wav", downTime = 2000, coeff = 10000, volume = 0.8, maxDistance = 20},
    [426] = {engine = "sounds/song14.wav",blowoff = "sounds/blowoff.wav",gear = "sounds/gear.wav", downTime = 2000, coeff = 10000, volume = 0.8, maxDistance = 20},
    [483] = {engine = "sounds/song15.wav",blowoff = "sounds/blowoff.wav",gear = "sounds/gear.wav", downTime = 2000, coeff = 10000, volume = 0.8, maxDistance = 20},
    [412] = {engine = "sounds/song16.wav",blowoff = "sounds/blowoff.wav",gear = "sounds/gear.wav", downTime = 2000, coeff = 10000, volume = 0.8, maxDistance = 20},
    [411] = {engine = "sounds/song17.wav",blowoff = "sounds/blowoff.wav",gear = "sounds/gear.wav", downTime = 2000, coeff = 10000, volume = 0.8, maxDistance = 20},
}

function startSound(vehicle)
    if isElement(vehicle) and not isElement ( getElementData ( vehicle, "carsound:sound" ) ) then
        local model = getElementModel ( vehicle )
        if vehiclesSounds[model] then
            local x,y,z = getElementPosition ( vehicle )
            local sound = playSound3D ( vehiclesSounds[model].engine, x, y, z, true )
            attachElements ( sound, vehicle )
            local rpm = getVehicleRPM(vehicle)
            setElementData (vehicle, "carsound:lastGear", getVehicleCurrentGear(vehicle), false)
            setElementData (vehicle, "carsound:lastRPM", rpm, false)
            setElementData (vehicle, "carsound:sound", sound, false)
            if vehiclesSounds[model].volume then
                setSoundVolume ( sound, vehiclesSounds[model].volume )
            end
            setSoundMaxDistance ( sound, vehiclesSounds[model].maxDistance )
            setSoundSpeed ( sound, rpm/vehiclesSounds[model].coeff )
        end
    end
end

addEventHandler( "onClientElementStreamIn", getRootElement( ),
    function ( )
        if getElementType( source ) == "vehicle" then
           startSound(source)
        end
    end
)

addEventHandler( "onClientElementStreamOut", getRootElement( ),
    function ( )
        if getElementType( source ) == "vehicle" then
            local sound = getElementData ( source, "carsound:sound" )
            if isElement ( sound ) then
                destroyElement ( sound )
            end
            local downgradingTimers = getElementData ( source, "carsound:downgradingTimers" ) or {}
            if isTimer ( downgradingTimers[1] ) then killTimer ( downgradingTimers[1] ) end
            if isTimer ( downgradingTimers[2] ) then killTimer ( downgradingTimers[2] ) end
        end
    end
)

addEventHandler("onClientElementDestroy", getRootElement(), function ()
    if getElementType(source) == "vehicle" then
        local sound = getElementData ( source, "carsound:sound" )
        if isElement ( sound ) then
            destroyElement ( sound )
        end
        local downgradingTimers = getElementData ( source, "carsound:downgradingTimers" ) or {}
        if isTimer ( downgradingTimers[1] ) then killTimer ( downgradingTimers[1] ) end
        if isTimer ( downgradingTimers[2] ) then killTimer ( downgradingTimers[2] ) end
    end
end)

--[[function unBugSounds()
    setTimer(
        function()
            setWorldSoundEnabled ( 40, false )
            setWorldSoundEnabled (12, false )
            addEventHandler("onClientRender", getRootElement(), checkVehiclesRPM )
                for i, vehicle in ipairs ( getElementsByType ( "vehicle", true ) ) do
                    startSound(vehicle)
                end
        1000, 0)
    end
end
addEventHandler("onClientRender", root, unBugSounds)
addEventHandler("onClientResourceStart",root,unBugSounds)]]

function disableSounds()
    setWorldSoundEnabled ( 40, false )
    setWorldSoundEnabled ( 12, false )
    addEventHandler("onClientRender", getRootElement(), checkVehiclesRPM )
    for i, vehicle in ipairs ( getElementsByType ( "vehicle", true ) ) do
        startSound(vehicle)
    end
end
addEventHandler("onClientResourceStart",getResourceRootElement(),disableSounds)

function test(text,vehicle)
    if getPedOccupiedVehicle ( localPlayer ) and getPedOccupiedVehicle ( localPlayer ) == vehicle then
        outputChatBox(text)
    end
end

function checkVehiclesRPM()
    local x,y,z = getElementPosition ( localPlayer )
    for i, vehicle in ipairs ( getElementsByType ( "vehicle", true ) ) do
        local tx, ty, tz = getElementPosition ( vehicle ) 
        if getDistanceBetweenPoints3D (x,y,z,tx,ty,tz) < 40 then
            local sound = getElementData ( vehicle, "carsound:sound" )
            if isElement(sound) then
                local rpm = getVehicleRPM(vehicle) 
                if not getVehicleEngineState(vehicle) or rpm == 0 then
                    if not isSoundPaused ( sound ) then
                        --setSoundPaused ( sound, true )
                    end
                    return true
                end
                if isSoundPaused ( sound ) then
                    setSoundPaused ( sound, false )
                end
                local model = getElementModel ( vehicle )
                local lastGear = getElementData ( vehicle, "carsound:lastGear" ) or 1
                local lastRPM = getElementData ( vehicle, "carsound:lastRPM" ) or 0
                local curGear = getVehicleCurrentGear(vehicle)
                if lastGear > curGear then
                    playGearSound(vehicle)
                end
                local downgradingTimers = getElementData ( vehicle, "carsound:downgradingTimers" ) or {}
                if lastGear > curGear and not downgrading then
                    if isTimer ( downgradingTimers[1] ) then killTimer ( downgradingTimers[1] ) end
                    if isTimer ( downgradingTimers[2] ) then killTimer ( downgradingTimers[2] ) end
                    downgrading = true
                    downgradingProgress = 0
                    worked = 0
                    start = getTickCount()
                    downgradingRPM = {lastRPM,500}
                    downgradingTimers[1] = setTimer (function() downgradingProgress = downgradingProgress+(1/(vehiclesSounds[model].downTime/50)) worked = worked+1 end, 50, vehiclesSounds[model].downTime/50)
                    downgradingTimers[2] = setTimer (function() downgrading  = false end, vehiclesSounds[model].downTime, 1)
                    setElementData ( vehicle, "carsound:downgradingTimers", downgradingTimers, false )
                else
                    if curGear > lastGear then
                        playBlowoffSound(vehicle)
                    end
                    if downgrading then
                        if ( lastRPM < rpm and ( lastGear <= curGear ) ) or lastGear < curGear then
                            if isTimer ( downgradingTimers[1] ) then killTimer ( downgradingTimers[1] ) end
                            if isTimer ( downgradingTimers[2] ) then killTimer ( downgradingTimers[2] ) end
                            downgrading = false
                        end
                        local temprpm = interpolateBetween ( downgradingRPM[1], 0, 0, downgradingRPM[2], 0, 0, downgradingProgress, "Linear" )
                        setSoundSpeed ( sound, temprpm/vehiclesSounds[model].coeff )
                    else
                        setSoundSpeed ( sound, rpm/vehiclesSounds[model].coeff )
                    end
                end
                setElementData ( vehicle, "carsound:lastGear", curGear, false )
                setElementData ( vehicle, "carsound:lastRPM", rpm, false )
            end
        end
    end
end

addEventHandler("onClientResourceStart", getResourceRootElement(),startSound)

function playBlowoffSound(vehicle)
    if isElement ( vehicle ) then
        local x,y,z = getElementPosition ( vehicle )
        local px,py,pz = getElementPosition ( localPlayer )
        if getDistanceBetweenPoints3D ( x,y,z, px,py,pz ) < 5 then
            local model = getElementModel ( vehicle )
            local blowoffSound = playSound3D ( vehiclesSounds[model].blowoff, x, y, z, false )
            attachElements ( blowoffSound, vehicle )
        end
    end
end

function playGearSound(vehicle)
    if isElement ( vehicle ) then
        local x,y,z = getElementPosition ( vehicle )
        local px,py,pz = getElementPosition ( localPlayer )
        if getDistanceBetweenPoints3D ( x,y,z, px,py,pz ) < 15 then
            local model = getElementModel ( vehicle )
            local gearSound = playSound3D ( vehiclesSounds[model].gear, x, y, z, false )
            setSoundVolume(gearSound, 2)
            attachElements ( gearSound, vehicle )
        end
    end
end

function getVehicleRPM(vehicle) 
    if isElement(vehicle) then  
        local vehicleRPM = getElementData ( vehicle, "rpm" ) or 0
        if (isVehicleOnGround(vehicle)) then     
            if (getVehicleEngineState(vehicle) == true) then
                if(getVehicleCurrentGear(vehicle) > 0) then
                    vehicleRPM = math.floor(((getVehicleSpeed(vehicle)/getVehicleCurrentGear(vehicle))*180) + 0.99)
                    
                    if (vehicleRPM < 650) then
                        vehicleRPM = math.random(650, 750)
                    elseif (vehicleRPM >= 9800) then
                        vehicleRPM = 9800
                    end
                else
                    vehicleRPM = math.floor(((getVehicleSpeed(vehicle)/1)*180) + 0.99)
                    
                    if (vehicleRPM < 650) then
                        vehicleRPM = math.random(650, 750)
                    elseif (vehicleRPM >= 9800) then
                        vehicleRPM = 9800
                    end
                end
            else
                vehicleRPM = 0
            end
        else
            if (getVehicleEngineState(vehicle) == true) then
                vehicleRPM = vehicleRPM - 0
                    
                if (vehicleRPM < 650) then
                    vehicleRPM = math.random(650, 750)
                elseif (vehicleRPM >= 9800) then
                    vehicleRPM = 9800
                end
            else
                vehicleRPM = 0
            end
        end
        setElementData ( vehicle, "rpm", vehicleRPM, false )
        return tonumber(vehicleRPM)
    else
        return 0
    end
end

function getVehicleSpeed(vehicle)   
    if isElement(vehicle) then
        local vx, vy, vz = getElementVelocity(vehicle)
        
        if (vx) and (vy)and (vz) then
            return math.sqrt(vx^2 + vy^2 + vz^2) * 180 -- km/h
        else
            return 0
        end
    else
        return 0
    end
end

 

Edited by Dutchman101
Fix [code] formatting
  • MTA Team
Posted (edited)
On 2017-3-21 at 16:03, Clay said:

Where to put the code?

Fixed, next time simply add the ''< >'' shortcut in the text editor: (and select LUA for highlighting)

MSHAyJ3.png

Edited by Dutchman101
  • Like 1
Posted
local sound
local lastGear = nil
local lastRPM = nil
local downgrading = false
local downgradingRPM = {0,0}
local downgradingTime = 2000
local downgradingProgress = 0
local start = 0
local worked = 0

local vehiclesSounds = {
    [597] = {engine = "sounds/song1.wav",blowoff = "sounds/blowoff.wav",gear = "sounds/gear.wav", downTime = 2000, coeff = 10000, volume = 0.8, maxDistance = 20},
    [542] = {engine = "sounds/song1.wav",blowoff = "sounds/blowoff.wav",gear = "sounds/gear.wav", downTime = 2000, coeff = 10000, volume = 0.8, maxDistance = 20},
    [555] = {engine = "sounds/song2.wav",blowoff = "sounds/blowoff.wav",gear = "sounds/gear.wav", downTime = 2000, coeff = 10000, volume = 0.8, maxDistance = 20},
    [482] = {engine = "sounds/song2.wav",blowoff = "sounds/blowoff.wav",gear = "sounds/gear.wav", downTime = 2000, coeff = 10000, volume = 0.8, maxDistance = 20},
    [402] = {engine = "sounds/song3.wav",blowoff = "sounds/blowoff.wav",gear = "sounds/gear.wav", downTime = 2000, coeff = 10000, volume = 0.8, maxDistance = 20},
    [491] = {engine = "sounds/song4.wav",blowoff = "sounds/blowoff.wav",gear = "sounds/gear.wav", downTime = 2000, coeff = 10000, volume = 0.8, maxDistance = 20},
    [410] = {engine = "sounds/song4.wav",blowoff = "sounds/blowoff.wav",gear = "sounds/gear.wav", downTime = 2000, coeff = 10000, volume = 0.8, maxDistance = 20},
    [492] = {engine = "sounds/song5.wav",blowoff = "sounds/blowoff.wav",gear = "sounds/gear.wav", downTime = 2000, coeff = 10000, volume = 0.8, maxDistance = 20},
    [445] = {engine = "sounds/song6.wav",blowoff = "sounds/blowoff.wav",gear = "sounds/gear.wav", downTime = 2000, coeff = 10000, volume = 0.8, maxDistance = 20},
    [426] = {engine = "sounds/song7.wav",blowoff = "sounds/blowoff.wav",gear = "sounds/gear.wav", downTime = 2000, coeff = 10000, volume = 0.8, maxDistance = 20},
    [418] = {engine = "sounds/song8.wav",blowoff = "sounds/blowoff.wav",gear = "sounds/gear.wav", downTime = 2000, coeff = 10000, volume = 0.8, maxDistance = 20},
    [466] = {engine = "sounds/song9.wav",blowoff = "sounds/blowoff.wav",gear = "sounds/gear.wav", downTime = 2000, coeff = 10000, volume = 0.8, maxDistance = 20},
    [405] = {engine = "sounds/song10.wav",blowoff = "sounds/blowoff.wav",gear = "sounds/gear.wav", downTime = 2000, coeff = 10000, volume = 0.8, maxDistance = 20},
    [474] = {engine = "sounds/song11.wav",blowoff = "sounds/blowoff.wav",gear = "sounds/gear.wav", downTime = 2000, coeff = 10000, volume = 0.8, maxDistance = 20},
    [587] = {engine = "sounds/song12.wav",blowoff = "sounds/blowoff.wav",gear = "sounds/gear.wav", downTime = 2000, coeff = 10000, volume = 0.8, maxDistance = 20},
    [518] = {engine = "sounds/song13.wav",blowoff = "sounds/blowoff.wav",gear = "sounds/gear.wav", downTime = 2000, coeff = 10000, volume = 0.8, maxDistance = 20},
    [547] = {engine = "sounds/song14.wav",blowoff = "sounds/blowoff.wav",gear = "sounds/gear.wav", downTime = 2000, coeff = 10000, volume = 0.8, maxDistance = 20},
    [426] = {engine = "sounds/song14.wav",blowoff = "sounds/blowoff.wav",gear = "sounds/gear.wav", downTime = 2000, coeff = 10000, volume = 0.8, maxDistance = 20},
    [483] = {engine = "sounds/song15.wav",blowoff = "sounds/blowoff.wav",gear = "sounds/gear.wav", downTime = 2000, coeff = 10000, volume = 0.8, maxDistance = 20},
    [412] = {engine = "sounds/song16.wav",blowoff = "sounds/blowoff.wav",gear = "sounds/gear.wav", downTime = 2000, coeff = 10000, volume = 0.8, maxDistance = 20},
    [411] = {engine = "sounds/song17.wav",blowoff = "sounds/blowoff.wav",gear = "sounds/gear.wav", downTime = 2000, coeff = 10000, volume = 0.8, maxDistance = 20},
}

function startSound(vehicle)
    if isElement(vehicle) and not isElement ( getElementData ( vehicle, "carsound:sound" ) ) then
        local model = getElementModel ( vehicle )
        if vehiclesSounds[model] then
            local x,y,z = getElementPosition ( vehicle )
            local sound = playSound3D ( vehiclesSounds[model].engine, x, y, z, true )
            attachElements ( sound, vehicle )
            local rpm = getVehicleRPM(vehicle)
            setElementData (vehicle, "carsound:lastGear", getVehicleCurrentGear(vehicle), false)
            setElementData (vehicle, "carsound:lastRPM", rpm, false)
            setElementData (vehicle, "carsound:sound", sound, false)
            if vehiclesSounds[model].volume then
                setSoundVolume ( sound, vehiclesSounds[model].volume )
            end
            setSoundMaxDistance ( sound, vehiclesSounds[model].maxDistance )
            setSoundSpeed ( sound, rpm/vehiclesSounds[model].coeff )
        end
    end
end

addEventHandler( "onClientElementStreamIn", getRootElement( ),
    function ( )
        if getElementType( source ) == "vehicle" then
           startSound(source)
        end
    end
)

addEventHandler( "onClientElementStreamOut", getRootElement( ),
    function ( )
        if getElementType( source ) == "vehicle" then
            local sound = getElementData ( source, "carsound:sound" )
            if isElement ( sound ) then
                destroyElement ( sound )
            end
            local downgradingTimers = getElementData ( source, "carsound:downgradingTimers" ) or {}
            if isTimer ( downgradingTimers[1] ) then killTimer ( downgradingTimers[1] ) end
            if isTimer ( downgradingTimers[2] ) then killTimer ( downgradingTimers[2] ) end
        end
    end
)

addEventHandler("onClientElementDestroy", getRootElement(), function ()
    if getElementType(source) == "vehicle" then
        local sound = getElementData ( source, "carsound:sound" )
        if isElement ( sound ) then
            destroyElement ( sound )
        end
        local downgradingTimers = getElementData ( source, "carsound:downgradingTimers" ) or {}
        if isTimer ( downgradingTimers[1] ) then killTimer ( downgradingTimers[1] ) end
        if isTimer ( downgradingTimers[2] ) then killTimer ( downgradingTimers[2] ) end
    end
end)

--[[function unBugSounds()
    setTimer(
        function()
            setWorldSoundEnabled ( 40, false )
            setWorldSoundEnabled (12, false )
            addEventHandler("onClientRender", getRootElement(), checkVehiclesRPM )
                for i, vehicle in ipairs ( getElementsByType ( "vehicle", true ) ) do
                    startSound(vehicle)
                end
        1000, 0)
    end
end
addEventHandler("onClientRender", root, unBugSounds)
addEventHandler("onClientResourceStart",root,unBugSounds)]]

function disableSounds()
    setWorldSoundEnabled ( 40, false )
    setWorldSoundEnabled ( 12, false )
    addEventHandler("onClientRender", getRootElement(), checkVehiclesRPM )
    for i, vehicle in ipairs ( getElementsByType ( "vehicle", true ) ) do
        startSound(vehicle)
    end
end
addEventHandler("onClientResourceStart",getResourceRootElement(),disableSounds)

function test(text,vehicle)
    if getPedOccupiedVehicle ( localPlayer ) and getPedOccupiedVehicle ( localPlayer ) == vehicle then
        outputChatBox(text)
    end
end

function checkVehiclesRPM()
    local x,y,z = getElementPosition ( localPlayer )
    for i, vehicle in ipairs ( getElementsByType ( "vehicle", true ) ) do
        local tx, ty, tz = getElementPosition ( vehicle ) 
        if getDistanceBetweenPoints3D (x,y,z,tx,ty,tz) < 40 then
            local sound = getElementData ( vehicle, "carsound:sound" )
            if isElement(sound) then
                local rpm = getVehicleRPM(vehicle) 
                if not getVehicleEngineState(vehicle) or rpm == 0 then
                    if not isSoundPaused ( sound ) then
                        --setSoundPaused ( sound, true )
                    end
                    return true
                end
                if isSoundPaused ( sound ) then
                    setSoundPaused ( sound, false )
                end
                local model = getElementModel ( vehicle )
                local lastGear = getElementData ( vehicle, "carsound:lastGear" ) or 1
                local lastRPM = getElementData ( vehicle, "carsound:lastRPM" ) or 0
                local curGear = getVehicleCurrentGear(vehicle)
                if lastGear > curGear then
                    playGearSound(vehicle)
                end
                local downgradingTimers = getElementData ( vehicle, "carsound:downgradingTimers" ) or {}
                if lastGear > curGear and not downgrading then
                    if isTimer ( downgradingTimers[1] ) then killTimer ( downgradingTimers[1] ) end
                    if isTimer ( downgradingTimers[2] ) then killTimer ( downgradingTimers[2] ) end
                    downgrading = true
                    downgradingProgress = 0
                    worked = 0
                    start = getTickCount()
                    downgradingRPM = {lastRPM,500}
                    downgradingTimers[1] = setTimer (function() downgradingProgress = downgradingProgress+(1/(vehiclesSounds[model].downTime/50)) worked = worked+1 end, 50, vehiclesSounds[model].downTime/50)
                    downgradingTimers[2] = setTimer (function() downgrading  = false end, vehiclesSounds[model].downTime, 1)
                    setElementData ( vehicle, "carsound:downgradingTimers", downgradingTimers, false )
                else
                    if curGear > lastGear then
                        playBlowoffSound(vehicle)
                    end
                    if downgrading then
                        if ( lastRPM < rpm and ( lastGear <= curGear ) ) or lastGear < curGear then
                            if isTimer ( downgradingTimers[1] ) then killTimer ( downgradingTimers[1] ) end
                            if isTimer ( downgradingTimers[2] ) then killTimer ( downgradingTimers[2] ) end
                            downgrading = false
                        end
                        local temprpm = interpolateBetween ( downgradingRPM[1], 0, 0, downgradingRPM[2], 0, 0, downgradingProgress, "Linear" )
                        setSoundSpeed ( sound, temprpm/vehiclesSounds[model].coeff )
                    else
                        setSoundSpeed ( sound, rpm/vehiclesSounds[model].coeff )
                    end
                end
                setElementData ( vehicle, "carsound:lastGear", curGear, false )
                setElementData ( vehicle, "carsound:lastRPM", rpm, false )
            end
        end
    end
end

addEventHandler("onClientResourceStart", getResourceRootElement(),startSound)

function playBlowoffSound(vehicle)
    if isElement ( vehicle ) then
        local x,y,z = getElementPosition ( vehicle )
        local px,py,pz = getElementPosition ( localPlayer )
        if getDistanceBetweenPoints3D ( x,y,z, px,py,pz ) < 5 then
            local model = getElementModel ( vehicle )
            local blowoffSound = playSound3D ( vehiclesSounds[model].blowoff, x, y, z, false )
            attachElements ( blowoffSound, vehicle )
        end
    end
end

function playGearSound(vehicle)
    if isElement ( vehicle ) then
        local x,y,z = getElementPosition ( vehicle )
        local px,py,pz = getElementPosition ( localPlayer )
        if getDistanceBetweenPoints3D ( x,y,z, px,py,pz ) < 15 then
            local model = getElementModel ( vehicle )
            local gearSound = playSound3D ( vehiclesSounds[model].gear, x, y, z, false )
            setSoundVolume(gearSound, 2)
            attachElements ( gearSound, vehicle )
        end
    end
end

function getVehicleRPM(vehicle) 
    if isElement(vehicle) then  
        local vehicleRPM = getElementData ( vehicle, "rpm" ) or 0
        if (isVehicleOnGround(vehicle)) then     
            if (getVehicleEngineState(vehicle) == true) then
                if(getVehicleCurrentGear(vehicle) > 0) then
                    vehicleRPM = math.floor(((getVehicleSpeed(vehicle)/getVehicleCurrentGear(vehicle))*180) + 0.99)
                    
                    if (vehicleRPM < 650) then
                        vehicleRPM = math.random(650, 750)
                    elseif (vehicleRPM >= 9800) then
                        vehicleRPM = 9800
                    end
                else
                    vehicleRPM = math.floor(((getVehicleSpeed(vehicle)/1)*180) + 0.99)
                    
                    if (vehicleRPM < 650) then
                        vehicleRPM = math.random(650, 750)
                    elseif (vehicleRPM >= 9800) then
                        vehicleRPM = 9800
                    end
                end
            else
                vehicleRPM = 0
            end
        else
            if (getVehicleEngineState(vehicle) == true) then
                vehicleRPM = vehicleRPM - 0
                    
                if (vehicleRPM < 650) then
                    vehicleRPM = math.random(650, 750)
                elseif (vehicleRPM >= 9800) then
                    vehicleRPM = 9800
                end
            else
                vehicleRPM = 0
            end
        end
        setElementData ( vehicle, "rpm", vehicleRPM, false )
        return tonumber(vehicleRPM)
    else
        return 0
    end
end

function getVehicleSpeed(vehicle)   
    if isElement(vehicle) then
        local vx, vy, vz = getElementVelocity(vehicle)
        
        if (vx) and (vy)and (vz) then
            return math.sqrt(vx^2 + vy^2 + vz^2) * 180 -- km/h
        else
            return 0
        end
    else
        return 0
    end
end
correct this script need to repair the MTA on volume SFX Volume plizzz help me

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...