Jump to content

[HELP]Radio script


Reflex#

Recommended Posts

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

Please help any1 if you can

Link to comment
  • Other Languages Moderators

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
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
  • MTA Team

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
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
  • MTA Team
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 by Guest
Link to comment
  • Other Languages Moderators
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
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
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
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
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

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

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