Jump to content

Vehicle radio, off


ReGo

Recommended Posts

radio = 0 
 
lawVehicles = {596, 597, 598, 599, 407, 544, 601}
local totalStreams = 18 --Update this with the number of streams
local theTimer
local streams = { }
--Template: streams[Next Number In Order] = { "Link to Stream", "Name of Stream" }
streams[1] = {"http://relay.181.fm:8098", "87.9 - Salsa FM"}  
streams[2] = {"http://80.232.162.149:8000/spin96mp3", "90.0 FM - Spin FM"}
streams[3] = {"http://lr2mp1.latvijasradio.lv:8002", "91.5 FM - Latvijas Radio 2"}
streams[4] = {"http://195.13.200.164:8000", "91.9 FM - TOP Radio"}
streams[5] = {"http://www.larocca.lv:8000/larocca.m3u", "92.5 FM - LaRocca"}
streams[6] = {"http://195.3.145.11:9006/", "93.1 FM - PlayHard Radio"}  
streams[7] = {"http://listen.radionomy.com/goth-n-metal", "94.0 FM - Goth 'n' Metal"}
streams[8] = {"http://radio1.clubradio.lv:8000/live128", " 101.1 FM - Club Radio"}
streams[9] = {"http://play.russianradio.eu/", " 101.5 FM - Russian Radio"}
streams[10] = {"http://listen.radionomy.com/a2r-rap-us", "102.6 FM - A2R Rap US"}  
streams[11] = {"http://stream.europeanhitradio.com:8000/ehr64", "104.3 FM - Eiropas Hitu Radio"}
streams[12] = {"http://80.232.162.149:8000/swh96mp3", "105.2 FM - SWH"}
streams[13] = {"http://72.13.91.147:8000", " 106.2 FM - Dubstep Radio"}
streams[14] = {"http://skonto.ls.lv:8002/mp3", "107.2 FM - Radio Skonto"}
streams[15] = {"http://mms-live.online.no/p4_nrj_mp3_hq", "107.5 FM - NRJ HMO FM"}
streams[16] = {"http://blackbeats.fm/listen.asx", "107.6 FM - Beats FM"}
streams[17] = {"http://relay.181.fm:8034", "107.7 FM - Country FM"}
streams[18] = {"http://radio2.capitalfm.lv:8000/listen.pls", "107.9 FM - Capital FM"}
streams[19] = {"http://relay.181.fm:8068","181.2 - Old School 181 FM"}
streams[20] = {"http://relay.181.fm:8132", "181.5 - Oldies 181 FM"}
streams[21] = {"http://108.61.73.119:8054", "106.2 FM - The Beat"}
local soundElement = nil
local soundElementsOutside = { }
 
function check(thePlayer)
    outputChatBox(getElementData(getLocalPlayer(), "streams"), 255, 0, 0)
end
addCommandHandler("checkme", check, false, false)
 
function setVolume(commandname, val)
    if tonumber(val) then
        val = tonumber(val)
        if (tonumber(val) >= 0 and tonumber(val) <= 100) then
            triggerServerEvent("car:radio:vol", getLocalPlayer(), tonumber(val))
            outputChatBox("Radio skaļums nomainīts uz: "..tonumber(val).."%")
            return
        end
    end
    outputChatBox("Nē.")
end
addCommandHandler("setvol", setVolume)
 
local textShowing = false
function showStation()
    local screenwidth, screenheight = guiGetScreenSize ()
    local width = 300
    local height = 100
    local x = (screenwidth - width)/2
    local y = screenheight - (screenheight/8 - (height/8))
    local meta = getSoundMetaTags(source)   
    local theVehicle = getPedOccupiedVehicle(getLocalPlayer())
    if (theVehicle) then
        local streamID = getElementData(theVehicle, "vehicle:radio")
        local streamTitle
        if tonumber(streamID) ~= 0 then
            streamTitle = streams[tonumber(streamID)][2]
        else
            streamTitle = "Radio ir atslēgts"
        end
        dxDrawText (streamTitle, 46, screenheight - 41, screenwidth, screenheight, tocolor ( 0, 0, 0, 255 ), 0.6, "bankgothic" )
        dxDrawText (streamTitle, 44, screenheight - 43, screenwidth, screenheight, tocolor ( 255, 255, 255, 255 ), 0.6, "bankgothic" )
    end
end
 
 
 
function saveRadio(station)
    local radios = 0
    if (station == 0) then
        return
    end
   
   
    if exports.vgscoreboard:isVisible() then
        cancelEvent()
        return
    end
    local vehicle = getPedOccupiedVehicle(getLocalPlayer())
    local modelid = getElementModel(vehicle)
    for k, v in ipairs(lawVehicles) do
        if v == modelid then
            radio = 0
            outputChatBox("Smieklīgi... Tavs magnetafons ir aizstāts ar rācijas iekārtu.", 255, 0, 0)
            cancelEvent()
            return
        end
    end
    if getVehicleType(vehicle) == "BMX" or getVehicleType(vehicle) == "Bike" or getVehicleType(vehicle) == "Quad" then 
    cancelEvent()
        outputChatBox("Šim transportlīdzeklim nav radio!", player, 255, 0, 0)
        return
    end
   
    if (vehicle) then
        if getVehicleOccupant(vehicle) == getLocalPlayer() or getVehicleOccupant(vehicle, 1) == getLocalPlayer() then
            if not getVehicleEngineState(vehicle) then
            cancelEvent()
                outputChatBox("Radio ekrāns ir tumšs, varbūt tas nav ieslēgts? ((Transportlīdzekļa dzinējs nav iedarbināts.))", 255, 0, 0)
                radio = 0
                return
            end
                        if (station == 12) then 
                if (radio == 0) then
                    radio = #streams + 1
                end
               
                if (streams[radio-1]) then
                    radio = radio-1
                else
                    radio = 0
                end
            elseif (station == 1) then
                if (streams[radio+1]) then
                    radio = radio+1
                else
                    radio = 0
                end
            end
            if not textShowing then
                addEventHandler("onClientRender", getRootElement(), showStation)
                if (isTimer(theTimer)) then
                    resetTimer(theTimer)
                else
                    theTimer = setTimer(removeTheEvent, 10000, 1)
                end
                textShowing = true
            else
                removeEventHandler("onClientRender", getRootElement(), showStation)
                addEventHandler("onClientRender", getRootElement(), showStation)
                if (isTimer(theTimer)) then
                    resetTimer(theTimer)
                else
                    theTimer = setTimer(removeTheEvent, 10000, 1)
                end
            end
            triggerServerEvent("car:radio:sync", getLocalPlayer(), radio)
        end
        cancelEvent()
    end
end
addEventHandler("onClientPlayerRadioSwitch", getLocalPlayer(), saveRadio)
 
addEventHandler("onClientPlayerVehicleEnter", getLocalPlayer(),
    function(theVehicle)
        stopStupidRadio()
        radio = getElementData(theVehicle, "vehicle:radio") or 0
        updateLoudness(theVehicle)
    end
)
 
addEventHandler("onClientPlayerVehicleExit", getLocalPlayer(),
    function(theVehicle)
        stopStupidRadio()
        radio = getElementData(theVehicle, "vehicle:radio") or 0
        updateLoudness(theVehicle)
    end
)
 
function stopStupidRadio()
    removeEventHandler("onClientPlayerRadioSwitch", getLocalPlayer(), saveRadio)
    setRadioChannel(0)
    addEventHandler("onClientPlayerRadioSwitch", getLocalPlayer(), saveRadio)
end
 
addEventHandler ( "onClientElementDataChange", getRootElement(),
    function ( dataName )
        if getElementType ( source ) == "vehicle" and dataName == "vehicle:radio" then
            local enableStreams = getElementData(getLocalPlayer(), "streams")
            if enableStreams == 1 then
                local newStation =  getElementData(source, "vehicle:radio") or 0
                if (isElementStreamedIn (source)) then
                    if newStation ~= 0 then
                        if (soundElementsOutside[source]) then
                            stopSound(soundElementsOutside[source])
                        end
                        local x, y, z = getElementPosition(source)
                       
                        newSoundElement = playSound3D(streams[newStation][1], x, y, z, true)
                        soundElementsOutside[source] = newSoundElement
                        updateLoudness(source)
                        setElementDimension(newSoundElement, getElementDimension(source))
                        setElementDimension(newSoundElement, getElementDimension(source))
                       
                    else
                        if (soundElementsOutside[source]) then
                            stopSound(soundElementsOutside[source])
                            soundElementsOutside[source] = nil
                        end
                    end
                end
            end
        elseif getElementType(source) == "vehicle" and dataName == "vehicle:windowstat" then
            if (isElementStreamedIn (source)) then
                if (soundElementsOutside[source]) then
                    updateLoudness(source)
                end
            end
        elseif getElementType(source) == "vehicle" and dataName == "vehicle:radio:volume" then
            if (isElementStreamedIn (source)) then
                if (soundElementsOutside[source]) then
                    updateLoudness(source)
                end
            end
        end
       
        --
    end
)
 
addEventHandler( "onClientPreRender", getRootElement(),
    function()
        if soundElementsOutside ~= nil then
            for element, sound in pairs(soundElementsOutside) do
                if (isElement(sound) and isElement(element)) then
                    local x, y, z = getElementPosition(element)
                    setElementPosition(sound, x, y, z)
                    setElementInterior(sound, getElementInterior(element))
                    getElementDimension(sound, getElementDimension(element))
                end
            end
        end
    end 
)
 
addEventHandler("onClientResourceStart", getResourceRootElement(getThisResource()),
    function() 
        local vehicles = getElementsByType("vehicle")
        for _, theVehicle in ipairs(vehicles) do
            if (isElementStreamedIn(theVehicle)) then
                spawnSound(theVehicle)
            end
        end
    end
)
 
addEventHandler("onClientResourceStop", getResourceRootElement(getThisResource()),
    function() 
        local vehicles = getElementsByType("vehicle")
        for _, theVehicle in ipairs(vehicles) do
            if (isElementStreamedIn(theVehicle)) then
                spawnSound(theVehicle)
            end
        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...