Jump to content

help PlaySound


barnik

Recommended Posts

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

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 by Ayush Rathore
  • Like 1
  • Haha 1
Link to comment

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...