Jump to content

I need help


Hero192

Recommended Posts

It's not about errors there's no errors, my problem is i want let these URLs in Table "defaultMusic" works in GuiGridList like when i put an URL in Editbox.

To be more clear,

I want let all acess for guigridlist like when i put url of music in editbox the same working i wants it to happen for gridlist when i selecte random URL in grid list ,it must create object/start musics/stop musics...etc

    defaultMusic = { 
        { "Hip Hop Radio", "http://mp3uplink.duplexfx.com:8054/listen.pls" }, 
        { "A horse with no name", "http://netanimations.net/A-Horse-With-No-Name.mp3" }, 
          {"Hit Radio", "http://www.181.fm/winamp.pls?station=181-power&style=mp3&description=Power%20181%20(Top%2040)&file=181-power.pls" } 
      
    } 
      
    local rx, ry = guiGetScreenSize ( ) 
    button = { } 
    GUIEditor_Grid = {} 
    window =  guiCreateWindow(510,288,352,322,"Speaker management.",false) 
    guiWindowSetSizable(window, false) 
    guiSetVisible ( window, false ) 
    CurrentSpeaker = guiCreateLabel(11,288,232,19,"Radio exist: No",false, window) 
    volume = guiCreateLabel(11,254,237,18,"Radio Vol: 100%", false, window) 
    pos = guiCreateLabel(71,271,232,19," X: 0 , Y: 0 , Z: 0", false, window) 
    guiCreateLabel(139,18,85,19,"Current URL:",false, window) 
    guiCreateLabel(13,56,100,17,"Radio list:",false, window) 
    guiCreateLabel(11,271,225,18,"Radio pos:", false, window)   
    url =  guiCreateEdit(9,35,328,20, "", false, window)   
    button["place"] = guiCreateButton(9,225,94,24,"Create/Pla", false, window) 
    button["remove"] = guiCreateButton(127,225,94,24,"Destroy", false, window) 
    button["v-"] = guiCreateButton(247,255,94,24,"Vol -", false, window) 
    button["v+"] = guiCreateButton(247,285,94,24,"Vol +", false, window) 
    button["close"] = guiCreateButton(247,225,94,24,"Close", false, window)   
    local List = guiCreateGridList(9,73,334,146,false,window) 
    guiGridListSetSelectionMode(List,0) 
    local col = guiGridListAddColumn(List,"Radio:",0.9,window) 
        for i=1, #defaultMusic do 
            guiGridListSetItemText(List, guiGridListAddRow(List), 1, defaultMusic[i][1], false, false) 
        end 
  
    addEventHandler( "onClientGUIClick", List, 
        function() 
            local row,col = guiGridListGetSelectedItem(List) 
            if (row ~= -1 and col ~= -1) then 
                playSound(defaultMusic[row][2]) 
            end 
        end) 
  
    local isSound = false 
    addEvent ( "onPlayerViewSpeakerManagment", true ) 
    addEventHandler ( "onPlayerViewSpeakerManagment", root, function ( current ) 
        local toState = not guiGetVisible ( window ) 
        guiSetVisible ( window, toState ) 
        showCursor ( toState ) 
        if ( toState == true ) then 
            guiSetInputMode ( "no_binds_when_editing" ) 
            local x, y, z = getElementPosition ( localPlayer ) 
            guiSetText ( pos, "X: "..math.floor ( x ).." , Y: "..math.floor ( y ).." , Z: "..math.floor ( z ) ) 
            if ( current ) then guiSetText ( CurrentSpeaker, "Radio exist: Yes" ) isSound = true 
            else guiSetText ( CurrentSpeaker, "Radio exist: No" ) end 
        end 
    end ) 
      
    addEventHandler ( "onClientGUIClick", root, function ( ) 
        if ( source == button["close"] ) then 
            guiSetVisible ( window, false ) 
            showCursor ( false ) 
        elseif ( source == button["place"] ) then 
            if ( isURL ( ) ) then 
                triggerServerEvent ( "onPlayerPlaceSpeakerBox", localPlayer, guiGetText ( url,col,row ), isPedInVehicle ( localPlayer ) ) 
                guiSetText ( CurrentSpeaker, "Radio exist: Yes" ) 
                isSound = true 
                guiSetText ( volume, "Radio Vol: 100%" ) 
            else 
                print ( "You need to enter a URL.", 255, 0, 0 ) 
            end 
        elseif ( source == button["remove"] ) then 
            triggerServerEvent ( "onPlayerDestroySpeakerBox", localPlayer ) 
            guiSetText ( CurrentSpeaker, "Radio exist: Yes" ) 
            isSound = false 
            guiSetText ( volume, "Radio Vol: 100%" ) 
        elseif ( source == button["v-"] ) then 
            if ( isSound ) then 
                local toVol = math.round ( getSoundVolume ( speakerSound [ localPlayer ] ) - subTrackOnSoundDown, 2 ) 
                if ( toVol > 0.0 ) then 
                    print ( "Volume set to "..math.floor ( toVol * 100 ).."%!", 0, 255, 0 ) 
                    triggerServerEvent ( "onPlayerChangeSpeakerBoxVolume", localPlayer, toVol ) 
                    guiSetText ( volume, "Radio Vol: "..math.floor ( toVol * 100 ).."%" ) 
                else 
                    print ( "The volume cannot go any lower.", 255, 0, 0 ) 
                end 
            end 
        elseif ( source == button["v+"] ) then 
            if ( isSound ) then 
                local toVol = math.round ( getSoundVolume ( speakerSound [ localPlayer ] ) + subTrackOnSoundUp, 2 ) 
                if ( toVol < 1.1 ) then 
                    print ( "Volume set to "..math.floor ( toVol * 100 ).."%!", 0, 255, 0 ) 
                    triggerServerEvent ( "onPlayerChangeSpeakerBoxVolume", localPlayer, toVol ) 
                    guiSetText ( volume, "Radio Vol: "..math.floor ( toVol * 100 ).."%" ) 
                else 
                    print ( "The volume cannot go any higher.", 255, 0, 0 ) 
                end 
            end 
        end 
    end ) 
      
    speakerSound = { } 
    addEvent ( "onPlayerStartSpeakerBoxSound", true ) 
    addEventHandler ( "onPlayerStartSpeakerBoxSound", root, function ( who, url,col,row, isCar,defaultMusic ) 
        if ( isElement ( speakerSound [ who ] ) ) then destroyElement ( speakerSound [ who ] ) end 
        local x, y, z = getElementPosition ( who ) 
        speakerSound [ who ] = playSound3D ( url,col,row, x, y, z, true ) 
        setSoundVolume ( speakerSound [ who ], 1 ) 
        setSoundMinDistance ( speakerSound [ who ], 25 ) 
        setSoundMaxDistance ( speakerSound [ who ], 40 ) 
        if ( isCar ) then 
            local car = getPedOccupiedVehicle ( who ) 
            attachElements ( speakerSound [ who ], car, 0, 5, 1 ) 
        end 
    end ) 
      
    addEvent ( "onPlayerDestroySpeakerBox", true ) 
    addEventHandler ( "onPlayerDestroySpeakerBox", root, function ( who ) 
        if ( isElement ( speakerSound [ who ] ) ) then 
            destroyElement ( speakerSound [ who ] ) 
        end 
    end ) 
      
--Volume 
    addEvent ( "onPlayerChangeSpeakerBoxVolumeC", true ) 
    addEventHandler ( "onPlayerChangeSpeakerBoxVolumeC", root, function ( who, vol ) 
        if ( isElement ( speakerSound [ who ] ) ) then 
            setSoundVolume ( speakerSound [ who ], tonumber ( vol ) ) 
        end 
    end ) 
      
    function isURL ( ) 
        if ( guiGetText ( url,col,row ) ~= "" ) then 
            return true 
        else 
            return false 
        end 
    end 
      
    function math.round(number, decimals, method) 
        decimals = decimals or 0 
        local factor = 10 ^ decimals 
        if (method == "ceil" or method == "floor") then return math[method](number * factor) / factor 
        else return tonumber(("%."..decimals.."f"):format(number)) end 
    end 

--server side:

local isSpeaker = false 
  
function print ( player, message, r, g, b ) 
    outputChatBox ( message, player, r, g, b ) 
end 
  
speakerBox = { } 
addCommandHandler ( "speaker", function ( thePlayer  ) 
    if ( isElement ( speakerBox [ thePlayer] ) ) then isSpeaker = true end 
    triggerClientEvent ( thePlayer, "onPlayerViewSpeakerManagment", thePlayer, isSpeaker ) 
end ) 
  
addEvent ( "onPlayerPlaceSpeakerBox", true ) 
addEventHandler ( "onPlayerPlaceSpeakerBox", root, function ( url, isCar,row,col )  
    if ( url ) then 
        if ( isElement ( speakerBox [ source ] ) ) then 
            local x, y, z = getElementPosition ( speakerBox [ source ] )  
            -- 
            destroyElement ( speakerBox [ source ] ) 
            removeEventHandler ( "onPlayerQuit", source, destroySpeakersOnPlayerQuit ) 
        end 
        local x, y, z = getElementPosition ( source ) 
        local rx, ry, rz = getElementRotation ( source ) 
        speakerBox [ source ] = createObject ( 2229, x-0.1, y+0.5, z - 1, 0, 0, rx ) 
        print ( source, "SPEAKER: Speaker is succssfully placed.", 0, 255, 0 ) 
        addEventHandler ( "onPlayerQuit", source, destroySpeakersOnPlayerQuit ) 
        triggerClientEvent ( root, "onPlayerStartSpeakerBoxSound", root, source, url, isCar,col,row ) 
        if ( isCar ) then 
            local car = getPedOccupiedVehicle ( source ) 
            attachElements ( speakerBox [ source ], car, 0.25, -1.3, -0.5, -0.5, 0, 0 ) 
        end 
    end 
end ) 
  
addEvent ( "onPlayerDestroySpeakerBox", true ) 
addEventHandler ( "onPlayerDestroySpeakerBox", root, function ( ) 
    if ( isElement ( speakerBox [ source ] ) ) then 
        destroyElement ( speakerBox [ source ] ) 
        triggerClientEvent ( root, "onPlayerDestroySpeakerBox", root, source ) 
        removeEventHandler ( "onPlayerQuit", source, destroySpeakersOnPlayerQuit ) 
        print ( source, "SPEAKER: Speaker has been removed.", 255, 0, 0 ) 
    else 
        --print  
    end 
end ) 
  
addEvent ( "onPlayerChangeSpeakerBoxVolume", true )  
addEventHandler ( "onPlayerChangeSpeakerBoxVolume", root, function ( to ) 
    triggerClientEvent ( root, "onPlayerChangeSpeakerBoxVolumeC", root, source, to ) 
end ) 

Edited by Guest
Link to comment
I would like to help but I can't understand you. You want to play an URL which you paste in editbox?

Normally,When you put an Music URL on the editbox it works fine, but what im trying to do, is to do an Table list with music URLs in the guiGridList you will just choose one of these URLs in gridlist to start them,

But i failed,it start only the music but all players in my local server hear it and without creating the Object of Speaker

i think you understood my situation

Link to comment
local isSpeaker = false 
  
function print ( player, message, r, g, b ) 
    outputChatBox ( message, player, r, g, b ) 
end 
  
speakerBox = { } 
addCommandHandler ( "speaker", function ( thePlayer  ) 
    if ( isElement ( speakerBox [ thePlayer] ) ) then isSpeaker = true end 
    triggerClientEvent ( thePlayer, "onPlayerViewSpeakerManagment", thePlayer, isSpeaker ) 
end ) 
  
addEvent ( "onPlayerPlaceSpeakerBox", true ) 
addEventHandler ( "onPlayerPlaceSpeakerBox", root, function ( url, isCar,row,col )  
    if ( url ) then 
        if ( isElement ( speakerBox [ source ] ) ) then 
            local x, y, z = getElementPosition ( speakerBox [ source ] )  
            -- 
            destroyElement ( speakerBox [ source ] ) 
            removeEventHandler ( "onPlayerQuit", source, destroySpeakersOnPlayerQuit ) 
        end 
        local x, y, z = getElementPosition ( source ) 
        local rx, ry, rz = getElementRotation ( source ) 
        speakerBox [ source ] = createObject ( 2229, x-0.1, y+0.5, z - 1, 0, 0, rx ) 
        print ( source, "SPEAKER: Speaker is succssfully placed.", 0, 255, 0 ) 
        addEventHandler ( "onPlayerQuit", source, destroySpeakersOnPlayerQuit ) 
        triggerClientEvent ( root, "onPlayerStartSpeakerBoxSound", root, source, url, isCar,col,row ) 
        if ( isCar ) then 
            local car = getPedOccupiedVehicle ( source ) 
            attachElements ( speakerBox [ source ], car, 0.25, -1.3, -0.5, -0.5, 0, 0 ) 
        end 
    end 
end ) 
  
addEvent ( "onPlayerDestroySpeakerBox", true ) 
addEventHandler ( "onPlayerDestroySpeakerBox", root, function ( ) 
    if ( isElement ( speakerBox [ source ] ) ) then 
        destroyElement ( speakerBox [ source ] ) 
        triggerClientEvent ( root, "onPlayerDestroySpeakerBox", root, source ) 
        removeEventHandler ( "onPlayerQuit", source, destroySpeakersOnPlayerQuit ) 
        print ( source, "SPEAKER: Speaker has been removed.", 255, 0, 0 ) 
    else 
        --print  
    end 
end ) 
  
addEvent ( "onPlayerChangeSpeakerBoxVolume", true )  
addEventHandler ( "onPlayerChangeSpeakerBoxVolume", root, function ( to ) 
    triggerClientEvent ( root, "onPlayerChangeSpeakerBoxVolumeC", root, source, to ) 
end ) 

Link to comment

It's not about errors there's no errors, my problem is i want let these URLs in Table works in GuiGridList like when i put an URL in Editbox.

To be more clear,

I want let all acess about when i add URl of music in editbox the same working when i selecte random URL in grid list ,it must create object/start musics/stop musics...etc

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