Mefisto_PL Posted October 22, 2012 Share Posted October 22, 2012 I have a small problem.. I found a radio gui, but when I double click on the song, it doesn't stop, but when I click it again then sound is double played.. local sTations ={ ["Power 181"] = "http://www.181.fm/asx.php?station=181-uktop40&style=&a..scription="; } function CreateRadioGui ( ) if ( guiGetVisible ( RadioGui ) == true ) then guiSetVisible ( RadioGui, false ) showCursor ( false ) guiSetInputEnabled ( false ) else guiSetVisible ( RadioGui, true ) showCursor ( true ) guiSetInputEnabled ( true ) end end RadioGui = guiCreateWindow ( 0.75, 0.65, 0.25, 0.35, "ASDF - Radio Gui", true ) guiSetAlpha ( RadioGui, 0.9 ) guiSetVisible ( RadioGui, false ) RadioCloseButton = guiCreateButton ( 0.0, 0.85, 1.0, 0.25, "Close", true, RadioGui ) StationsGridList = guiCreateGridList ( 0.0, 0.1, 1.0, 0.70, true, RadioGui ) StationsList = guiGridListAddColumn( StationsGridList, "Stations List", 0.9 ) addCommandHandler ( "radio", CreateRadioGui ) function CloseRadioGui ( ) if ( source == RadioCloseButton ) then guiSetVisible ( RadioGui, false ) showCursor ( false ) guiSetInputEnabled ( false ) end end addEventHandler ( "onClientGUIClick", RadioCloseButton, CloseRadioGui ) addEventHandler( "onClientResourceStart", getRootElement( ), function () for StationName, StationAdress in pairs ( sTations ) do local row = guiGridListAddRow ( StationsGridList ) guiGridListSetItemText ( StationsGridList, row, 1, StationName, false, false ) end end ) function StartRadio() if source == StationsGridList then local row, col = guiGridListGetSelectedItem ( StationsGridList ) if ( row and col and row ~= -1 and col ~= -1 ) then local statioN = guiGridListGetItemText ( StationsGridList, row, 1 ) playSound( sTations[statioN] ) end end end addEventHandler("onClientGUIClick", getRootElement( ), StartRadio ) function StopRadio() if source == StationsGridList then local row, col = guiGridListGetSelectedItem ( StationsGridList ) if ( row and col and row ~= -1 and col ~= -1 ) then local statioN = guiGridListGetItemText ( StationsGridList, row, 1 ) stopSound( sTations[statioN] ) end end end addEventHandler("onClientDoubleClick", getRootElement( ), StopRadio ) Link to comment
Renkon Posted October 22, 2012 Share Posted October 22, 2012 local sTations ={ ["Power 181"] = "http://www.181.fm/asx.php?station=181-uktop40&style=&a..scription="; } function CreateRadioGui ( ) if ( guiGetVisible ( RadioGui ) == true ) then guiSetVisible ( RadioGui, false ) showCursor ( false ) guiSetInputEnabled ( false ) else guiSetVisible ( RadioGui, true ) showCursor ( true ) guiSetInputEnabled ( true ) end end RadioGui = guiCreateWindow ( 0.75, 0.65, 0.25, 0.35, "ASDF - Radio Gui", true ) guiSetAlpha ( RadioGui, 0.9 ) guiSetVisible ( RadioGui, false ) RadioCloseButton = guiCreateButton ( 0.0, 0.85, 1.0, 0.25, "Close", true, RadioGui ) StationsGridList = guiCreateGridList ( 0.0, 0.1, 1.0, 0.70, true, RadioGui ) StationsList = guiGridListAddColumn( StationsGridList, "Stations List", 0.9 ) addCommandHandler ( "radio", CreateRadioGui ) function CloseRadioGui ( ) if ( source == RadioCloseButton ) then guiSetVisible ( RadioGui, false ) showCursor ( false ) guiSetInputEnabled ( false ) end end addEventHandler ( "onClientGUIClick", RadioCloseButton, CloseRadioGui ) addEventHandler( "onClientResourceStart", getRootElement( ), function () for StationName, StationAdress in pairs ( sTations ) do local row = guiGridListAddRow ( StationsGridList ) guiGridListSetItemText ( StationsGridList, row, 1, StationName, false, false ) end end ) function StartRadio() if source == StationsGridList then local row, col = guiGridListGetSelectedItem ( StationsGridList ) if ( row and col and row ~= -1 and col ~= -1 ) then local statioN = guiGridListGetItemText ( StationsGridList, row, 1 ) radio = playSound( sTations[statioN] ) end end end addEventHandler("onClientGUIClick", getRootElement( ), StartRadio ) function StopRadio() if source == StationsGridList then local row, col = guiGridListGetSelectedItem ( StationsGridList ) if ( row and col and row ~= -1 and col ~= -1 ) then local statioN = guiGridListGetItemText ( StationsGridList, row, 1 ) stopSound( radio ) end end end addEventHandler("onClientDoubleClick", getRootElement( ), StopRadio ) Link to comment
Mefisto_PL Posted October 23, 2012 Author Share Posted October 23, 2012 It's not working but I have made that and I have a mistake in addEventHandler ( 2 argument ) local sTations ={ ["Power 181"] = "http://www.181.fm/asx.php?station=181-uktop40&style=&a..scription="; } function CreateRadioGui ( ) if ( guiGetVisible ( RadioGui ) == true ) then guiSetVisible ( RadioGui, false ) showCursor ( false ) guiSetInputEnabled ( false ) else guiSetVisible ( RadioGui, true ) showCursor ( true ) guiSetInputEnabled ( true ) end end RadioGui = guiCreateWindow ( 0.75, 0.65, 0.25, 0.35, "ASDF - Radio Gui", true ) guiSetAlpha ( RadioGui, 0.9 ) guiSetVisible ( RadioGui, false ) RadioCloseButton = guiCreateButton ( 0.0, 0.85, 1.0, 0.25, "Close", true, RadioGui ) StationsGridList = guiCreateGridList ( 0.0, 0.1, 1.0, 0.70, true, RadioGui ) StationsList = guiGridListAddColumn( StationsGridList, "Stations List", 0.9 ) addCommandHandler ( "radio", CreateRadioGui ) function CloseRadioGui ( ) if ( source == RadioCloseButton ) then guiSetVisible ( RadioGui, false ) showCursor ( false ) guiSetInputEnabled ( false ) end end addEventHandler ( "onClientGUIClick", RadioCloseButton, CloseRadioGui ) addEventHandler( "onClientResourceStart", getRootElement( ), function () for StationName, StationAdress in pairs ( sTations ) do local row = guiGridListAddRow ( StationsGridList ) guiGridListSetItemText ( StationsGridList, row, 1, StationName, false, false ) end end ) function StartRadio() if source == StationsGridList then local row, col = guiGridListGetSelectedItem ( StationsGridList ) if ( row and col and row ~= -1 and col ~= -1 ) then local statioN = guiGridListGetItemText ( StationsGridList, row, 1 ) local radioItem = guiGridListGetSelectedItem ( StationsGridList ) radio = playSound( sTations[statioN] ) end end end addEventHandler("onClientGUIClick", radioItem, Start ) function StopRadio() if source == StationsGridList then local row, col = guiGridListGetSelectedItem ( StationsGridList ) if ( row and col and row ~= -1 and col ~= -1 ) then local statioN = guiGridListGetItemText ( StationsGridList, row, 1 ) local radioItem = guiGridListGetSelectedItem ( StationsGridList ) stopSound( radio ) end end end addEventHandler("onClientGUIDoubleClick", radioItem, StopRadio ) Link to comment
Renkon Posted October 23, 2012 Share Posted October 23, 2012 addEventHandler("onClientGUIClick", radioItem, Start ) -- Line53 to addEventHandler("onClientGUIClick", StationsGridList, StartRadio ) Link to comment
Mefisto_PL Posted October 23, 2012 Author Share Posted October 23, 2012 Thanks, but a mistake is in 2. argument "radioItem".. What could be wrong? Link to comment
Renkon Posted October 23, 2012 Share Posted October 23, 2012 Thanks, but a mistake is in 2. argument "radioItem".. What could be wrong? Paste again, I modified something Link to comment
Mefisto_PL Posted October 23, 2012 Author Share Posted October 23, 2012 Double sound .. Link to comment
Renkon Posted October 23, 2012 Share Posted October 23, 2012 Define at the beginning: local sound = nil And modify this addEventHandler("onClientGUIDoubleClick", radioItem, StopRadio ) --line 65 to addEventHandler("onClientGUIDoubleClick", StationsGridList, StopRadio ) Link to comment
Mefisto_PL Posted October 23, 2012 Author Share Posted October 23, 2012 still double sound.. Link to comment
Renkon Posted October 23, 2012 Share Posted October 23, 2012 Noticed the reason. You are using onClientGUIClick, and for stopping, DoubleClick. So whenever you use a click it reproduces again, and after the second click, first one stops, but there is another one enabled My recommendation: create a GUI Button so you don't have these kind of problems. If you set them both to GUIClick or DoubleClick, no sound will be heard. So, another posible way is the following Remove EventHandler for stopping Radio add in start radio function: addEventHandler("onClientGUIDoubleClick", StationsGridList, StopRadio ) removeEventHandler("onClientGUIClick", StationsGridList, StartRadio ) add in Stop radio function: removeEventHandler("onClientGUIDoubleClick", StationsGridList, StopRadio ) addEventHandler("onClientGUIClick", StationsGridList, StartRadio ) Link to comment
Mefisto_PL Posted October 23, 2012 Author Share Posted October 23, 2012 Bad Argument Data [ 3 argument ] " removeEventHandler("onClientGUIDoubleClick", StationsGridList, StopRadio ) " Link to comment
Mefisto_PL Posted October 23, 2012 Author Share Posted October 23, 2012 Okey I made it with buttons but when I double-clicked on Play then sound starts again ( double sound ) function StartRadio() if source == RadioPlayButton then local row, col = guiGridListGetSelectedItem ( StationsGridList ) if ( row and col and row ~= -1 and col ~= -1 ) then local statioN = guiGridListGetItemText ( StationsGridList, row, 1 ) local radioItem = guiGridListGetSelectedItem ( StationsGridList ) radio = playSound( sTations[statioN] ) end end end addEventHandler("onClientGUIClick", RadioPlayButton, StartRadio ) function StopRadio() if source == RadioStopButton then local row, col = guiGridListGetSelectedItem ( StationsGridList ) if ( row and col and row ~= -1 and col ~= -1 ) then local statioN = guiGridListGetItemText ( StationsGridList, row, 1 ) local radioItem = guiGridListGetSelectedItem ( StationsGridList ) stopSound( radio ) end end end addEventHandler("onClientGUIClick", RadioStopButton, StopRadio ) Link to comment
Anderl Posted October 23, 2012 Share Posted October 23, 2012 Add: if isElement( radio ) then stopSound( radio ) end After line 6. Link to comment
Mefisto_PL Posted October 24, 2012 Author Share Posted October 24, 2012 function StartRadio() if source == StationsGridList then local row, col = guiGridListGetSelectedItem ( StationsGridList ) if ( row and col and row ~= -1 and col ~= -1 ) then local statioN = guiGridListGetItemText ( StationsGridList, row, 1 ) if isElement( radio ) then stopSound( radio ) end radio = playSound( sTations[statioN] ) end end end addEventHandler("onClientGUIClick", StationsGridList, StartRadio ) Working, but I can't stop this sound, when I click on it second time then play it again.. Link to comment
Castillo Posted October 24, 2012 Share Posted October 24, 2012 Destroy the sound via: destroyElement Link to comment
Mefisto_PL Posted October 24, 2012 Author Share Posted October 24, 2012 function StartRadio() if source == StationsGridList then local row, col = guiGridListGetSelectedItem ( StationsGridList ) if ( row and col and row ~= -1 and col ~= -1 ) then local statioN = guiGridListGetItemText ( StationsGridList, row, 1 ) if isElement( radio ) then destroyElement( radio ) end radio = playSound( sTations[statioN] ) end end end addEventHandler("onClientGUIClick", StationsGridList, StartRadio ) Doesn't make a sound Link to comment
Mefisto_PL Posted October 24, 2012 Author Share Posted October 24, 2012 function StartRadio() if source == StationsGridList then local row, col = guiGridListGetSelectedItem ( StationsGridList ) if ( row and col and row ~= -1 and col ~= -1 ) then local statioN = guiGridListGetItemText ( StationsGridList, row, col ) if isElement( radio ) then radio = false else radio = playSound( sTations[statioN] ) end end end end addEventHandler("onClientGUIClick", StationsGridList, StartRadio ) Why it's not working? :C Link to comment
Anderl Posted October 24, 2012 Share Posted October 24, 2012 Because I sent you working code and you changed it for some non-sense shit. Link to comment
Mefisto_PL Posted October 24, 2012 Author Share Posted October 24, 2012 Ohh.. I fix that, but thanks everyone Link to comment
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now