Jump to content

playSound problem


goofie88

Recommended Posts

hello guys I've made a voice thing but for some reason it shows the voice but when I press 1 theres no souns :(

Client

voice = nil 
  
  
addCommandHandler("voice", function() 
    if not voice then 
        voice = 1 
    else 
        voice = nil 
    end 
end 
) 
  
addEventHandler("onClientPlayerWasted", getLocalPlayer(), function() 
    voice = nil 
end) 
  
local width,height = guiGetScreenSize() 
addEventHandler("onClientRender", getRootElement(), function() 
    if voice then 
        tab1 = nil 
        tab2 = nil 
        dxDrawText("Radio Machine ",1,(height/2)-80,width,height,tocolor(255,255,255,255),0.6,"bankgothic" ) 
        if not isPedInVehicle(getLocalPlayer()) then 
            tab1 = 1 
            dxDrawRectangle(0,(height/2)-80,220,200,tocolor(0,0,0,70)) 
            if not disabled then 
                dxDrawText("(1) Roger",1,(height/2)-60,width,height,tocolor(100,150,240,255),0.6,"bankgothic" )         one = true 
            else 
                dxDrawText("(1) Roger",1,(height/2)-60,width,height,tocolor(100,100,100,255),0.6,"bankgothic" )         one = false 
            end 
        end 
    end 
end) 
  
function pressed1()     if voice then       if one == true then         local x, y, z = getElementPosition(getLocalPlayer())    if tab1 then    triggerEvent("sendSound", getLocalPlayer(), "1.1", x, y, z) end     end     disableAll()    end end  
  
function disableAll() disabled = 1  setTimer(enableAll, 5000, 1)    end 
function enableAll() disabled = nil end 
  
bindKey("1", "down", pressed1) 
  
function sendSound (sound, nX, nY, nZ) 
    local pX, pY, pZ = getElementPosition(getLocalPlayer()) 
    local dist = getDistanceBetweenPoints3D(pX, pY, pZ, nX, nY, nZ) 
    if dist < 40 then 
        if sound == "1.1" then  playSound("sounds/roger.mp3", false) end 
    end 
end 
addEventHandler("sendSound", getRootElement(), sendSound) 
addEvent("sendSound", true) 

Edited by Guest
Link to comment

Still the same theres no sound :/

function pressed1()     if voice then       if one == true then         local x, y, z = getElementPosition(getLocalPlayer())    if tab1 then    triggerEvent("sendSound", getLocalPlayer(), "1.1", x, y, z) end     end     disableAll()    end end  

Link to comment

try this:

voice = false 
addCommandHandler("voice", function() 
    voice = not voice 
end) 
  
addEventHandler("onClientPlayerWasted", getLocalPlayer(), function() 
    voice = false 
end) 
  
local width,height = guiGetScreenSize() 
addEventHandler("onClientRender", getRootElement(), function() 
    if voice then 
        tab1 = nil 
        tab2 = nil 
        dxDrawText("Radio Machine ",1,(height/2)-80,width,height,tocolor(255,255,255,255),0.6,"bankgothic" ) 
        if not isPedInVehicle(getLocalPlayer()) then 
            tab1 = 1 
            dxDrawRectangle(0,(height/2)-80,220,200,tocolor(0,0,0,70)) 
            if not disabled then 
                dxDrawText("(1) Roger",1,(height/2)-60,width,height,tocolor(100,150,240,255),0.6,"bankgothic" ) 
                one = true 
            else 
                dxDrawText("(1) Roger",1,(height/2)-60,width,height,tocolor(100,100,100,255),0.6,"bankgothic" ) 
                one = false 
            end 
        end 
    end 
end) 
  
function disableAll() disabled = true  setTimer(enableAll, 5000, 1)    end 
function enableAll() disabled = false end 
function pressed1() 
    if voice then  
        if one == true then 
            if tab1 then 
                local x, y, z = getElementPosition(getLocalPlayer()) 
                triggerEvent("sendSound", getLocalPlayer(), "1.1", x, y, z) 
            end 
        end 
        disableAll() 
    end 
end 
bindKey("1", "down", pressed1) 
  
function sendSound (sound, nX, nY, nZ) 
    local pX, pY, pZ = getElementPosition(getLocalPlayer()) 
    local dist = getDistanceBetweenPoints3D(pX, pY, pZ, nX, nY, nZ) 
    if dist < 40 then 
        if sound == "1.1" then  playSound("sounds/roger.mp3", false) end 
    end 
end 
addEventHandler("sendSound", getRootElement(), sendSound) 
addEvent("sendSound", true) 

Link to comment
<meta> 
    <info author="goofie88" name="Sound Panel" version="1.3r" type="script" />[color=#FF0000]>[/color] 
  
    <script src="sounds_client.lua" type="client"/> 
    <file src="sounds/roger.mp3"/> 
  
</meta> 

Extra '>' ?

    "goofie88" name="Sound Panel" version="1.3r" type="script" /> 
  
    

No need to increase your posts 8)

Link to comment

try this:

voice = false 
disabled = true 
one = false 
tab1 = false 
tab2 = false 
  
addCommandHandler("voice",function() voice = not voice end) 
addEventHandler("onClientPlayerWasted",localPlayer, function() voice = false end) 
  
addEventHandler("onClientRender",root, function() 
    local width,height = guiGetScreenSize() 
    if voice then 
        dxDrawText("Radio Machine ",1,(height/2)-80,width,height,tocolor(255,255,255,255),0.6,"bankgothic" ) 
        if isPedInVehicle(localPlayer) then return end 
        tab1 = true 
        dxDrawRectangle(0,(height/2)-80,220,200,tocolor(0,0,0,70)) 
        if not disabled then 
            dxDrawText("(1) Roger",1,(height/2)-60,width,height,tocolor(100,150,240,255),0.6,"bankgothic" ) 
            one = true 
        else 
            dxDrawText("(1) Roger",1,(height/2)-60,width,height,tocolor(100,100,100,255),0.6,"bankgothic" ) 
            one = false 
        end 
    end 
end) 
  
function enableAll() disabled = false end 
function disableAll() disabled = true  setTimer(enableAll, 5000, 1)    end 
  
bindKey("1", "down",function() 
    if voice then 
        if one then 
            local x, y, z = getElementPosition(localPlayer) 
            if tab1 then 
                sendSound("1.1", x, y, z) 
            end 
        end 
        disableAll() 
    end 
end) 
  
function sendSound (sound, nX, nY, nZ) 
    local pX, pY, pZ = getElementPosition(getLocalPlayer()) 
    local dist = getDistanceBetweenPoints3D(pX, pY, pZ, nX, nY, nZ) 
    if dist < 40 then 
        if sound == "1.1" then  playSound("sounds/roger.mp3", false) end 
    end 
end 

Link to comment
Thank you I hear the sound now :D but others dont hear, is that bcz its client side? if yes then how should I do so others car hear? Thank you again

Maybe like this?

    voice = false 
    disabled = true 
    one = false 
    tab1 = false 
    tab2 = false 
      
    addCommandHandler("voice",function() voice = not voice end) 
    addEventHandler("onClientPlayerWasted",root, function() voice = false end) 
      
    addEventHandler("onClientRender",root, function() 
        local width,height = guiGetScreenSize() 
        if voice then 
            dxDrawText("Radio Machine ",1,(height/2)-80,width,height,tocolor(255,255,255,255),0.6,"bankgothic" ) 
            if isPedInVehicle(localPlayer) then return end 
            tab1 = true 
            dxDrawRectangle(0,(height/2)-80,220,200,tocolor(0,0,0,70)) 
            if not disabled then 
                dxDrawText("(1) Roger",1,(height/2)-60,width,height,tocolor(100,150,240,255),0.6,"bankgothic" ) 
                one = true 
            else 
                dxDrawText("(1) Roger",1,(height/2)-60,width,height,tocolor(100,100,100,255),0.6,"bankgothic" ) 
                one = false 
            end 
        end 
    end) 
      
    function enableAll() disabled = false end 
    function disableAll() disabled = true  setTimer(enableAll, 5000, 1)    end 
      
    bindKey("1", "down",function() 
        if voice then 
            if one then 
                local x, y, z = getElementPosition(localPlayer) 
                if tab1 then 
                    sendSound("1.1", x, y, z) 
                end 
            end 
            disableAll() 
        end 
    end) 
      
    function sendSound (sound, nX, nY, nZ) 
        local pX, pY, pZ = getElementPosition(getLocalPlayer()) 
        local dist = getDistanceBetweenPoints3D(pX, pY, pZ, nX, nY, nZ) 
        if dist < 40 then 
            if sound == "1.1" then  playSound("sounds/roger.mp3", false) end 
        end 
    end 

Link to comment
Thank you I hear the sound now :D but others dont hear, is that bcz its client side? if yes then how should I do so others car hear? Thank you again

You need to trigger a server event and then back to all clients, then start the sound on every client and attach it to the vehicle.

Link to comment

here, try this:

client-side:

voice = false 
disabled = true 
one = false 
tab1 = false 
tab2 = false 
  
addCommandHandler("voice",function() voice = not voice end) 
addEventHandler("onClientPlayerWasted",localPlayer, function() voice = false end) 
  
addEventHandler("onClientRender",root, function() 
    local width,height = guiGetScreenSize() 
    if voice then 
        dxDrawText("Radio Machine ",1,(height/2)-80,width,height,tocolor(255,255,255,255),0.6,"bankgothic" ) 
        if isPedInVehicle(localPlayer) then return end 
        tab1 = true 
        dxDrawRectangle(0,(height/2)-80,220,200,tocolor(0,0,0,70)) 
        if not disabled then 
            dxDrawText("(1) Roger",1,(height/2)-60,width,height,tocolor(100,150,240,255),0.6,"bankgothic" ) 
            one = true 
        else 
            dxDrawText("(1) Roger",1,(height/2)-60,width,height,tocolor(100,100,100,255),0.6,"bankgothic" ) 
            one = false 
        end 
    end 
end) 
  
function enableAll() disabled = false end 
function disableAll() disabled = true  setTimer(enableAll, 5000, 1)    end 
  
bindKey("1", "down",function() 
    if voice then 
        if one then 
            local x, y, z = getElementPosition(localPlayer) 
            if tab1 then 
                triggerServerEvent("sendSound",localPlayer,1.1,x,y,z)--sendSound("1.1", x, y, z) 
            end 
        end 
        disableAll() 
    end 
end) 
  
addEvent("receiveSound",true) 
addEventHandler("receiveSound",root,function(sPath,sLoop) playSound(sPath,sLoop) end) 

server-side:

addEvent("sendSound",true) 
addEventHandler("sendSound",root,function(sound, nX, nY, nZ) 
    for i,_ in ipairs(getElementsByType("player"))do 
        local pX, pY, pZ = getElementPosition(i) 
        local dist = getDistanceBetweenPoints3D(pX, pY, pZ, nX, nY, nZ) 
        if dist < 40 then 
            if sound == "1.1" then  triggerClientEvent("receiveSound","sounds/roger.mp3", false) end 
        end 
    end 
end) 

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