Reflex# Posted November 20, 2012 Share Posted November 20, 2012 local musicStream = "http://www.181.fm/winamp.pls?station=181-power&style=mp3&description=Power%20181%20(Top%2040)&file=181-power.pls" function onResourceStart() sound = playSound( musicStream, true) end function makeRadioStayOff() setRadioChannel(0) cancelEvent() end function toggleSong() if not songOff then setSoundVolume(sound,0) songOff = true removeEventHandler("onClientPlayerRadioSwitch",getRootElement(),makeRadioStayOff) dxDrawText("[RADIO] Radio is switched on",0,0,5,5,tocolor(0,0,0,255),1,"default-bold") else setSoundVolume(sound,1) songOff = false setRadioChannel(0) addEventHandler("onClientPlayerRadioSwitch",getRootElement(),makeRadioStayOff) dxDrawText("[RADIO] Radio is switched off",0,0,5,5,tocolor(0,0,0,255),1,"default-bold") end end addEventHandler("onClientResourceStart", getResourceRootElement(getThisResource()), onResourceStart) addEventHandler("onClientPlayerRadioSwitch",getRootElement(),makeRadioStayOff) addEventHandler("onClientPlayerVehicleEnter",getRootElement(),makeRadioStayOff) addEventHandler("onClientRender",root, addCommandHandler("radio",toggleSong) I found this script on community mtasa,edited it some,now I add dxDrawText..but it's dont work.. No errors in debugscript.. Please help any1 if you can Link to comment
Renkon Posted November 20, 2012 Share Posted November 20, 2012 Size is too goddamn small Link to comment
Reflex# Posted November 20, 2012 Author Share Posted November 20, 2012 Size is too goddamn small I think this is not a reason,why it dont work. Link to comment
Kenix Posted November 20, 2012 Share Posted November 20, 2012 addEventHandler("onClientRender",root, ??? Link to comment
Reflex# Posted November 20, 2012 Author Share Posted November 20, 2012 addEventHandler("onClientRender",root, ??? one scripter who helped me wih dxDrawText,said that dxDrawText is client-side,and I must to add this event Link to comment
Kenix Posted November 20, 2012 Share Posted November 20, 2012 You don't finish function name and ')' when you call function addEventHandler. It's syntax error. Look at arguments: bool addEventHandler ( string eventName, element attachedTo, function handlerFunction, [ bool getPropagated = true, string priority = "normal" ] ) Link to comment
Reflex# Posted November 20, 2012 Author Share Posted November 20, 2012 You don't finish function name and ')' when you call function addEventHandler. It's syntax error. Look at arguments: bool addEventHandler ( string eventName, element attachedTo, function handlerFunction, [ bool getPropagated = true, string priority = "normal" ] ) I added ')' in the end,but it' didn't work too... addEventHandler(onClientRender,root)I think I dont need this line in script.. Link to comment
myonlake Posted November 20, 2012 Share Posted November 20, 2012 You can't avoid the last argument of addEventHandler. It must be a function. function exampleFunction() -- Code end addEventHandler("onClientRender", root, exampleFunction) addEventHandler("onClientRender", root, function() -- Code end ) But as far as I can see, you don't need this event in your script. Link to comment
Reflex# Posted November 20, 2012 Author Share Posted November 20, 2012 You can't avoid the last argument of addEventHandler. It must be a function. function exampleFunction() -- Code end addEventHandler("onClientRender", root, exampleFunction) addEventHandler("onClientRender", root, function() -- Code end ) But as far as I can see, you don't need this event in your script. i know that I must'nt avoid it) but...what the problem of script? I just must delete this event? Link to comment
Renkon Posted November 20, 2012 Share Posted November 20, 2012 Code is a mess, gonna be honest.... You could try making codes more organized. Link to comment
Reflex# Posted November 20, 2012 Author Share Posted November 20, 2012 Code is a mess, gonna be honest.... You could try making codes more organized. I uploaded this script from mtasa resources,and just added in it dxDrawText function and changed stream.. Link to comment
Reflex# Posted November 21, 2012 Author Share Posted November 21, 2012 So what is the problem,guys? Link to comment
myonlake Posted November 21, 2012 Share Posted November 21, 2012 (edited) So what is the problem,guys? Everything. Try this. Client-side local musicStream = "http://www.181.fm/winamp.pls?station=181-power&style=mp3&description=Power%20181%20(Top%2040)&file=181-power.pls" addEventHandler("onClientResourceStart", function() sound = playSound(musicStream, true) end ) function makeRadioStayOff() setRadioChannel(0) cancelEvent() end addEventHandler("onClientPlayerRadioSwitch", root, makeRadioStayOff) addEventHandler("onClientPlayerVehicleEnter", root, makeRadioStayOff) addCommandHandler("radio", function(cmd) if not songOff then setSoundVolume(sound, 0) songOff = true removeEventHandler("onClientPlayerRadioSwitch", root, makeRadioStayOff) else setSoundVolume(sound, 1) songOff = false setRadioChannel(0) addEventHandler("onClientPlayerRadioSwitch", root, makeRadioStayOff) end end ) addEventHandler("onClientRender", root, function() if not songOff then dxDrawText("[RADIO] Radio is switched on", 0, 0, 5, 5, tocolor(0, 0, 0, 255), 1, "default-bold") else dxDrawText("[RADIO] Radio is switched off", 0, 0, 5, 5, tocolor(0, 0, 0, 255), 1, "default-bold") end end ) Edited November 21, 2012 by Guest Link to comment
Reflex# Posted November 21, 2012 Author Share Posted November 21, 2012 Ok,when I will come home,I'll try it. But thx in helping. Link to comment
Scripting Moderators Sarrum Posted November 21, 2012 Scripting Moderators Share Posted November 21, 2012 local musicStream = "http://www.181.fm/winamp.pls?station=181-power&style=mp3&description=Power%20181%20(Top%2040)&file=181-power.pls" function onResourceStart ( ) sound = playSound ( musicStream, true ) end function makeRadioStayOff ( ) setRadioChannel ( 0 ) cancelEvent ( ) end function toggleSong ( ) if not songOff then setSoundVolume ( sound, 0 ) songOff = true removeEventHandler ( "onClientPlayerRadioSwitch", root, makeRadioStayOff ) else setSoundVolume ( sound, 1 ) songOff = false setRadioChannel ( 0 ) addEventHandler ( "onClientPlayerRadioSwitch", root, makeRadioStayOff ) end end function renderText ( ) if not songOff then dxDrawText ( "[RADIO] Radio is switched on", 0, 0, 5, 5, tocolor ( 0, 0, 0, 255 ), 1, "default-bold" ) else dxDrawText ( "[RADIO] Radio is switched off", 0, 0, 5, 5, tocolor ( 0, 0, 0, 255 ), 1, "default-bold" ) end end addEventHandler ( "onClientResourceStart", resourceRoot, onResourceStart ) addEventHandler ( "onClientPlayerRadioSwitch", root, makeRadioStayOff ) addEventHandler ( "onClientPlayerVehicleEnter", root, makeRadioStayOff ) addEventHandler ( "onClientRender", root, renderText ) addCommandHandler ( "radio", toggleSong ) Link to comment
Reflex# Posted November 21, 2012 Author Share Posted November 21, 2012 local musicStream = "http://www.181.fm/winamp.pls?station=181-power&style=mp3&description=Power%20181%20(Top%2040)&file=181-power.pls" function onResourceStart ( ) sound = playSound ( musicStream, true ) end function makeRadioStayOff ( ) setRadioChannel ( 0 ) cancelEvent ( ) end function toggleSong ( ) if not songOff then setSoundVolume ( sound, 0 ) songOff = true removeEventHandler ( "onClientPlayerRadioSwitch", root, makeRadioStayOff ) else setSoundVolume ( sound, 1 ) songOff = false setRadioChannel ( 0 ) addEventHandler ( "onClientPlayerRadioSwitch", root, makeRadioStayOff ) end end function renderText ( ) if not songOff then dxDrawText ( "[RADIO] Radio is switched on", 0, 0, 5, 5, tocolor ( 0, 0, 0, 255 ), 1, "default-bold" ) else dxDrawText ( "[RADIO] Radio is switched off", 0, 0, 5, 5, tocolor ( 0, 0, 0, 255 ), 1, "default-bold" ) end end addEventHandler ( "onClientResourceStart", resourceRoot, onResourceStart ) addEventHandler ( "onClientPlayerRadioSwitch", root, makeRadioStayOff ) addEventHandler ( "onClientPlayerVehicleEnter", root, makeRadioStayOff ) addEventHandler ( "onClientRender", root, renderText ) addCommandHandler ( "radio", toggleSong ) ty,script is work..but how I can make..when I ON radio,text showing and then hiding? same with OFF Link to comment
Castillo Posted November 21, 2012 Share Posted November 21, 2012 local musicStream = "http://www.181.fm/winamp.pls?station=181-power&style=mp3&description=Power%20181%20(Top%2040)&file=181-power.pls" function onResourceStart ( ) sound = playSound ( musicStream, true ) end function makeRadioStayOff ( ) setRadioChannel ( 0 ) cancelEvent ( ) end function toggleSong ( ) removeEventHandler ( "onClientRender", root, renderText ) if ( isTimer ( hideTimer ) ) then killTimer ( hideTimer ) end if not songOff then setSoundVolume ( sound, 0 ) songOff = true removeEventHandler ( "onClientPlayerRadioSwitch", root, makeRadioStayOff ) addEventHandler ( "onClientRender", root, renderText ) hideTimer = setTimer ( function ( ) removeEventHandler ( "onClientRender", root, renderText ) end ,5000, 1 ) else setSoundVolume ( sound, 1 ) songOff = false setRadioChannel ( 0 ) addEventHandler ( "onClientPlayerRadioSwitch", root, makeRadioStayOff ) addEventHandler ( "onClientRender", root, renderText ) hideTimer = setTimer ( function ( ) removeEventHandler ( "onClientRender", root, renderText ) end ,5000, 1 ) end end function renderText ( ) dxDrawText ( "[RADIO] Radio is switched ".. ( songOff and "off" or "on" ), 0, 0, 5, 5, tocolor ( 0, 0, 0, 255 ), 1, "default-bold" ) end addEventHandler ( "onClientResourceStart", resourceRoot, onResourceStart ) addEventHandler ( "onClientPlayerRadioSwitch", root, makeRadioStayOff ) addEventHandler ( "onClientPlayerVehicleEnter", root, makeRadioStayOff ) addCommandHandler ( "radio", toggleSong ) After 5 seconds when shown, it'll hide it. Link to comment
Reflex# Posted November 21, 2012 Author Share Posted November 21, 2012 local musicStream = "http://www.181.fm/winamp.pls?station=181-power&style=mp3&description=Power%20181%20(Top%2040)&file=181-power.pls" function onResourceStart ( ) sound = playSound ( musicStream, true ) end function makeRadioStayOff ( ) setRadioChannel ( 0 ) cancelEvent ( ) end function toggleSong ( ) removeEventHandler ( "onClientRender", root, renderText ) if ( isTimer ( hideTimer ) ) then killTimer ( hideTimer ) end if not songOff then setSoundVolume ( sound, 0 ) songOff = true removeEventHandler ( "onClientPlayerRadioSwitch", root, makeRadioStayOff ) addEventHandler ( "onClientRender", root, renderText ) hideTimer = setTimer ( function ( ) removeEventHandler ( "onClientRender", root, renderText ) end ,5000, 1 ) else setSoundVolume ( sound, 1 ) songOff = false setRadioChannel ( 0 ) addEventHandler ( "onClientPlayerRadioSwitch", root, makeRadioStayOff ) addEventHandler ( "onClientRender", root, renderText ) hideTimer = setTimer ( function ( ) removeEventHandler ( "onClientRender", root, renderText ) end ,5000, 1 ) end end function renderText ( ) dxDrawText ( "[RADIO] Radio is switched ".. ( songOff and "off" or "on" ), 0, 0, 5, 5, tocolor ( 0, 0, 0, 255 ), 1, "default-bold" ) end addEventHandler ( "onClientResourceStart", resourceRoot, onResourceStart ) addEventHandler ( "onClientPlayerRadioSwitch", root, makeRadioStayOff ) addEventHandler ( "onClientPlayerVehicleEnter", root, makeRadioStayOff ) addCommandHandler ( "radio", toggleSong ) After 5 seconds when shown, it'll hide it. Thank's solid And if I want to change time,I must change this? ,5000, 1 Link to comment
Castillo Posted November 21, 2012 Share Posted November 21, 2012 Yes, you have to change "5000". Link to comment
Reflex# Posted November 21, 2012 Author Share Posted November 21, 2012 Yes, you have to change "5000". Thanks for help,but have another problem,look : I changed deleted addComandHandler and add bindkey..but when I press R,radio don't off/on local musicStream = "http://www.181.fm/winamp.pls?station=181-power&style=mp3&description=Power%20181%20(Top%2040)&file=181-power.pls" function onResourceStart ( ) sound = playSound ( musicStream, true ) end function makeRadioStayOff ( ) setRadioChannel ( 0 ) cancelEvent ( ) end function toggleSong ( ) removeEventHandler ( "onClientRender", root, renderText ) if ( isTimer ( hideTimer ) ) then killTimer ( hideTimer ) end if not songOff then setSoundVolume ( sound, 0 ) songOff = true removeEventHandler ( "onClientPlayerRadioSwitch", root, makeRadioStayOff ) addEventHandler ( "onClientRender", root, renderText ) hideTimer = setTimer ( function ( ) removeEventHandler ( "onClientRender", root, renderText ) end ,5000, 1 ) else setSoundVolume ( sound, 1 ) songOff = false setRadioChannel ( 0 ) addEventHandler ( "onClientPlayerRadioSwitch", root, makeRadioStayOff ) addEventHandler ( "onClientRender", root, renderText ) hideTimer = setTimer ( function ( ) removeEventHandler ( "onClientRender", root, renderText ) end ,5000, 1 ) end end function renderText ( ) dxDrawText ( "[RADIO] Radio is switched ".. ( songOff and "off" or "on" ), 230, 100, 400, 300, tocolor ( 255, 91, 3, 255 ), 2, "default-bold" ) end addEventHandler ( "onClientResourceStart", resourceRoot, onResourceStart ) addEventHandler ( "onClientPlayerRadioSwitch", root, makeRadioStayOff ) addEventHandler ( "onClientPlayerVehicleEnter", root, makeRadioStayOff ) bindKey("r","down","music") Link to comment
Castillo Posted November 21, 2012 Share Posted November 21, 2012 That's because you binded it to command "music", not to "toggleSong" function. local musicStream = "http://www.181.fm/winamp.pls?station=181-power&style=mp3&description=Power%20181%20(Top%2040)&file=181-power.pls" function onResourceStart ( ) sound = playSound ( musicStream, true ) end function makeRadioStayOff ( ) setRadioChannel ( 0 ) cancelEvent ( ) end function toggleSong ( ) removeEventHandler ( "onClientRender", root, renderText ) if ( isTimer ( hideTimer ) ) then killTimer ( hideTimer ) end if not songOff then setSoundVolume ( sound, 0 ) songOff = true removeEventHandler ( "onClientPlayerRadioSwitch", root, makeRadioStayOff ) addEventHandler ( "onClientRender", root, renderText ) hideTimer = setTimer ( function ( ) removeEventHandler ( "onClientRender", root, renderText ) end ,5000, 1 ) else setSoundVolume ( sound, 1 ) songOff = false setRadioChannel ( 0 ) addEventHandler ( "onClientPlayerRadioSwitch", root, makeRadioStayOff ) addEventHandler ( "onClientRender", root, renderText ) hideTimer = setTimer ( function ( ) removeEventHandler ( "onClientRender", root, renderText ) end ,5000, 1 ) end end function renderText ( ) dxDrawText ( "[RADIO] Radio is switched ".. ( songOff and "off" or "on" ), 0, 0, 5, 5, tocolor ( 0, 0, 0, 255 ), 1, "default-bold" ) end addEventHandler ( "onClientResourceStart", resourceRoot, onResourceStart ) addEventHandler ( "onClientPlayerRadioSwitch", root, makeRadioStayOff ) addEventHandler ( "onClientPlayerVehicleEnter", root, makeRadioStayOff ) bindKey ( "R", "down", toggleSong ) Link to comment
Reflex# Posted November 21, 2012 Author Share Posted November 21, 2012 That's because you binded it to command "music", not to "toggleSong" function. local musicStream = "http://www.181.fm/winamp.pls?station=181-power&style=mp3&description=Power%20181%20(Top%2040)&file=181-power.pls" function onResourceStart ( ) sound = playSound ( musicStream, true ) end function makeRadioStayOff ( ) setRadioChannel ( 0 ) cancelEvent ( ) end function toggleSong ( ) removeEventHandler ( "onClientRender", root, renderText ) if ( isTimer ( hideTimer ) ) then killTimer ( hideTimer ) end if not songOff then setSoundVolume ( sound, 0 ) songOff = true removeEventHandler ( "onClientPlayerRadioSwitch", root, makeRadioStayOff ) addEventHandler ( "onClientRender", root, renderText ) hideTimer = setTimer ( function ( ) removeEventHandler ( "onClientRender", root, renderText ) end ,5000, 1 ) else setSoundVolume ( sound, 1 ) songOff = false setRadioChannel ( 0 ) addEventHandler ( "onClientPlayerRadioSwitch", root, makeRadioStayOff ) addEventHandler ( "onClientRender", root, renderText ) hideTimer = setTimer ( function ( ) removeEventHandler ( "onClientRender", root, renderText ) end ,5000, 1 ) end end function renderText ( ) dxDrawText ( "[RADIO] Radio is switched ".. ( songOff and "off" or "on" ), 0, 0, 5, 5, tocolor ( 0, 0, 0, 255 ), 1, "default-bold" ) end addEventHandler ( "onClientResourceStart", resourceRoot, onResourceStart ) addEventHandler ( "onClientPlayerRadioSwitch", root, makeRadioStayOff ) addEventHandler ( "onClientPlayerVehicleEnter", root, makeRadioStayOff ) bindKey ( "R", "down", toggleSong ) ty now I wanna just ask..How to make text "[RADIO]" color and "Radio swithched on/off" not same? Link to comment
Castillo Posted November 21, 2012 Share Posted November 21, 2012 Enable the colorCoded argument at dxDrawText and then use HEX colors. Link to comment
Reflex# Posted November 21, 2012 Author Share Posted November 21, 2012 Enable the colorCoded argument at dxDrawText and then use HEX colors. okay thanks 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