maxpayne394 Posted September 16, 2023 Share Posted September 16, 2023 Hello guys. First of all, I don't know anything about scripting, I just copied the codes from wiki and other scripts. I was trying to play an mp3 file in Jizzy's Club, and I did it somehow, music is playing when I enter the club but when I reconnect to the server the mp3 file plays from beginning. I haven't tried with someone else but I guess it isn't synchronized with other players. It is a 20 minutes long mix of songs so I want to be sure that everyone hears the same music at the same time. I read some topics about playsound3d and synchronization however I couldn't figured it out how to do that. Can you help me guys? This is the code. I guess I need a server side script. addEventHandler('onClientResourceStart', resourceRoot, function() local sound = playSound3D("Dj_Ivan.mp3", -2677, 1411, 908, true) setSoundMaxDistance(sound, 100) setSoundVolume(sound, 4) end ) function disableClubMusic() if getElementInterior(localPlayer) == 3 and getDistanceBetweenPoints3D(-2677, 1411, 908, getElementPosition(localPlayer)) < 50 and getInteriorSoundsEnabled() then setInteriorSoundsEnabled(false) elseif not getInteriorSoundsEnabled() then setInteriorSoundsEnabled(true) end end addEventHandler("onClientPreRender", root, disableClubMusic) Link to comment
FLUSHBICEPS Posted September 16, 2023 Share Posted September 16, 2023 --server side local startTime = getTickCount() addEvent("requestMusicPosition", true) addEventHandler("requestMusicPosition", root, function() local elapsedTime = getTickCount() - startTime local soundDuration = 20 * 60 * 1000 local playbackPosition = elapsedTime % soundDuration triggerClientEvent(client, "playClubMusic", client, playbackPosition) end ) --clientside addEventHandler('onClientResourceStart', resourceRoot, function() triggerServerEvent("requestMusicPosition", localPlayer) end ) addEvent("playClubMusic", true) addEventHandler("playClubMusic", root, function(playbackPosition) local sound = playSound3D("Dj_Ivan.mp3", -2677, 1411, 908, true) setSoundMaxDistance(sound, 100) setSoundVolume(sound, 4) setSoundPosition(sound, playbackPosition / 1000) end ) This setup ensures that when a player enters the club, they hear the music from the same position as everyone else Link to comment
maxpayne394 Posted September 16, 2023 Author Share Posted September 16, 2023 1 hour ago, FLUSHBICEPS said: --server side local startTime = getTickCount() addEvent("requestMusicPosition", true) addEventHandler("requestMusicPosition", root, function() local elapsedTime = getTickCount() - startTime local soundDuration = 20 * 60 * 1000 local playbackPosition = elapsedTime % soundDuration triggerClientEvent(client, "playClubMusic", client, playbackPosition) end ) --clientside addEventHandler('onClientResourceStart', resourceRoot, function() triggerServerEvent("requestMusicPosition", localPlayer) end ) addEvent("playClubMusic", true) addEventHandler("playClubMusic", root, function(playbackPosition) local sound = playSound3D("Dj_Ivan.mp3", -2677, 1411, 908, true) setSoundMaxDistance(sound, 100) setSoundVolume(sound, 4) setSoundPosition(sound, playbackPosition / 1000) end ) This setup ensures that when a player enters the club, they hear the music from the same position as everyone else Thank you very much 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