Lukkas2201 Posted March 14, 2020 Posted March 14, 2020 Boa noite, fiz um pequeno script simples, onde ao digitar um comando o player faz uma animação e surge um som, porém ao invés do som sair só para o player que digitou o comando, sai para todos do servidor, e não é só pra quem está perto, mas se um cara estiver em LS, e o outro em SF, consegue escutar também, oque pode ter de errado? Server addCommandHandler("coco",function(source) local x,y,z = getElementPosition(source) coco = createObject(14810,x,y-0.1,z-0.8,0,0,rotation) setTimer(destroyElement,900000,1,coco) triggerClientEvent("somcoco",getRootElement()) setPedAnimation( source, "ped", "WEAPON_crouch", -1, false,false,nil,false ) end) addCommandHandler("tomacachaca",function(source) setPedAnimation( source, "VENDING", "VEND_Drink2_P", -1,false,false,nil,false ) triggerClientEvent("somcachaca",getRootElement()) end) Client addEvent("somcoco",true) addEventHandler("somcoco",getRootElement(),function() playSound("Sounds/PUM"..math.random(1,7)..".mp3") end) addEvent("somcachaca",true) addEventHandler("somcachaca",getRootElement(),function() playSound("Sounds/cachaca"..math.random(1,4)..".mp3") end)
_Ace Posted March 14, 2020 Posted March 14, 2020 ta saindo o som para todos pq o evento ta especificado pra disparar em todos os clients (players), se for pra quem usou o som, e mais quem estiver por perto, deixe o evento como ta mas use o playSound3d https://wiki.multitheftauto.com/wiki/PlaySound3d especificando as coordenadas do player (que ta emitindo o som), dai ajusta a distancia que pode ser ouvido com setSoundMaxDistance
Santi Posted March 14, 2020 Posted March 14, 2020 No server use source invés de getRootElement() na hora de fazer trigger no client, ficando assim: addCommandHandler("coco",function(source) local x,y,z = getElementPosition(source) coco = createObject(14810,x,y-0.1,z-0.8,0,0,rotation) setTimer(destroyElement,900000,1,coco) triggerClientEvent("somcoco",source) setPedAnimation( source, "ped", "WEAPON_crouch", -1, false,false,nil,false ) end) addCommandHandler("tomacachaca",function(source) setPedAnimation( source, "VENDING", "VEND_Drink2_P", -1,false,false,nil,false ) triggerClientEvent("somcachaca",source) end)
Moderators Lord Henry Posted March 14, 2020 Moderators Posted March 14, 2020 (edited) Continua errado. O triggerClientEvent tem o primeiro parâmetro opcional que identifica em qual cliente ele vai ativar o evento. Se você não especificar o primeiro parâmetro, ele vai considerar como todo mundo. addCommandHandler ("coco", function (thePlayer) local x,y,z = getElementPosition (thePlayer) coco = createObject (14810, x, y-0.1, z-0.8, 0, 0, rotation) setTimer (destroyElement, 900000, 1, coco) triggerClientEvent (thePlayer, "somcoco", thePlayer) -- Parâmetros: Jogador cujo cliente vai ativar o evento, "nome do evento", source do evento. setPedAnimation (thePlayer, "ped", "WEAPON_crouch", -1, false, false, nil, false) end) addCommandHandler ("tomacachaca", function (thePlayer) setPedAnimation (thePlayer, "VENDING", "VEND_Drink2_P", -1, false, false, nil, false) triggerClientEvent (thePlayer, "somcachaca", thePlayer) end) E não se usa source como parâmetro de função. Edited March 14, 2020 by Lord Henry Eu te ajudei ou achou meu comentário útil? Não esqueça de deixar um Thanks! Minhas contribuições para a comunidade: LordHenry - MTA Wiki Profile Inscreva-se no meu canal do YouTube: Lord Henry - Entertainment Discord Oficial do MTA: https://mtasa.com/discord Blacklist e Whitelist de Scripters: Planilha Por favor, não me envie mensagens privadas solicitando suporte. Crie um tópico no fórum em vez disso.
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