Jump to content

Sound script not working


Xwad

Recommended Posts

Hi i made a script that makes possible that when i press w then the audio will start and if i stop pressing w then the audio will stop. Its not working help

client.lua

  
local sound 
  
function startSound ()  
    sound = playSound("sounds/sound.mp3")  
    setSoundVolume(sound, 1)  
end 
  
  
function stopSound() 
    if isElement(sound) then 
        stopSound(sound) 
    end 
end 
  
  
function bindTheKeys () 
  bindKey ( "w", "down", startSound )   
  bindKey ( "w", "up", stopSound )      
end 
  
  
  

Link to comment
local sound 
local stopSound = stopSound_ 
  
function startSound () 
    sound = playSound("sounds/sound.mp3") 
    setSoundVolume(sound, 1) 
end 
  
function stopSound() 
    if isElement(sound) then 
        stopSound(sound) 
    end 
end 
bindKey ( "w", "down", startSound )   
bindKey ( "w", "up", stopSound ) 

Link to comment

or is this good?

  
function switchEngine ( playerSource ) 
    local theVehicle = getPedOccupiedVehicle ( playerSource ) 
  
    -- Check if the player is in any vehicle and if he is the driver 
    if theVehicle and getVehicleController ( theVehicle ) == playerSource then 
        local state = getVehicleEngineState ( theVehicle ) 
        if setVehicleEngineState ( theVehicle, not state ) then 
        triggerClientEvent ( playerSource, "stop_Sound" ) 
        else 
        cancelEvent () 
    end 
end 
  

Link to comment

Music plays when vehicle is moving:

local sound 
setTimer(function() 
    local vehicle = getPedOccupiedVehicle(localPlayer) 
    if vehicle then 
        local vx,vy,vz = getElementVelocity(vehicle) 
        if vx+vy+vz == 0 then 
            if sound then 
                  setSoundPaused(sound,true) 
            end 
        else 
            if not sound then 
                sound = playSound("sounds/sound.mp3") 
                        else 
                                setSoundPaused(sound,false) 
            end 
        end 
    elseif sound then 
        setSoundPaused(sound,true) 
    end 
end,1000,0) 

Link to comment

One more question . I want to make that when the player die then the music stops so i added this to the script but its not working

  
function stopSound() 
setSoundPaused(sound,false) 
end 
addEventHandler("onClientPlayerWasted", root, stopSound) 
  

Link to comment

last last last question xD i wanted to make that when i drive the rustler then the sound will not start but its not working xD

i added this to the script

  
function Plane_sound() 
if getElementModel(source) == 476 then  
setSoundPaused(sound,true) 
end 
end 
  

Link to comment
local sound 
setTimer(function() 
    local vehicle = getPedOccupiedVehicle(localPlayer) 
    if vehicle then 
        local vx,vy,vz = getElementVelocity(vehicle) 
        if vx+vy+vz == 0 then 
            if sound then 
                  setSoundPaused(sound,true) 
            end 
        else 
            if not sound then 
                sound = playSound("sounds/sound.mp3") 
                setSoundVolume(sound, 0.1) 
                        else 
                                setSoundPaused(sound,false) 
            end 
        end 
    elseif sound then 
        setSoundPaused(sound,true) 
    end 
end,1000,0) 
  
function stopSound() 
setSoundPaused(sound, true) 
end 
addEventHandler("onClientPlayerWasted", root, stopSound) 
  
  
function Plane_sound() 
if getElementModel(source) == 476 then  
setSoundPaused(sound,true) 
end 
end 
addEventHandler("onClientVehicleEnter", root, Plane_sound) 

Link to comment
local sound 
setTimer(function() 
    local vehicle = getPedOccupiedVehicle(localPlayer) 
    if vehicle and getElementModel(vehicle) ~= 476 then 
        local vx,vy,vz = getElementVelocity(vehicle) 
        if vx+vy+vz == 0 then 
            if sound then 
                  setSoundPaused(sound,true) 
            end 
        else 
            if not sound then 
                sound = playSound("sounds/sound.mp3") 
                setSoundVolume(sound, 0.1) 
                        else 
                                setSoundPaused(sound,false) 
            end 
        end 
    elseif sound then 
        setSoundPaused(sound,true) 
    end 
end,1000,0) 
  
function stopSound() 
setSoundPaused(sound, true) 
end 
addEventHandler("onClientPlayerWasted", root, stopSound) 

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