Sign in to follow this  
EW1611

Ajuda com playSound3D

Recommended Posts

Olá fiz o seguinte script, para quando o player soltar o acelerador dar play no som, mas não da play e nenhum erro no debugscript, até tentei aumentar o volume, mas ainda não acontece nada:
 

function blowoff(thePlayer)
	p = getPedOccupiedVehicle(thePlayer)
	id = getElementModel(p)
	if id == 562 then
		pos = getElementPosition(thePlayer)
		s1 = playSound3D("BlowOff.mp3", pos, true)
		setSoundVolume(s1, 10)
	end
end

function bnd()
	unbindKey("accelerate","up",blowoff)
end
addEventHandler("onClientVehicleEnter", root, bnd)

function ubnd()
	unbindKey("accelerate","up",blowoff)
end
addEventHandler("onClientVehicleExit", root, ubnd)

Obs: O áudio tem 1 segundo, não sei se pode ser isso

 

Share this post


Link to post

Linha 12 deveria ser bindKey.

Você está bindando a função ao soltar a tecla, é isso mesmo? Ou deveria ocorrer ao pressionar a tecla?

Share this post


Link to post

é, ao soltar a tecla que o player usa para acelerar o veículo

Erro na linha 2: Bad argument @ 'getElementPosition' [Expected element at argument 1, got string 'accelerate']; linha 3:Bad argument @ 'playSound3D' [Expected vector 3 at argument 2, got boolean]; linha 4: bad 'sound/player' pointer @ 'setSoundVolume'(1)

Edited by EW1611

Share this post


Link to post

Scripts client-side usam localPlayer. Remova o parâmetro de função e troque todos os thePlayer por localPlayer.

Se você ler a wiki do bindKey, vai perceber que no client-side, o primeiro parâmetro não é o jogador e sim o nome da tecla/controle.

Edited by Lord Henry
  • Thanks 1

Share this post


Link to post
function blowoff(localPlayer, accelerate, up)
	local p = getPedOccupiedVehicle(localPlayer)
	local id = getElementModel(p)
	if id == 562 then
		local x,y,z = getElementPosition(localPlayer)
		s1 = playSound3D("BlowOff.mp3", x,y,z)
		setSoundVolume(s1, 1.5)
	end
end

function bnd()
	bindKey("accelerate","up",blowoff)
end
addEventHandler("onClientVehicleEnter", root, bnd)

function ubnd()
	unbindKey("accelerate","up",blowoff)
end
addEventHandler("onClientVehicleExit", root, ubnd)

Fiz assim e continua dando o mesmo erro na linha 2 e 3

Share this post


Link to post

remova o localPlayer do parametro

e tente remover a linha 3 e 4 pra ver se o problema está ali

 

getKeyState

 isso pode te ajudar tambem

Edited by Furzy
  • Thanks 1

Share this post


Link to post

fiz assim, mas da o mesmo erro " [Expected element at argument 1, got string 'accelerate']"

function blowoff(source, localPlayer, accelerate, up)
	local x,y,z = getElementPosition(localPlayer)
	playSound3D("BlowOff.mp3", x,y,z)
end

function bnd()
	bindKey("accelerate","up",blowoff)
end
addEventHandler("onClientVehicleEnter", root, bnd)

function ubnd()
	unbindKey("accelerate","up",blowoff)
end
addEventHandler("onClientVehicleExit", root, ubnd)

 

Share this post


Link to post

Fiz assim e agora está funcionando perfeitamente:
 

addEventHandler("onClientVehicleEnter", root, 
function (key, keystate)
	bindKey("accelerate", "up", blowoff)
end)
	
function blowoff(commandname)
	p = getPedOccupiedVehicle(localPlayer)
	id = getElementModel(p)
	if id == 562 then
		x,y,z = getElementPosition(localPlayer)
		playSound3D("BlowOff.mp3", x,y,z)
	end
end

 

  • Like 1

Share this post


Link to post
37 minutes ago, EW1611 said:

Fiz assim e agora está funcionando perfeitamente:
 


addEventHandler("onClientVehicleEnter", root, 
function (key, keystate)
	bindKey("accelerate", "up", blowoff)
end)
	
function blowoff(commandname)
	p = getPedOccupiedVehicle(localPlayer)
	id = getElementModel(p)
	if id == 562 then
		x,y,z = getElementPosition(localPlayer)
		playSound3D("BlowOff.mp3", x,y,z)
	end
end

 

Boa xD

  • Thanks 1

Share this post


Link to post

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
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.