Jump to content

I need help


Hero192

Recommended Posts

Hello there i need help please,

When i enter URL in Edit it works fine, like: Creating object,Destroying object,Playing music,stopping music...

Please im stuck,i want all these thing that works in Edit works also for "guiGridListGetSelectedItem".

function print ( message, r, g, b ) 
        outputChatBox ( message, r, g, b ) 
    end 
      
    ------------------------------ 
    -- The GUI                  -- 
    ------------------------------ 
    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",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) 
    --GUIEditor_Grid = guiCreateGridList(9,73,334,146,false, window) 
    guiCreateLabel(11,271,225,18,"Radio pos:", false, window) 
    --url = guiCreateEdit(11, 96, 272, 23, "", 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) 
    -------------------------- 
    -- My sweet codes       -- 
    -------------------------- 
    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 

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