Jump to content

Ajuda com Som


Recommended Posts

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)

 

Link to comment

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)

 

Link to comment
  • Other Languages Moderators

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 by Lord Henry
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...