Jump to content

Play music from editbox


Waileer

Recommended Posts

Hello, I downloaded one resource and tried to edit it so it plays song on speaker from edit box at GUI. But after clicking "Create" or "Remove" it doesn't do anything

Here is client.lua

commandGUI = "speaker" 
  
screenW,screenH = guiGetScreenSize() 
  
  
addEventHandler("onClientResourceStart", resourceRoot, 
    function() 
        Window = guiCreateWindow((screenW - 384) / 2, (screenH - 102) / 2, 384, 102, "Speakers", false) 
        guiWindowSetSizable(Window, false) 
         
        bCreate = guiCreateButton(83, 64, 72, 27, "Create", false, Window) 
        bRemove = guiCreateButton(160, 64, 72, 27, "Remove", false, Window) 
        bClose = guiCreateButton(237, 64, 72, 27, "Close", false, Window) 
         
    addEventHandler("onClientGUIClick",bCreate, playTheSound) 
    addEventHandler("onClientGUIClick",bRemove, stopTheSound) 
  
        link = guiCreateEdit(43, 31, 331, 26, "", false, Window) 
  
        guiCreateLabel(10, 36, 26, 16, "Link:", false, Window) 
        
    guiSetVisible (Window, false)        
    end 
)  
  
  
function openGUI() 
guiSetVisible (Window, true) 
showCursor (true) 
end 
  
function closeGUI() 
guiSetVisible (Window, false) 
showCursor (false) 
end 
  
  
  
function playTheSound(x, y, z, vehicle) 
        local url = guiGetText(link) 
    sound = playSound3D(url, x, y, z) 
    if (isElement(vehicle)) then attachElements(sound, vehicle) end 
end 
addEvent("playTheSound", true) 
addEventHandler("playTheSound", root, playTheSound) 
  
function stopTheSound(x, y, z) 
    stopSound(sound) 
end 
addEvent("stopTheSound", true) 
addEventHandler("stopTheSound", root, stopTheSound) 
  
addEventHandler ( "onClientGUIClick", getResourceRootElement(getThisResource()), 
        function ( ) 
            if (source == bClose) then 
            closeGUI() 
            end 
         end 
) 
  
addCommandHandler(commandGUI,openGUI) 

Link to comment

x, y, z and vehicle weren't defined in your code (they were parameters from the onClientGUIClick event), but I think that you trigger the "playTheSoundEvent" event in the server side, so i didn't remove the old 'variables'.

commandGUI = "speaker" 
  
screenW,screenH = guiGetScreenSize() 
  
  
addEventHandler("onClientResourceStart", resourceRoot, 
    function() 
        Window = guiCreateWindow((screenW - 384) / 2, (screenH - 102) / 2, 384, 102, "Speakers", false) 
        guiWindowSetSizable(Window, false) 
        
        bCreate = guiCreateButton(83, 64, 72, 27, "Create", false, Window) 
        bRemove = guiCreateButton(160, 64, 72, 27, "Remove", false, Window) 
        bClose = guiCreateButton(237, 64, 72, 27, "Close", false, Window) 
        
        addEventHandler("onClientGUIClick",bCreate, playTheSound) 
        addEventHandler("onClientGUIClick",bRemove, stopTheSound) 
  
        link = guiCreateEdit(43, 31, 331, 26, "", false, Window) 
  
        guiCreateLabel(10, 36, 26, 16, "Link:", false, Window) 
        
        guiSetVisible (Window, false)       
    end 
) 
  
  
function openGUI() 
    guiSetVisible (Window, true) 
    showCursor (true) 
end 
  
function closeGUI() 
    guiSetVisible (Window, false) 
    showCursor (false) 
end 
  
  
  
function playTheSound(x, y, z, vehicle) 
    local url       =   guiGetText( link ) 
    local pos       =   type(x) ~= "string" and { x, y, z } or { getElementPosition ( localPlayer ) } 
    local vehicle   =   isElement(vehicle) and vehicle or ( isPedInVehicle( localPlayer ) and getPedOccupiedVehicle ( localPlayer ) or false ) 
    
    sound = playSound3D(url, unpack ( pos ) ) 
    if (isElement(vehicle)) then attachElements(sound, vehicle) end 
end 
addEvent("playTheSound", true) 
addEventHandler("playTheSound", root, playTheSound) 
  
function stopTheSound(x, y, z) 
    if sound and isElement(sound) then 
        stopSound(sound) 
    end 
end 
addEvent("stopTheSound", true) 
addEventHandler("stopTheSound", root, stopTheSound) 
  
addEventHandler ( "onClientGUIClick", getResourceRootElement(getThisResource()), 
    function ( ) 
        if (source == bClose) then 
            closeGUI() 
        end 
     end 
) 
  
addCommandHandler(commandGUI,openGUI) 

Link to comment
x, y, z and vehicle weren't defined in your code (they were parameters from the onClientGUIClick event), but I think that you trigger the "playTheSoundEvent" event in the server side, so i didn't remove the old 'variables'.
commandGUI = "speaker" 
  
screenW,screenH = guiGetScreenSize() 
  
  
addEventHandler("onClientResourceStart", resourceRoot, 
    function() 
        Window = guiCreateWindow((screenW - 384) / 2, (screenH - 102) / 2, 384, 102, "Speakers", false) 
        guiWindowSetSizable(Window, false) 
        
        bCreate = guiCreateButton(83, 64, 72, 27, "Create", false, Window) 
        bRemove = guiCreateButton(160, 64, 72, 27, "Remove", false, Window) 
        bClose = guiCreateButton(237, 64, 72, 27, "Close", false, Window) 
        
        addEventHandler("onClientGUIClick",bCreate, playTheSound) 
        addEventHandler("onClientGUIClick",bRemove, stopTheSound) 
  
        link = guiCreateEdit(43, 31, 331, 26, "", false, Window) 
  
        guiCreateLabel(10, 36, 26, 16, "Link:", false, Window) 
        
        guiSetVisible (Window, false)       
    end 
) 
  
  
function openGUI() 
    guiSetVisible (Window, true) 
    showCursor (true) 
end 
  
function closeGUI() 
    guiSetVisible (Window, false) 
    showCursor (false) 
end 
  
  
  
function playTheSound(x, y, z, vehicle) 
    local url       =   guiGetText( link ) 
    local pos       =   type(x) ~= "string" and { x, y, z } or { getElementPosition ( localPlayer ) } 
    local vehicle   =   isElement(vehicle) and vehicle or ( isPedInVehicle( localPlayer ) and getPedOccupiedVehicle ( localPlayer ) or false ) 
    
    sound = playSound3D(url, unpack ( pos ) ) 
    if (isElement(vehicle)) then attachElements(sound, vehicle) end 
end 
addEvent("playTheSound", true) 
addEventHandler("playTheSound", root, playTheSound) 
  
function stopTheSound(x, y, z) 
    if sound and isElement(sound) then 
        stopSound(sound) 
    end 
end 
addEvent("stopTheSound", true) 
addEventHandler("stopTheSound", root, stopTheSound) 
  
addEventHandler ( "onClientGUIClick", getResourceRootElement(getThisResource()), 
    function ( ) 
        if (source == bClose) then 
            closeGUI() 
        end 
     end 
) 
  
addCommandHandler(commandGUI,openGUI) 

Thank you! :)

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