Everything works, thanks a lot. But I, the idiot, forgot to say more: it is necessary that this sound is heard by the nearest player near the one who reproduced the sound.
I tried to do the following:
Created a script say1_s.lua (server):
function say1Command ( playerSource, commandName )
triggerClientEvent ( "onSay1", root)
end
addCommandHandler ( "say1", say1Command )
and created a script say1_c.lua (client):
local sound
function onSay1()
if isElement(sound) then
stopSound (sound)
end
local x, y, z = getElementPosition(localPlayer)
sound = playSound3D('say1.mp3',x,y,z)
setSoundMaxDistance(sound, 25)
end
addEventHandler("onClientRender", root,
function ()
if isElement(sound) then
local x,y,z = getElementPosition(localPlayer)
setElementPosition (sound, x, y, z)
end
end)
addEvent("onSay1",true)
addEventHandler("onSay1",localPlayer,say1)
But when the player enters /say1 the sound is heard from all the players of the server, regardless of the distance. How to fix this?