Jump to content

Sound script not working


Xwad

Recommended Posts

Posted

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 
  
  
  

Posted
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 ) 

Posted

ok now its working thx but i have found another problem. When i stop pressing w and the vehicle is still mooving then the music stops.. How can i make that the sound will only stopps when the vehicle stops?

Posted

there is just server side example:/ can you make a client sided example pls? whats the different? or should i make it with triggerclientevent?

Posted

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 
  

Posted

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) 

Posted

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) 
  

Posted

Why double post? No wonder you have 1k posts.

function destroySound() 
     stopSound(sound) 
end 
addEventHandler("onClientPlayerWasted", root, destroySound) 

Posted

i tryed that but its not working:/ I aléways fixed the debugscripts but not working:/ only for that spawn script. So i made this topic for the vehicle sound

Posted
@Xwad, reported

Stop to multiply topics now :x

It's not multiplied, it's based on totally different script. Can you check the discussion before replying to the topic? And reported for what?

Posted

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 
  

Posted
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) 

Posted
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) 

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