ScofieldX Posted October 10, 2015 Share Posted October 10, 2015 I have this small problem. It involves carradio that's the resource, Now here's my problem The car radio streams good when the engine is running, but when I turn the engine off, to save gas, the radio turns off, I'm not a scripter when it comes to .lua But if anyone can help me out with how to make the radio still play even when the engine is turned off that would be fantastic. Link to comment
ScofieldX Posted October 10, 2015 Author Share Posted October 10, 2015 (edited) Here's the tip end of what I'm talking about. function updateCarRadio() local state = getElementData(localPlayer, "streams") if (state == "0") then setRadioChannel(0) -- kill all radio channels for _, value in pairs(soundElementsOutside) do stopSound(value) end soundElementsOutside = {} -- kill the mp3 player if mp3Sound then stopSound(mp3Sound) mp3Sound = nil mp3Station = nil end else -- repopulate all radio channels local vehicles = getElementsByType("vehicle") for _, theVehicle in ipairs(vehicles) do if (isElementStreamedIn(theVehicle)) then spawnSound(theVehicle) end end end end addEvent("accounts:settings:updateCarRadio", false) addEventHandler("accounts:settings:updateCarRadio", getRootElement(), updateCarRadio) -- local mp3Window = nil local width, height = mp3_w, mp3_h function destroyMP3Window() if mp3Window then destroyElement(mp3Window) mp3Window = nil end end addEventHandler('onClientChangeChar', root, function() if mp3Sound then stopSound(mp3Sound) mp3Sound = nil mp3Station = nil end destroyMP3Window() end) function showMP3GUI() destroyMP3Window() mp3Window = guiCreateStaticImage(mp3_x, mp3_y, mp3_w, mp3_h, ":resources/window_body.png", false) local grid = guiCreateGridList(10, 10, width - 20, height - 50, false, mp3Window) local col = guiGridListAddColumn(grid, 'Station', 0.85) for k, v in ipairs(streams) do if k ~= 0 then local row = guiGridListAddRow(grid) guiGridListSetItemText(grid, row, col, v[1], false, false) guiGridListSetItemData(grid, row, col, tostring(k)) end end addEventHandler('onClientGUIClick', grid, function() local item = guiGridListGetSelectedItem(grid) if item ~= -1 then local station = tonumber(guiGridListGetItemData(grid, item, col)) if mp3Sound then stopSound(mp3Sound) mp3Sound = nil end mp3Sound = playSound(streams[station][2], true) mp3Station = station end end, false) local off = guiCreateButton(10, height - 35, 85, 25, 'Turn Off', false, mp3Window) addEventHandler('onClientGUIClick', off, function() if mp3Sound then stopSound(mp3Sound) mp3Sound = nil mp3Station = nil end end, false) local close = guiCreateButton(105, height - 35, 85, 25, 'Close', false, mp3Window) addEventHandler('onClientGUIClick', close, destroyMP3Window, false) end addEvent('realism:mp3:off', true) addEventHandler('realism:mp3:off', root, function() if mp3Sound then stopSound(mp3Sound) mp3Sound = nil mp3Station = nil end end) Edited October 10, 2015 by Guest Link to comment
ScofieldX Posted October 10, 2015 Author Share Posted October 10, 2015 Use . Ah thanks, and it's edited, thanks again man. 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