Jump to content

A Bug and A little help..


justn

Recommended Posts

The Bug Is I have this radio script and the problem is that when the player is in a vehicle, sometimes the radio stations gets removed automatically, fix this problem ty ! :D and i need a little help, so i can hear the music playing from another player's car when im outside of a vehicle

addEventHandler("onClientPlayerVehicleEnter", getRootElement(), 
    function(thePlayer,seat) 
    if seat == 0 then 
        setRadioChannel(0) 
        local x, y = guiGetScreenSize() 
        addEventHandler("onClientRender",root,function() 
        if isPedInVehicle(localPlayer) then 
        dxradio = dxDrawText("Song Name: "..title, x*0.299, y*0.778, x*0.599, y*0.800, tocolor(255, 255, 255, 255), 1.00, "default-bold", "left", "top", false, false, true, false, false) 
        dxtitle = dxDrawText("Radio: "..tostring(radiotitle), x*0.299, y*0.757, x*0.599, y*0.778, tocolor(255, 255, 255, 255), 1.00, "default-bold", "left", "top", false, false, true, false, false) 
        --1024x768 
        else 
        if dxradio then 
        destroyElement(dxradio) 
        destroyElement(dxtitle) 
        end 
        end 
        end) 
            bindKey("mouse_wheel_up", "down", function() 
                    setRadioChannel(0) 
                    local xp,yp,zp = getElementPosition(thePlayer) 
                    if tonumber(n) ~= 6 then 
                                                    destroyElement(sound) 
                                        n = n+1 
                      sound = playSound3D( radios[n][1],xp,yp,zp ) 
                      radiotitle = radios[n][2] 
                            attachElements(sound, thePlayer) 
                    end 
            end) 
                        bindKey("mouse_wheel_down", "down", function() 
                                setRadioChannel(0) 
                    local xp,yp,zp = getElementPosition(thePlayer) 
                    if tonumber(n) ~= 1 then 
                     
            destroyElement(sound) 
                    n = n-1 
                          sound = playSound3D( radios[n][1],xp,yp,zp ) 
                          radiotitle = radios[n][2] 
                            attachElements(sound, thePlayer) 
                    end 
            end) 
    end 
    end 
    ) 
     
    function stopMySound(player,seat) 
    if ( player == localPlayer ) then 
    destroyElement( sound ) 
    n = 0 
end 
end 
addEventHandler("onClientPlayerVehicleExit",getRootElement(),stopMySound) 

Link to comment

Its pretty messed up, try this:

  
function onPlayerEnterVehicle(thePlayer,seat) 
    if seat == 0 then 
        setRadioChannel(0) 
        addEventHandler("onClientRender", getRootElement(), RenderClient) 
        bindKey("mouse_wheel_up", "down", PlaySound, "up") 
        bindKey("mouse_wheel_down", "down", PlaySound, "down") 
    end 
    end 
addEventHandler("onClientPlayerVehicleEnter", getRootElement(), onPlayerEnterVehicle) 
    
function stopMySound(player,seat) 
if ( player == localPlayer ) then 
stopSound( sound ) 
removeEventHandler("onClientRender", getRootElement(), RenderClient) 
unbindKey("mouse_wheel_up", "down", PlaySound) 
unbindKey("mouse_wheel_down", "down", PlaySound) 
n = 0 
end 
end 
addEventHandler("onClientPlayerVehicleExit",getRootElement(),stopMySound) 
  
function RenderClient() 
if isPedInVehicle(localPlayer) then 
dxDrawText("Song Name: "..title, x*0.299, y*0.778, x*0.599, y*0.800, tocolor(255, 255, 255, 255), 1.00, "default-bold", "left", "top", false, false, true, false, false) 
dxDrawText("Radio: "..tostring(radiotitle), x*0.299, y*0.757, x*0.599, y*0.778, tocolor(255, 255, 255, 255), 1.00, "default-bold", "left", "top", false, false, true, false, false) 
end 
end 
  
function PlaySound(state) 
local x,y,z = getElementPosition(getLocalPlayer()) 
n = tonumber(n) 
if sound then 
stopSound(sound) 
end 
if state == "up" then 
n = n + 1 
if n == 6 then 
n = 1 
end 
elseif state == "down" then 
n = n - 1 
if n == 0 then 
n = 1 
end 
end 
local n = tonumber(n) 
sound = playSound3D(radios[n][1], x,y,z) 
radiotitle = radios[n][2] 
end 
  
function UpadteSound() 
if sound then 
local x,y,z = getElementPosition(getLocalPlayer()) 
setElementPosition(sound, x,y,z) 
end 
end 
addEventHandler("onClientRender", getRootElement(), UpdateSound) 
  

PD: it will also stop you from going to any higher value of N than 6, or any lower one than 1. (it will just re-play the lowest/highest)

Link to comment

I don't see the difference really. Because it does the same thing as my code, it plays, when i am on one radio station, and i switch, most of the radio stations gets deleted :/ i dont know why really .. theres only 1 radio station which stays , but all the others , deleted.

Link to comment
local radios = { 
    {"None","None",6}, 
    {"http://mp3uplink.duplexfx.com:8054/listen.pls","West Coast Rap",5}, 
    {"http://somafm.com/dubstep.pls","Dubstep",4}, 
    {"http://www.181.fm/winamp.pls?station=181-power&style=mp3&description=Power%20181%20(Top%2040)&file=181-power.pls","Power 181",3}, 
    {"http://193.34.51.25/listen.pls","rauteMusik.",2}, 
    {"http://212.45.104.34:8042/listen.pls","defjay",1} 
} 

Link to comment

could you try this? tell me what outputchatbox says

  
function onPlayerEnterVehicle(thePlayer,seat) 
    if seat == 0 then 
        setRadioChannel(0) 
        addEventHandler("onClientRender", getRootElement(), RenderClient) 
        bindKey("mouse_wheel_up", "down", PlaySound, "up") 
        bindKey("mouse_wheel_down", "down", PlaySound, "down") 
    end 
    end 
addEventHandler("onClientPlayerVehicleEnter", getRootElement(), onPlayerEnterVehicle) 
    
function stopMySound(player,seat) 
if ( player == localPlayer ) then 
stopSound( sound ) 
removeEventHandler("onClientRender", getRootElement(), RenderClient) 
unbindKey("mouse_wheel_up", "down", PlaySound) 
unbindKey("mouse_wheel_down", "down", PlaySound) 
n = 0 
end 
end 
addEventHandler("onClientPlayerVehicleExit",getRootElement(),stopMySound) 
  
function RenderClient() 
if isPedInVehicle(localPlayer) then 
dxDrawText("Song Name: "..title, x*0.299, y*0.778, x*0.599, y*0.800, tocolor(255, 255, 255, 255), 1.00, "default-bold", "left", "top", false, false, true, false, false) 
dxDrawText("Radio: "..tostring(radiotitle), x*0.299, y*0.757, x*0.599, y*0.778, tocolor(255, 255, 255, 255), 1.00, "default-bold", "left", "top", false, false, true, false, false) 
end 
end 
  
function PlaySound(state) 
local x,y,z = getElementPosition(getLocalPlayer()) 
n = tonumber(n) 
if sound then 
stopSound(sound) 
end 
if state == "up" then 
n = n + 1 
if n == 6 then 
n = 1 
end 
elseif state == "down" then 
n = n - 1 
if n == 0 then 
n = 1 
end 
end 
local n = tonumber(n) 
sound = playSound3D(radios[n][1], x,y,z) 
outputChatBox("Stream: "..radios[n][1]) 
outputChatBox("Title: "..radios[n][2]) 
radiotitle = radios[n][2] 
end 
  
function UpadteSound() 
if sound then 
local x,y,z = getElementPosition(getLocalPlayer()) 
setElementPosition(sound, x,y,z) 
end 
end 
addEventHandler("onClientRender", getRootElement(), UpdateSound) 
  

Link to comment

Then there's two possibilities, either your table is not indexed, or n is bad.

  
function onPlayerEnterVehicle(thePlayer,seat) 
    if seat == 0 then 
        setRadioChannel(0) 
        addEventHandler("onClientRender", getRootElement(), RenderClient) 
        bindKey("mouse_wheel_up", "down", PlaySound, "up") 
        bindKey("mouse_wheel_down", "down", PlaySound, "down") 
    end 
    end 
addEventHandler("onClientPlayerVehicleEnter", getRootElement(), onPlayerEnterVehicle) 
    
function stopMySound(player,seat) 
if ( player == localPlayer ) then 
stopSound( sound ) 
removeEventHandler("onClientRender", getRootElement(), RenderClient) 
unbindKey("mouse_wheel_up", "down", PlaySound) 
unbindKey("mouse_wheel_down", "down", PlaySound) 
n = 0 
end 
end 
addEventHandler("onClientPlayerVehicleExit",getRootElement(),stopMySound) 
  
function RenderClient() 
if isPedInVehicle(localPlayer) then 
dxDrawText("Song Name: "..title, x*0.299, y*0.778, x*0.599, y*0.800, tocolor(255, 255, 255, 255), 1.00, "default-bold", "left", "top", false, false, true, false, false) 
dxDrawText("Radio: "..tostring(radiotitle), x*0.299, y*0.757, x*0.599, y*0.778, tocolor(255, 255, 255, 255), 1.00, "default-bold", "left", "top", false, false, true, false, false) 
end 
end 
  
function PlaySound(state) 
local x,y,z = getElementPosition(getLocalPlayer()) 
n = tonumber(n) 
if sound then 
stopSound(sound) 
end 
if state == "up" then 
n = n + 1 
if n == 6 then 
n = 1 
end 
elseif state == "down" then 
n = n - 1 
if n == 0 then 
n = 1 
end 
end 
local n = tonumber(n) 
outputChatBox(n) 
sound = playSound3D(radios[1][1], x,y,z) 
outputChatBox("Stream: "..radios[1][1]) 
outputChatBox("Title: "..radios[1][2]) 
radiotitle = radios[n][2] 
end 
  
function UpadteSound() 
if sound then 
local x,y,z = getElementPosition(getLocalPlayer()) 
setElementPosition(sound, x,y,z) 
end 
end 
addEventHandler("onClientRender", getRootElement(), UpdateSound) 

Try that

Link to comment

here's the entire code

n = 0 
local radios = { 
    {"None","None",6}, 
    {"http://mp3uplink.duplexfx.com:8054/listen.pls","West Coast Rap",5}, 
    {"http://somafm.com/dubstep.pls","Dubstep",4}, 
    {"http://www.181.fm/winamp.pls?station=181-power&style=mp3&description=Power%20181%20(Top%2040)&file=181-power.pls","Power 181",3}, 
    {"http://193.34.51.25/listen.pls","rauteMusik.",2}, 
    {"http://212.45.104.34:8042/listen.pls","defjay",1} 
} 
title = "Radio Off" 
addEventHandler("onClientSoundChangedMeta", root, function(streamTitle) 
title = streamTitle 
end) 
addEventHandler("onClientSoundStream",root,function(suc,length,streamN) 
title = streamN 
end) 
  
  
  
  
function onPlayerEnterVehicle(thePlayer,seat) 
    if seat == 0 then 
        setRadioChannel(0) 
        addEventHandler("onClientRender", getRootElement(), RenderClient) 
        bindKey("mouse_wheel_up", "down", PlaySound, "up") 
        bindKey("mouse_wheel_down", "down", PlaySound, "down") 
    end 
    end 
addEventHandler("onClientPlayerVehicleEnter", getRootElement(), onPlayerEnterVehicle) 
    
function stopMySound(player,seat) 
if ( player == localPlayer ) then 
stopSound( sound ) 
removeEventHandler("onClientRender", getRootElement(), RenderClient) 
unbindKey("mouse_wheel_up", "down", PlaySound) 
unbindKey("mouse_wheel_down", "down", PlaySound) 
n = 0 
end 
end 
addEventHandler("onClientPlayerVehicleExit",getRootElement(),stopMySound) 
  
function RenderClient() 
if isPedInVehicle(localPlayer) then 
local x,y = guiGetScreenSize() 
dxDrawText("Song Name: "..title, x*0.299, y*0.778, x*0.599, y*0.800, tocolor(255, 255, 255, 255), 1.00, "default-bold", "left", "top", false, false, true, false, false) 
dxDrawText("Radio: "..tostring(radiotitle), x*0.299, y*0.757, x*0.599, y*0.778, tocolor(255, 255, 255, 255), 1.00, "default-bold", "left", "top", false, false, true, false, false) 
end 
end 
  
function PlaySound(state) 
local x,y,z = getElementPosition(getLocalPlayer()) 
n = tonumber(n) 
if sound then 
stopSound(sound) 
end 
if state == "up" then 
n = n + 1 
if n == 6 then 
n = 1 
end 
elseif state == "down" then 
n = n - 1 
if n == 0 then 
n = 1 
end 
end 
local n = tonumber(n) 
outputChatBox(n) 
sound = playSound3D(radios[1][1], x,y,z) 
outputChatBox("Stream: "..radios[1][1]) 
outputChatBox("Title: "..radios[1][2]) 
radiotitle = radios[n][2] 
end 
  
function UpdateSound() 
if sound then 
local x,y,z = getElementPosition(getLocalPlayer()) 
setElementPosition(sound, x,y,z) 
end 
end 
addEventHandler("onClientRender", getRootElement(), UpdateSound) 

Link to comment

Why you have a number at the end of each table?

just tell me what it says, n should be a number and the rest work, else you're doing something wrong. (try removing the number at the end of each table, its pointless since the only ways you're using it is by directly reaching it, you know whats the value, or by table, where you also know the value.)

Link to comment
local radios = { 
    [1] =  {"None","None"}, 
    [2] = {"http://mp3uplink.duplexfx.com:8054/listen.pls","West Coast Rap"}, 
    [3] = {"http://somafm.com/dubstep.pls","Dubstep"}, 
    [4] = {"http://www.181.fm/winamp.pls?station=181-power&style=mp3&description=Power%20181%20(Top%2040)&file=181-power.pls","Power 181"}, 
    [5] = {"http://193.34.51.25/listen.pls","rauteMusik."}, 
    [6] = {"http://212.45.104.34:8042/listen.pls","defjay"} 
} 

Tried that and the error was

ERROR: radio\client.lua:72: attempt to index field '?' (a nil value)

__

Also tried this table below and the error was the same thing ..

local radios = { 
    {1,"None","None"}, 
    {2,"http://mp3uplink.duplexfx.com:8054/listen.pls","West Coast Rap"}, 
    {3,"http://somafm.com/dubstep.pls","Dubstep"}, 
    {4,"http://www.181.fm/winamp.pls?station=181-power&style=mp3&description=Power%20181%20(Top%2040)&file=181-power.pls","Power 181"}, 
    {5,"http://193.34.51.25/listen.pls","rauteMusik."}, 
    {6,"http://212.45.104.34:8042/listen.pls","defjay"} 
} 

Link to comment

No. Thats basically an error saying the number wasnt recognized, as lines before having a number were passed correctly.

Try this:

n = 0 
local radios = { 
    {"None","None",6}, 
    {"http://mp3uplink.duplexfx.com:8054/listen.pls","West Coast Rap",5}, 
    {"http://somafm.com/dubstep.pls","Dubstep",4}, 
    {"http://www.181.fm/winamp.pls?station=181-power&style=mp3&description=Power%20181%20(Top%2040)&file=181-power.pls","Power 181",3}, 
    {"http://193.34.51.25/listen.pls","rauteMusik.",2}, 
    {"http://212.45.104.34:8042/listen.pls","defjay",1} 
} 
title = "Radio Off" 
addEventHandler("onClientSoundChangedMeta", root, function(streamTitle) 
title = streamTitle 
end) 
addEventHandler("onClientSoundStream",root,function(suc,length,streamN) 
title = streamN 
end) 
  
  
  
  
function onPlayerEnterVehicle(thePlayer,seat) 
    if seat == 0 then 
        setRadioChannel(0) 
        addEventHandler("onClientRender", getRootElement(), RenderClient) 
        bindKey("mouse_wheel_up", "down", PlaySound, "up") 
        bindKey("mouse_wheel_down", "down", PlaySound, "down") 
    end 
    end 
addEventHandler("onClientPlayerVehicleEnter", getRootElement(), onPlayerEnterVehicle) 
    
function stopMySound(player,seat) 
if ( player == localPlayer ) then 
stopSound( sound ) 
removeEventHandler("onClientRender", getRootElement(), RenderClient) 
unbindKey("mouse_wheel_up", "down", PlaySound) 
unbindKey("mouse_wheel_down", "down", PlaySound) 
n = 0 
end 
end 
addEventHandler("onClientPlayerVehicleExit",getRootElement(),stopMySound) 
  
function RenderClient() 
if isPedInVehicle(localPlayer) then 
local x,y = guiGetScreenSize() 
dxDrawText("Song Name: "..title, x*0.299, y*0.778, x*0.599, y*0.800, tocolor(255, 255, 255, 255), 1.00, "default-bold", "left", "top", false, false, true, false, false) 
dxDrawText("Radio: "..tostring(radiotitle), x*0.299, y*0.757, x*0.599, y*0.778, tocolor(255, 255, 255, 255), 1.00, "default-bold", "left", "top", false, false, true, false, false) 
end 
end 
  
function PlaySound(state) 
local x,y,z = getElementPosition(getLocalPlayer()) 
n = tonumber(n) 
if sound then 
stopSound(sound) 
end 
if state == "up" then 
n = n + 1 
if n == 6 then 
n = 1 
end 
elseif state == "down" then 
n = n - 1 
if n == 0 then 
n = 1 
end 
end 
outputChatBox(n) 
local a = tonumber(n) 
sound = playSound3D(radios[a][1], x,y,z) 
outputChatBox("Stream: "..radios[a][1]) 
outputChatBox("Title: "..radios[a][2]) 
radiotitle = radios[a][2] 
end 
  
function UpdateSound() 
if sound then 
local x,y,z = getElementPosition(getLocalPlayer()) 
setElementPosition(sound, x,y,z) 
end 
end 
addEventHandler("onClientRender", getRootElement(), UpdateSound) 

Link to comment

what does this output?

  
n = 0 
local radios = { 
    {"None","None",6}, 
    {"http://mp3uplink.duplexfx.com:8054/listen.pls","West Coast Rap",5}, 
    {"http://somafm.com/dubstep.pls","Dubstep",4}, 
    {"http://www.181.fm/winamp.pls?station=181-power&style=mp3&description=Power%20181%20(Top%2040)&file=181-power.pls","Power 181",3}, 
    {"http://193.34.51.25/listen.pls","rauteMusik.",2}, 
    {"http://212.45.104.34:8042/listen.pls","defjay",1} 
} 
title = "Radio Off" 
addEventHandler("onClientSoundChangedMeta", root, function(streamTitle) 
title = streamTitle 
end) 
addEventHandler("onClientSoundStream",root,function(suc,length,streamN) 
title = streamN 
end) 
  
  
  
  
function onPlayerEnterVehicle(thePlayer,seat) 
    if seat == 0 then 
        setRadioChannel(0) 
        addEventHandler("onClientRender", getRootElement(), RenderClient) 
        bindKey("mouse_wheel_up", "down", PlaySound, "up") 
        bindKey("mouse_wheel_down", "down", PlaySound, "down") 
    end 
    end 
addEventHandler("onClientPlayerVehicleEnter", getRootElement(), onPlayerEnterVehicle) 
    
function stopMySound(player,seat) 
if ( player == localPlayer ) then 
stopSound( sound ) 
removeEventHandler("onClientRender", getRootElement(), RenderClient) 
unbindKey("mouse_wheel_up", "down", PlaySound) 
unbindKey("mouse_wheel_down", "down", PlaySound) 
n = 0 
end 
end 
addEventHandler("onClientPlayerVehicleExit",getRootElement(),stopMySound) 
  
function RenderClient() 
if isPedInVehicle(localPlayer) then 
local x,y = guiGetScreenSize() 
dxDrawText("Song Name: "..title, x*0.299, y*0.778, x*0.599, y*0.800, tocolor(255, 255, 255, 255), 1.00, "default-bold", "left", "top", false, false, true, false, false) 
dxDrawText("Radio: "..tostring(radiotitle), x*0.299, y*0.757, x*0.599, y*0.778, tocolor(255, 255, 255, 255), 1.00, "default-bold", "left", "top", false, false, true, false, false) 
end 
end 
  
function PlaySound(state) 
local x,y,z = getElementPosition(getLocalPlayer()) 
n = tonumber(n) 
if sound then 
stopSound(sound) 
end 
if state == "up" then 
n = n + 1 
if n == 6 then 
n = 1 
end 
elseif state == "down" then 
n = n - 1 
if n == 0 then 
n = 1 
end 
end 
outputChatBox(type(n)) 
local a = tonumber(n) 
sound = playSound3D(radios[a][1], x,y,z) 
outputChatBox("Stream: "..radios[a][1]) 
outputChatBox("Title: "..radios[a][2]) 
radiotitle = radios[a][2] 
end 
  
function UpdateSound() 
if sound then 
local x,y,z = getElementPosition(getLocalPlayer()) 
setElementPosition(sound, x,y,z) 
end 
end 
addEventHandler("onClientRender", getRootElement(), UpdateSound) 
  
  

Link to comment

Then there's something wrong with your code, it should work..

tell me exactly what this says:

  
n = 0 
local radios = { 
    {"None","None",6}, 
    {"http://mp3uplink.duplexfx.com:8054/listen.pls","West Coast Rap",5}, 
    {"http://somafm.com/dubstep.pls","Dubstep",4}, 
    {"http://www.181.fm/winamp.pls?station=181-power&style=mp3&description=Power%20181%20(Top%2040)&file=181-power.pls","Power 181",3}, 
    {"http://193.34.51.25/listen.pls","rauteMusik.",2}, 
    {"http://212.45.104.34:8042/listen.pls","defjay",1} 
} 
title = "Radio Off" 
addEventHandler("onClientSoundChangedMeta", root, function(streamTitle) 
title = streamTitle 
end) 
addEventHandler("onClientSoundStream",root,function(suc,length,streamN) 
title = streamN 
end) 
  
  
  
  
function onPlayerEnterVehicle(thePlayer,seat) 
    if seat == 0 then 
        setRadioChannel(0) 
        addEventHandler("onClientRender", getRootElement(), RenderClient) 
        bindKey("mouse_wheel_up", "down", PlaySound, "up") 
        bindKey("mouse_wheel_down", "down", PlaySound, "down") 
    end 
    end 
addEventHandler("onClientPlayerVehicleEnter", getRootElement(), onPlayerEnterVehicle) 
    
function stopMySound(player,seat) 
if ( player == localPlayer ) then 
stopSound( sound ) 
removeEventHandler("onClientRender", getRootElement(), RenderClient) 
unbindKey("mouse_wheel_up", "down", PlaySound) 
unbindKey("mouse_wheel_down", "down", PlaySound) 
n = 0 
end 
end 
addEventHandler("onClientPlayerVehicleExit",getRootElement(),stopMySound) 
  
function RenderClient() 
if isPedInVehicle(localPlayer) then 
local x,y = guiGetScreenSize() 
dxDrawText("Song Name: "..title, x*0.299, y*0.778, x*0.599, y*0.800, tocolor(255, 255, 255, 255), 1.00, "default-bold", "left", "top", false, false, true, false, false) 
dxDrawText("Radio: "..tostring(radiotitle), x*0.299, y*0.757, x*0.599, y*0.778, tocolor(255, 255, 255, 255), 1.00, "default-bold", "left", "top", false, false, true, false, false) 
end 
end 
  
function PlaySound(state) 
local x,y,z = getElementPosition(getLocalPlayer()) 
n = tonumber(n) 
if sound then 
stopSound(sound) 
end 
if state == "up" then 
n = n + 1 
if n == 6 then 
n = 1 
end 
elseif state == "down" then 
n = n - 1 
if n == 0 then 
n = 1 
end 
end 
outputChatBox(type(n)) 
outputChatBox(n) 
outputChatBox(radios[1][1]) 
outputChatBox(radios[n][1]) 
sound = playSound3D(radios[n][1], x,y,z) 
outputChatBox("Stream: "..radios[n][1]) 
outputChatBox("Title: "..radios[a][2]) 
radiotitle = radios[n][2] 
end 
  
function UpdateSound() 
if sound then 
local x,y,z = getElementPosition(getLocalPlayer()) 
setElementPosition(sound, x,y,z) 
end 
end 
addEventHandler("onClientRender", getRootElement(), UpdateSound) 

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