barnik Posted March 27, 2022 Share Posted March 27, 2022 Hello everyone, I have a problem. When music is played (random), it is played to all users, but different, how to make it so that it is not different? Client.lua tablerand = { [1] = "soundsMM/1.mp3", [2] = "soundsMM/2.mp3", [3] = "soundsMM/3.mp3", [4] = "soundsMM/4.mp3", [5] = "soundsMM/5.mp3", [6] = "soundsMM/6.mp3", [7] = "soundsMM/7.mp3", [8] = "soundsMM/8.mp3", [9] = "soundsMM/9.mp3", [10] = "soundsMM/10.mp3", [11] = "soundsMM/11.mp3", [12] = "soundsMM/12.mp3", } resourceRoot = getResourceRootElement() addEvent("playSoundRound",true) addEventHandler("playSoundRound",resourceRoot, function () local RandTable = (tablerand[math.random(1,#tablerand)]) sound = playSound(RandTable,false) end) function SayChatik () local meta = getSoundMetaTags(sound) local art = 'Артист: ' local tag = '[Legends]' outputChatBox("[Legends] Artist(s) or track: "..meta.artist.." "..xuesosina1.."") end addEventHandler("onClientMapStopping",resourceRoot,SayChatik) server.lua function musicround(player) resourceRoot = getResourceRootElement() triggerClientEvent(root,"playSoundRound",resourceRoot) end addEventHandler ("onRoundFinish", root, musicround) Link to comment
Spakye Posted March 28, 2022 Share Posted March 28, 2022 Hello, use math.random(1, 12) on server side and pass the result to all clients through your event. You can then play then use playSound(tablerand[result]) 1 1 Link to comment
Ayush Rathore Posted March 28, 2022 Share Posted March 28, 2022 (edited) Client side local sounds = { [1] = "soundsMM/1.mp3", [2] = "soundsMM/2.mp3", [3] = "soundsMM/3.mp3", [4] = "soundsMM/4.mp3", [5] = "soundsMM/5.mp3", [6] = "soundsMM/6.mp3", [7] = "soundsMM/7.mp3", [8] = "soundsMM/8.mp3", [9] = "soundsMM/9.mp3", [10] = "soundsMM/10.mp3", [11] = "soundsMM/11.mp3", [12] = "soundsMM/12.mp3" }; local resourceRoot = getResourceRootElement(); local sound = nil addEvent("playSoundRound", true); addEventHandler("playSoundRound", resourceRoot, function(id) sound = playSound(sounds[id], false); end); function SayChatik() local meta = getSoundMetaTags(sound); local art = "Артист: "; local tag = "[Legends]"; outputChatBox("[Legends] Artist(s) or track: " .. meta.artist .. " " .. xuesosina1 .. ""); end; addEventHandler("onClientMapStopping", resourceRoot, SayChatik); Server Side local totalSounds = 12 -- change it when you change sound table in client side local resourceRoot = getResourceRootElement() function musicround() triggerClientEvent(root,"playSoundRound",resourceRoot,math.random(1,totalSounds)) end addEventHandler ("onRoundFinish", root, musicround) This will do the needful! Edited March 28, 2022 by Ayush Rathore 1 1 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