Jump to content

Gear Sound


JesusOkay

Recommended Posts

I need to make the sound sound once, and not repeat in a loop , sound for gear , the problem is why this is bucle

 

 

_______________________________________________________________________________________________-


g_player = getLocalPlayer()
g_root = getRootElement()

function CurrentGear()
    g_vehicle = getPedOccupiedVehicle(g_player)
    if g_vehicle then
        
        gear = getVehicleCurrentGear(g_vehicle)
        if (gear == 2) then
            local sound = playSound("sounds/bov.wav",false)
            setSoundVolume(sound, 0.5)
            
        end
        
    else
        return
    end
end
addEventHandler("onClientRender",g_root,CurrentGear)

Edited by JesusOkay
Link to comment
  • Moderators

First of all, read this before your next post: https://forum.multitheftauto.com/topic/94790-guidelines-and-formatting-for-this-section-read-before-posting/

 

 

onClientRender triggered ~60 times in a second, so play the sound ~60 times as long as the gear doesn't change.

You need to limit it.

 

g_player = getLocalPlayer()
g_root = getRootElement()

local alreadyPlayed = false

function CurrentGear()
    local g_vehicle = getPedOccupiedVehicle(g_player)
    
    if g_vehicle then
        local gear = getVehicleCurrentGear(g_vehicle)
        
        if (gear == 2) then
            if (alreadyPlayed == false) then -- play sound if we haven't played it yet
                local sound = playSound("sounds/bov.wav",false)
                setSoundVolume(sound, 0.5)
                alreadyPlayed = true -- remember, we already played it
            end
        else
            alreadyPlayed = false -- reset alreadyPlayed, when gear not 2
        end
    end
end
addEventHandler("onClientRender",g_root,CurrentGear)

 

Edited by stPatrick
Link to comment

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...