Jump to content

[HELP] Change the horn sound


QoRaY

Recommended Posts

function playMySound() 
local x, y, z = getElementPosition(localPlayer) 
local sound = playSound3D ("horn.wav", x, y, z) 
end 
  
function stopMySound() 
local soundoff = stopSound(sound) 
end 
  
function bindTheKeys() 
unbindKey("h") 
bindKey("h", "down", playMySound) 
bindKey("h", "up", stopMySound) 

UNTESTED! And we don't do codes but we help only, I just did for you to learn

Link to comment
function playMySound() 
local x, y, z = getElementPosition(localPlayer) 
local sound = playSound3D ("horn.wav", x, y, z) 
end 
  
function stopMySound() 
local soundoff = stopSound(sound) 
end 
  
function bindTheKeys() 
unbindKey("h") 
bindKey("h", "down", playMySound) 
bindKey("h", "up", stopMySound) 

UNTESTED! And we don't do codes but we help only, I just did for you to learn

Wrong!

Link to comment
function playMySound() 
local x, y, z = getElementPosition(localPlayer) 
local sound = playSound3D ("horn.wav", x, y, z) 
end 
  
function stopMySound() 
local soundoff = stopSound(sound) 
end 
  
function bindTheKeys() 
unbindKey("h") 
bindKey("h", "down", playMySound) 
bindKey("h", "up", stopMySound) 
end 

((missed out 'end' ))

Link to comment
function bindHoron( key, keyState ) 
    if isPedInVehicle( localPlayer ) then 
        if ( keyState == 'down' ) then 
            sound = playSound3D( 'horn.wav', getElementPosition( localPlayer ) ) 
            attachElements( sound, getPedOccupiedVehicle( localPlayer ) ) 
        elseif ( keyState == 'up' ) then 
            if isElement( sound ) then  
                stopSound( sound )  
            end 
        end 
    end 
end 
bindKey( 'h', 'down', bindHoron ) 
bindKey( 'h', 'up', bindHoron ) 

And you need disabled the control horn:

toggleControl( 'horn', false ) 

Link to comment
trigger it to server side and back
    
      
        

Just in case, i think he means this

How can there be a client script as type: server? I think he means: triggerServerEvent

On the other hand, wouldn't binding a new sound collide with the existing GTA sounds?

Link to comment
trigger it to server side and back
    
      
        

Just in case, i think he means this

How can there be a client script as type: server? I think he means: triggerServerEvent

On the other hand, wouldn't binding a new sound collide with the existing GTA sounds?

He disabled horn control.

Link to comment
  • 1 month later...
  • 3 years later...

There was no problems with this script...

function playMySound()

local x, y, z = getElementPosition(localPlayer)

local sound = playSound3D ("horn.wav", x, y, z)

end

function stopMySound()

local soundoff = stopSound(sound)

end

function bindTheKeys()

unbindKey("h")

bindKey("h", "down", playMySound)

bindKey("h", "up", stopMySound)

end

addEventHandler("onClientResourceStart", resourceRoot, bindTheKeys)

You just missed the EventHandler.

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