Xwad Posted July 28, 2015 Posted July 28, 2015 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
Buffalo Posted July 28, 2015 Posted July 28, 2015 Rename your function stopSound! You must use other names than MTA function names like my_stopSound
Miika Posted July 28, 2015 Posted July 28, 2015 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 )
Xwad Posted July 28, 2015 Author Posted July 28, 2015 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?
Xwad Posted July 28, 2015 Author Posted July 28, 2015 there is just server side example:/ can you make a client sided example pls? whats the different? or should i make it with triggerclientevent?
Xwad Posted July 28, 2015 Author Posted July 28, 2015 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
Buffalo Posted July 28, 2015 Posted July 28, 2015 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)
Xwad Posted July 28, 2015 Author Posted July 28, 2015 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)
TheSmart Posted July 28, 2015 Posted July 28, 2015 try now function stopSound() setSoundPaused(sound, true) end addEventHandler("onClientPlayerWasted", root, stopSound)
#RooTs Posted July 28, 2015 Posted July 28, 2015 man, I've already helped you with this issue. still need help? oh god. not is possible
GTX Posted July 28, 2015 Posted July 28, 2015 Why double post? No wonder you have 1k posts. function destroySound() stopSound(sound) end addEventHandler("onClientPlayerWasted", root, destroySound)
Xwad Posted July 28, 2015 Author Posted July 28, 2015 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
Xwad Posted July 28, 2015 Author Posted July 28, 2015 Thanks TheSmart now its working:D i just forget to change false to true..
TheSmart Posted July 28, 2015 Posted July 28, 2015 Thanks TheSmart now its working:D i just forget to change false to true.. You're Welcome
GTX Posted July 28, 2015 Posted July 28, 2015 @Xwad, reportedStop to multiply topics now 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?
Xwad Posted July 28, 2015 Author Posted July 28, 2015 last last last question i wanted to make that when i drive the rustler then the sound will not start but its not working i added this to the script function Plane_sound() if getElementModel(source) == 476 then setSoundPaused(sound,true) end end
Xwad Posted July 28, 2015 Author Posted July 28, 2015 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)
GTX Posted July 28, 2015 Posted July 28, 2015 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)
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now