Jump to content

Why isn't the sound playing?


Recommended Posts

(script.lua)

function CriarPed (source, command, model)
    local sX, sY, sZ = getElementPosition(source)
    ped = createPed(model, sX, sY, sZ)
    if ped then
    outputChatBox ("Criaste um ped com o modelo: " .. model .. ".")
    setPedAnimation(ped, "ped", "WOMAN_walknorm")
    addEventHandler("onPedWasted", ped, PedMorreu)
    addCommandHandler("matarped", MatarPed)
    addCommandHandler("setvp", SetarVidaPed)
    addCommandHandler("setsp", SetarSkinPed)
    triggerClientEvent ("onPedCriado", source)
    else
        outputChatBox("Uso: /criarped [0-312].")
    end
end
addCommandHandler("criarped", CriarPed)
addCommandHandler("cp", CriarPed)
addCommandHandler("criarped", CriarPed)

So, before the else I trigger a Client Event named "onPedCriado", which I then create on the client script (scriptclient.lua);

function TocarSomPed ()
        local sound = playSound3D("main/reeet.mp3", 1948, -1713, 13.5, true)
    end
addEvent("onPedCriado", true)
addEventHandler("onPedCriado", localPlayer, TocarSomPed)

The sound is located in deathmatch > resources > main and this is my meta:

<meta>
    <info author="HugoAlmeida" type="gamemode" name="O meu humilde servidor" description="Prepara-te, Bill Gates! Eu venho aí!" />
    <script src="script.lua" />
    <script src="scriptclient.lua" type="client" />
    <script src="client/gui.lua" type="client" />
    <script src="ficheiro.lua" />
    <file src="reeet.mp3" />
</meta>

 

What's wrong?

Link to comment
function CriarPed (source, command, model)
    local sX, sY, sZ = getElementPosition(source)
    local ped = createPed(model, sX, sY, sZ)
    if ped then
		outputChatBox ("Criaste um ped com o modelo: " .. model .. ".")
		setPedAnimation(ped, "ped", "WOMAN_walknorm")
		addEventHandler("onPedWasted", ped, PedMorreu)
		addCommandHandler("matarped", MatarPed)
		addCommandHandler("setvp", SetarVidaPed)
		addCommandHandler("setsp", SetarSkinPed)
		triggerClientEvent (source, "onPedCriado", source)
    else
        outputChatBox("Uso: /criarped [0-312].", source)
    end
end
addCommandHandler("criarped", CriarPed)
addCommandHandler("cp", CriarPed)
addCommandHandler("criarped", CriarPed)
function TocarSomPed ()
		if ( isElement ( sound ) ) then
			destroyElement ( sound )
		end
        local sound = playSound3D("reeet.mp3", 1948, -1713, 13.5, true)
    end
addEvent("onPedCriado", true)
addEventHandler("onPedCriado", localPlayer, TocarSomPed)

 

Link to comment
1 hour ago, N3xT said:

function CriarPed (source, command, model)
    local sX, sY, sZ = getElementPosition(source)
    local ped = createPed(model, sX, sY, sZ)
    if ped then
		outputChatBox ("Criaste um ped com o modelo: " .. model .. ".")
		setPedAnimation(ped, "ped", "WOMAN_walknorm")
		addEventHandler("onPedWasted", ped, PedMorreu)
		addCommandHandler("matarped", MatarPed)
		addCommandHandler("setvp", SetarVidaPed)
		addCommandHandler("setsp", SetarSkinPed)
		triggerClientEvent (source, "onPedCriado", source)
    else
        outputChatBox("Uso: /criarped [0-312].", source)
    end
end
addCommandHandler("criarped", CriarPed)
addCommandHandler("cp", CriarPed)
addCommandHandler("criarped", CriarPed)

function TocarSomPed ()
		if ( isElement ( sound ) ) then
			destroyElement ( sound )
		end
        local sound = playSound3D("reeet.mp3", 1948, -1713, 13.5, true)
    end
addEvent("onPedCriado", true)
addEventHandler("onPedCriado", localPlayer, TocarSomPed)

 

Doesn't work. The sound doesn't play. Thanks anyways! Question: What are you looking after when you put isElement and why the need to check if it is an Element and then to destroy it? 

Error at pedsclient.lua (the second script): Bad Argument @ addEventHandler Expected element at argument 2, got nil

Edited by Hugo_Almeidowski
Link to comment

Oh!, my bad I didn't read the whole code so I missed that localPlayer. however, try this.

function TocarSomPed ()
		if ( isElement ( sound ) ) then
			destroyElement ( sound )
		end
        local sound = playSound3D("reeet.mp3", 1948, -1713, 13.5, true)
    end
addEvent("onPedCriado", true)
addEventHandler("onPedCriado", root, TocarSomPed)

About your question, You have to check if there's a played sound and destroy it before you play another one. If you didn't destroy it you can spam that command which makes the sound repeat over and over...

Link to comment
9 minutes ago, N3xT said:

Oh!, my bad I didn't read the whole code so I missed that localPlayer. however, try this.


function TocarSomPed ()
		if ( isElement ( sound ) ) then
			destroyElement ( sound )
		end
        local sound = playSound3D("reeet.mp3", 1948, -1713, 13.5, true)
    end
addEvent("onPedCriado", true)
addEventHandler("onPedCriado", root, TocarSomPed)

About your question, You have to check if there's a played sound and destroy it before you play another one. If you didn't destroy it you can spam that command which makes the sound repeat over and over...

It's still not working, but not it gives no Error...

?

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...