Xwad Posted April 17, 2016 Share Posted April 17, 2016 Hi! I have a lot of problems with sync. So what im trying to do is adding playSOund3D to a vehicle. The problem is that it's not synced with other players so they can't hear the sound, only the player can hear it who enters the car. So i know that serverside i needless for sync so its possible to sync it in client side, but i dont know how.. Please help! code: function start_sound() local veh = getPedOccupiedVehicle(localPlayer) if getElementModel(veh) == 480 then setTimer ( function () if not isElement(sound_move) then sound_move = playSound3D("files/tank_move.wav",0,0,0, true) setSoundMaxDistance(sound_move, 40) setSoundVolume(sound_move, 0.6) attachElements(sound_move, veh) end end, 200, 1 ) if not isElement(sound_track) then sound_track = playSound3D("files/tracks.wav",0,0,0, true) setSoundMaxDistance(sound_track, 40) setSoundVolume(sound_track, 0.-- s8) --> attachElements(sound_track, veh) sound_start = playSound3D("files/start.wav",0,0,0, false) setSoundMaxDistance(sound_start, 40) setSoundVolume(sound_start, 0.5) attachElements(sound_start, veh) setTimer ( function () addEventHandler("onClientRender", root, stop_sound) end, 50, 1 ) end end end function stop_sound() local veh = getPedOccupiedVehicle(localPlayer) local id = getElementModel ( veh ) if id == 480 then local vx,vy,vz = getElementVelocity(veh) if vx+vy+vz == 0 then if isElement(sound_track) then stopSound(sound_track) removeEventHandler("onClientRender", root, stop_sound) end if isElement(sound_move) then stopSound(sound_move) removeEventHandler("onClientRender", root, stop_sound) end end end end function stop_sound2() local veh = getPedOccupiedVehicle(localPlayer) local id = getElementModel ( veh ) if id == 480 then if isElement(sound_move) then stopSound(sound_move) end end end function bindTheKeys (thePlayer, seat) bindKey ( "w", "down", start_sound ) bindKey ( "s", "down", start_sound ) bindKey ( "w", "up", stop_sound2 ) bindKey ( "s", "up", stop_sound2 ) end addEventHandler("onClientVehicleEnter", root, bindTheKeys) Link to comment
aka Blue Posted April 17, 2016 Share Posted April 17, 2016 Client = Only the client can hear the Music. Server = Everybody can hear the Music. Link to comment
Xwad Posted April 17, 2016 Author Share Posted April 17, 2016 Are you sure? Take a look at this code. Its client sided and i tested it and other players can hear it. There are 'thePlayer' argumentums local sounds = {} addEventHandler("onClientVehicleEnter", root, function(thePlayer, seat) if seat ~= 0 then return end local vehicle = getPedOccupiedVehicle(thePlayer) if getElementModel(vehicle) == 480 then sounds[thePlayer] = playSound3D("files/engine.wav",0,0,0, true) setSoundMaxDistance(sounds[thePlayer], 50) setSoundVolume(sounds[thePlayer], 1) attachElements(sounds[thePlayer], vehicle) end end) addEventHandler("onClientVehicleExit", root, function(thePlayer, seat) if isElement(sounds[thePlayer]) then stopSound(sounds[thePlayer].sound) end end) Link to comment
Fist Posted April 17, 2016 Share Posted April 17, 2016 (edited) nvm Edited April 17, 2016 by Guest Link to comment
aka Blue Posted April 17, 2016 Share Posted April 17, 2016 Creates a sound element in the GTA world and plays it immediately after creation for the local player. setElementPosition can be used to move the sound element around after it has been created. Remember to use setElementDimension after creating the sound to play it outside of dimension 0. Link to comment
Simple0x47 Posted April 17, 2016 Share Posted April 17, 2016 How I told you previously, use getDistanceBetweenPoints3D Link to comment
Xwad Posted April 18, 2016 Author Share Posted April 18, 2016 ok i have sync it now but i have a few bugs: when i enter a vehicle and hold w then the engine sound is starting but when another player stops pressing w then the sound is stopping in all vehicles.. How can i fix that? CLIENT function start_sound () local veh = getPedOccupiedVehicle(localPlayer) if getElementModel(veh) == 480 then triggerServerEvent("start_sound", resourceRoot, veh ) end end function start_sound_client(veh) setTimer ( function () if not isElement(sound_move) then sound_move = playSound3D("files/tank_move.wav",0,0,0, true) setSoundMaxDistance(sound_move, 40) setSoundVolume(sound_move, 0.60) attachElements(sound_move, veh) end end, 200, 1 ) if not isElement(sound_track) then sound_track = playSound3D("files/tracks.wav",0,0,0, true) setSoundMaxDistance(sound_track, 40) setSoundVolume(sound_track, 0.76) attachElements(sound_track, veh) setElementData(localPlayer,"sound_track", sound_track) sound_start = playSound3D("files/start.wav",0,0,0, false) setSoundMaxDistance(sound_start, 40) setSoundVolume(sound_start, 0.5) attachElements(sound_start, veh) setTimer ( function () addEventHandler("onClientRender", root, stop_sound) end, 50, 1 ) end end addEvent("start_sound", true) addEventHandler("start_sound", root, start_sound_client) function stop_sound () local veh = getPedOccupiedVehicle(localPlayer) if getElementModel(veh) == 480 then triggerServerEvent("stop_sound", resourceRoot, veh ) end end function stop_sound_client(veh) local vx,vy,vz = getElementVelocity(veh) if vx+vy+vz == 0 then if isElement(sound_track) then stopSound(sound_track) removeEventHandler("onClientRender", root, stop_sound) end if isElement(sound_move) then stopSound(sound_move) removeEventHandler("onClientRender", root, stop_sound) end end end addEvent("stop_sound", true) addEventHandler("stop_sound", root, stop_sound_client) function stop_sound2 () local veh = getPedOccupiedVehicle(localPlayer) if getElementModel(veh) == 480 then triggerServerEvent("stop_sound2", resourceRoot, veh ) end end function stop_sound_client2(veh) if isElement(sound_move) then stopSound(sound_move) end end addEvent("stop_sound2", true) addEventHandler("stop_sound2", root, stop_sound_client2) function bindTheKeys () bindKey ( "w", "down", start_sound ) bindKey ( "s", "down", start_sound ) bindKey ( "w", "up", stop_sound2 ) bindKey ( "s", "up", stop_sound2 ) end addEventHandler("onClientVehicleEnter", root, bindTheKeys) SERVER function start_sound(veh) triggerClientEvent("start_sound", resourceRoot, veh) end addEvent("start_sound", true) addEventHandler("start_sound", resourceRoot, start_sound) function stop_sound(veh) triggerClientEvent("stop_sound", resourceRoot, veh) end addEvent("stop_sound", true) addEventHandler("stop_sound", resourceRoot, stop_sound) function stop_sound2(veh) triggerClientEvent("stop_sound2", resourceRoot, veh) end addEvent("stop_sound2", true) addEventHandler("stop_sound2", resourceRoot, stop_sound2) [/lua] Link to comment
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