Xwad Posted June 12, 2016 Share Posted June 12, 2016 only the local player can hear it ( the player in the vehicle) , other players cant hear the sound.. Thanks in advance! server function start_sound() outputChatBox("triggerClientEvent") triggerClientEvent(getRootElement(), "start_sound", getRootElement()) end function bindTheKeys (thePlayer, seat, jacked) if (getElementModel (source) == 480) then bindKey (thePlayer, "w", "down", start_sound) outputChatBox("onVehicleEnter") end end addEventHandler ("onVehicleEnter", getRootElement(), bindTheKeys) client function start_sound() local vehicle = getPedOccupiedVehicle(localPlayer) local x,y,z = getElementPosition(vehicle) if not isElement(sound_track) then sound_start = playSound3D("files/start.wav",x,y,z, false) setSoundMaxDistance( sound_start, 40 ) setSoundVolume(sound_start, 0.-- s8) --> attachElements ( sound_start, vehicle, 0,0,0 ) sound_track = playSound3D("files/tracks.wav",x,y,z, true) setSoundMaxDistance( sound_track, 40 ) setSoundVolume(sound_track, 0.5) attachElements ( sound_track, vehicle, 0,0,0 ) if not isElement(sound_move) then sound_move = playSound3D("files/tank_move.wav",x,y,z, true) setSoundMaxDistance( sound_move, 40 ) setSoundVolume(sound_move, 0.5) attachElements ( sound_move, vehicle, 0,0,0 ) setTimer ( function () addEventHandler("onClientRender", root, stop_sound2) end, 50, 1 ) end end end addEvent("start_sound",true) addEventHandler("start_sound", getRootElement(), start_sound) Link to comment
Bean666 Posted June 12, 2016 Share Posted June 12, 2016 not tested try(but i will think this will play to all players through the map), anyways just try. function start_sound() outputChatBox("triggerClientEvent") for _, player in ipairs(getElementsByType("player")) do triggerClientEvent(getRootElement(), "start_sound", getRootElement()) end end Link to comment
Bean666 Posted June 12, 2016 Share Posted June 12, 2016 try changing getrootelement to player Link to comment
Xwad Posted June 12, 2016 Author Share Posted June 12, 2016 like this? function start_sound() outputChatBox("triggerClientEvent") for _, player in ipairs(getElementsByType("player")) do triggerClientEvent(player, "start_sound", player) end end Link to comment
Xwad Posted June 12, 2016 Author Share Posted June 12, 2016 still not working:// Maybe i have to bind the key in client side and trigger to server and after then trigger again to client? Link to comment
Bean666 Posted June 12, 2016 Share Posted June 12, 2016 why not use onClientVehicleEnter? Link to comment
Tomas Posted June 12, 2016 Share Posted June 12, 2016 still not working:// Maybe i have to bind the key in client side and trigger to server and after then trigger again to client? function start_sound(keyPresser) triggerClientEvent(root, "start_sound", root, keyPresser) end function bindTheKeys (thePlayer, seat, jacked) if (getElementModel (source) == 480) then bindKey (thePlayer, "w", "down", start_sound) end end addEventHandler ("onVehicleEnter", getRootElement(), bindTheKeys) function start_sound (player) local vehicle = getPedOccupiedVehicle(player) local x,y,z = getElementPosition(vehicle) if not isElement(sound_track) then sound_start = playSound3D("files/start.wav",x,y,z, false) setSoundMaxDistance( sound_start, 40 ) --[[setSoundVolume(sound_start, 0.]] attachElements ( sound_start, vehicle, 0,0,0 ) sound_track = playSound3D("files/tracks.wav",x,y,z, true) setSoundMaxDistance( sound_track, 40 ) setSoundVolume(sound_track, 0.5) attachElements ( sound_track, vehicle, 0,0,0 ) if not isElement(sound_move) then sound_move = playSound3D("files/tank_move.wav",x,y,z, true) setSoundMaxDistance( sound_move, 40 ) setSoundVolume(sound_move, 0.5) attachElements ( sound_move, vehicle, 0,0,0 ) setTimer ( function () addEventHandler("onClientRender", root, stop_sound2) end, 50, 1 ) end end end addEvent("start_sound",true) addEventHandler("start_sound", getRootElement(), start_sound) Link to comment
Xwad Posted June 12, 2016 Author Share Posted June 12, 2016 yeah its working now! Thanks guys:) Link to comment
Xwad Posted June 12, 2016 Author Share Posted June 12, 2016 I have a new problem!! i added a sound stop function to the script. The problem with it is that the sound stop function is executing for all players:/ so when a player stops pressing w then the sound will stop on all players vehicle:/ I hope you can help me:/ server function start_sound(keyPresser) triggerClientEvent(root, "start_sound", root, keyPresser) end function stop_sound(keyPresser) triggerClientEvent(root, "stop_sound", root, keyPresser) end function bindTheKeys (thePlayer, seat, jacked) if (getElementModel (source) == 480) then bindKey (thePlayer, "w", "down", start_sound) bindKey (thePlayer, "w", "up", stop_sound) end end addEventHandler ("onVehicleEnter", getRootElement(), bindTheKeys) client function start_sound(player) local vehicle = getPedOccupiedVehicle(player) local x,y,z = getElementPosition(vehicle) if not isElement(sound_track) then sound_start = playSound3D("files/start.wav",x,y,z, false) setSoundMaxDistance( sound_start, 40 ) attachElements ( sound_start, vehicle, 0,0,0 ) sound_track = playSound3D("files/tracks.wav",x,y,z, true) setSoundMaxDistance( sound_track, 40 ) setSoundVolume(sound_track, 0.5) attachElements ( sound_track, vehicle, 0,0,0 ) if not isElement(sound_move) then sound_move = playSound3D("files/tank_move.wav",x,y,z, true) setSoundMaxDistance( sound_move, 40 ) setSoundVolume(sound_move, 0.5) attachElements ( sound_move, vehicle, 0,0,0 ) setTimer ( function () addEventHandler("onClientRender", root, stop_sound2) end, 50, 1 ) end end end addEvent("start_sound",true) addEventHandler("start_sound", getRootElement(), start_sound) function stop_sound(player) local vehicle = getPedOccupiedVehicle(player) if isElement(sound_move) then stopSound(sound_move) outputChatBox("sound_move stopped",200,0,0) end end addEvent("stop_sound",true) addEventHandler("stop_sound", getRootElement(), stop_sound) function stop_sound2() if isPedInVehicle ( localPlayer ) then local vehicle = getPedOccupiedVehicle(localPlayer) local vx,vy,vz = getElementVelocity(vehicle) local id = getElementModel ( vehicle ) if id == 480 then if vx+vy+vz == 0 then if isElement(sound_track) then outputChatBox("sound_track stopped",200,0,0) stopSound(sound_track) removeEventHandler("onClientRender", root, stop_sound2) end end end end end Link to comment
Captain Cody Posted June 12, 2016 Share Posted June 12, 2016 Make the stop command handler client sided. Link to comment
Xwad Posted June 12, 2016 Author Share Posted June 12, 2016 i already tried that. But i think the problem is becaouse the playSound3D does not have local. is this possible? Maybe i have to use setElementData? Link to comment
Bean666 Posted June 12, 2016 Share Posted June 12, 2016 i think you need to define the localPlayer maybe use if (player == localPlayer) then might work. but i think localPlayer is already defined in MTA. so maybe u wont need that. and just change player to localPlayer. Link to comment
Xwad Posted June 13, 2016 Author Share Posted June 13, 2016 Yeah its working now! Thx again!! Link to comment
Xwad Posted June 13, 2016 Author Share Posted June 13, 2016 I thought its working but it isnt:( So this script makes possible when a player starts pressing W in a vehicle (id:480) then a sound will be attached to the players vehicle! now i got a really strange bug.. the bug is: player 1 starts pressing W (in the vehicle 480) and after that, player 2 also starts pressing W (in the vehicle 480). When player 1 stops pressing W then the sound will not stop in his vehicle, it will only stop on players 2 vehicle!! And the same happens on the contrary!!! Please help! I am trying to fix that bug sice 3 hours!! Here is the code: Thanks in advance! CLIENT function start_sound(player) local vehicle = getPedOccupiedVehicle(player) local x,y,z = getElementPosition(vehicle) if not isElement(sound_move) then local sound_move = playSound3D("files/tank_move.wav",x,y,z, true) setSoundMaxDistance( sound_move, 40 ) setSoundVolume(sound_move, 0.5) attachElements ( sound_move, vehicle, 0,0,0 ) setElementData(localPlayer, "sound_move", sound_move) end end end addEvent("start_sound",true) addEventHandler("start_sound", getRootElement(), start_sound) function stop_sound() local sound_move = getElementData(localPlayer, "sound_move") if isElement(sound_move) then stopSound(sound_move) outputChatBox("sound_move stopped",200,0,0) end end addEvent("stop_sound",true) addEventHandler("stop_sound", getRootElement(), stop_sound) function stop_client() triggerServerEvent("stop_sound", root, localPlayer) end function bindTheKeys (thePlayer, seat) local vehicle = getPedOccupiedVehicle(localPlayer) local id = getElementModel ( vehicle ) if id == 480 then bindKey ("w", "up", stop_client) bindKey ("mouse1", "down", projectile) end end addEventHandler("onClientVehicleEnter", getRootElement(), bindTheKeys) SERVER function start_sound(keyPresser) triggerClientEvent(root, "start_sound", root, keyPresser) end function bindTheKeys (thePlayer, seat, jacked) if (getElementModel (source) == 480) then bindKey (thePlayer, "w", "down", start_sound) end end addEventHandler ("onVehicleEnter", getRootElement(), bindTheKeys) function stop_sound () triggerClientEvent("stop_sound", getRootElement()) end addEvent( "stop_sound", true ) addEventHandler( "stop_sound", resourceRoot, stop_sound ) 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