Jump to content

radio not work :(


Electrosumm

Recommended Posts

function radiobekapcsol () 
local jatekosautoban = getPlayerName ( localPlayer ) 
  
  
        radiomegy = not radiomegy 
        if radiomegy  
        then mozgat = true 
        if (jatekosautoban) then 
            if isPedInVehicle (jatekosautoban) then 
            setSoundVolume(stream, 1) 
            outputChatBox("#00FF00Bekapcsoltad/Kikapcsoltad a rádiót!#00FF00", 255, 255, 255, true) 
            else 
            mozgat = false 
            setSoundVolume(stream, 0) 
            outputChatBox("#8B1A1ANem vagy autóban!#8B1A1A", 255, 255, 255, true) 
            end 
        end 
    end 
end 

its from my radio script but i have problem with it...i can only switch off the radio but cant swtich on.

and debugscript said it : lua 16 bad argument 'isPedInVehicle (expected ped at argument 1 got string myname.

help me :o

and the last question is how can i do it ? : the radio switch on only keybind cause when i join the radio turn on...i use keybind + addEventHandler("onClientRender"

Link to comment
  • Moderators

Here is how your code should look like (read the comments):

local radiomegy = false -- radio isn't playing 
function radiobekapcsol () 
    if not radiomegy then -- if the radio is not playing then 
        if isPedInVehicle (localPlayer) then -- if the local player is in a vehicle then 
            playRadio() -- start the radio 
        else 
            outputChatBox("#8B1A1ANem vagy autóban!#8B1A1A", localPlayer, 255, 255, 255, true) 
        end 
    else -- if the radio is playing then 
        stopRadio() -- stop the radio 
    end 
end 
  
function playRadio() 
    setSoundVolume(stream, 1) -- set the volume to 1 
    outputChatBox("#00FF00Bekapcsoltad a rádiót !#00FF00", localPlayer, 255, 255, 255, true) 
    radiomegy = true -- the radio is started 
end 
  
function stopRadio() 
    setSoundVolume(stream, 0) -- set the volume to 0 
    outputChatBox("#00FF00Kikapcsoltad a rádiót !#00FF00", localPlayer, 255, 255, 255, true) 
    radiomegy = false -- the radio is stopped 
end 
  
addEventHandler("onClientPlayerVehicleExit", localPlayer, stopRadio) -- calls stopRadio after the local player exited a vehicle 

Link to comment
  • Moderators

Yeah, the logic was not really clear so I kinda wrote down exactly when the radio should be turned on and when it should be turned off. I wrote two seperate functions to turn it on and off, and then I just had to call them exactly when I wanted to.

Very very thanks

No problem ;)

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