Jump to content

Userdata value error in a table


Mimimiguel

Recommended Posts

Hello all, at first thanks for read it, another of my noobish questions, this:

  
function actualizarPosicionSonido( sound, vehicle ) 
    if sound and vehicle then 
    x, y, z = getElementPosition( vehicle ) 
    setElementPosition( sound, x, y, z ) 
    end 
end 
  
function getSoundPath( id ) 
    if id == 1 then return "http://salvajefm.com/modules/mod_ngs_shoutcast/singleplaylist.php?ip=94.75.209.28&port=8188&format=ASX" 
    elseif id == 2 then return "http://194.169.201.177:8085/live3.mp3" 
    elseif id == 3 then return "http://194.169.201.177:8085/liveDial.mp3"  
    elseif id == 4 then return "http://194.169.201.177:8085/liveser.mp3" 
    elseif id == 5 then return "http://rtve.stream.flumotion.com/rtve/radio1.mp3.m3u" 
    elseif id == 7 then return "http://streaming.tst.es/stcasx/va90winlive2001/play.asx" 
    end 
end 
  
sound = { [1] = {}, [2] = {}, [3] = {}, [4] = {}, [5] = {}, [6] = {}} 
  
addEvent( "playsound", true ) 
addEventHandler( "playsound", getRootElement(), function( veh, id, player ) 
    if getElementData( player, "radio" ) == false then 
    x, y, z = getElementPosition( veh ) 
    path = getSoundPath( id ) 
    sound[ player ] = playSound3D( path, x, y, z, false ) 
    sound[1] = path 
    sound[2] = x 
    sound[3] = y 
    sound[4] = z 
    sound[5] = guiScrollBarGetScrollPosition (volumebar) / 50 
    sound[6] = setTimer( actualizarPosicionSonido, 50, 0, sound[player], getPedOccupiedVehicle( player ) ) 
    setSoundMaxDistance( sound[player], maxdistance ) 
    setElementData( player, "radio", true ) 
    setSoundVolume( sound[player], sound[5] or 1 ) 
    else 
    stopSound( sound[ player ] ) 
    sound[ player ] = nil 
    sound[1] = nil 
    sound[2] = nil 
    sound[3] = nil 
    sound[4] = nil 
    sound[5] = nil 
    killTimer( sound[6] ) 
    sound[6] = nil 
    setElementData( player, "radio", false ) 
    end 
end 
) 

returns:

'attempt to index global 'sound' ( a userdata value )'

I did never had a error of this kind before so I don't know whats going on here :/

Link to comment

Try this:

function actualizarPosicionSonido( sound, vehicle ) 
    if sound and vehicle then 
    x, y, z = getElementPosition( vehicle ) 
    setElementPosition( sound, x, y, z ) 
    end 
end 
  
function getSoundPath( id ) 
    if id == 1 then return "http://salvajefm.com/modules/mod_ngs_shoutcast/singleplaylist.php?ip=94.75.209.28&port=8188&format=ASX" 
    elseif id == 2 then return "http://194.169.201.177:8085/live3.mp3" 
    elseif id == 3 then return "http://194.169.201.177:8085/liveDial.mp3" 
    elseif id == 4 then return "http://194.169.201.177:8085/liveser.mp3" 
    elseif id == 5 then return "http://rtve.stream.flumotion.com/rtve/radio1.mp3.m3u" 
    elseif id == 7 then return "http://streaming.tst.es/stcasx/va90winlive2001/play.asx" 
    end 
end 
  
sound = {} 
  
addEvent( "playsound", true ) 
addEventHandler( "playsound", getRootElement(), function( veh, id, player ) 
    if getElementData( player, "radio" ) == false then 
    x, y, z = getElementPosition( veh ) 
    path = getSoundPath( id ) 
    sound[player] = {} 
    sound[player].theSound = playSound3D( path, x, y, z, false ) 
    sound[player].path = path 
    sound[player].x = x 
    sound[player].y = y 
    sound[player].z = z 
    if volumebar then volume = guiScrollBarGetScrollPosition (volumebar) / 50 else volume = 2.5 end 
    sound[player].volume = volume 
    sound[player].timer = setTimer( actualizarPosicionSonido, 50, 0, sound[player].theSound, getPedOccupiedVehicle( player ) ) 
    setSoundMaxDistance( sound[player], maxdistance ) 
    setElementData( player, "radio", true ) 
    setSoundVolume( sound[player], sound[5] or 1 ) 
    else 
    stopSound( sound[ player ] ) 
    killTimer( sound[player].timer ) 
    sound[ player ] = nil 
    setElementData( player, "radio", false ) 
    end 
end 
) 

Link to comment
addEvent( "radio", true ) 
addEventHandler( "radio", getRootElement(), function ( sound ) 
    if isPedInVehicle( source ) then 
    veh = getPedOccupiedVehicle( source ) 
    triggerClientEvent( "playsound", getRootElement(), veh, sound, source ) 
    end 
end 
) 
addEvent( "OnCharacterLogin", true ) 
addEventHandler( "OnCharacterLogin", getRootElement(), function ()  
    triggerClientEvent( "sync", source ) 
end 
) 

Link to comment
function actualizarPosicionSonido( sound, vehicle ) 
    if sound and vehicle then 
    x, y, z = getElementPosition( vehicle ) 
    setElementPosition( sound, x, y, z ) 
    end 
end 
  
function getSoundPath( id ) 
    if id == 1 then return "http://salvajefm.com/modules/mod_ngs_shoutcast/singleplaylist.php?ip=94.75.209.28&port=8188&format=ASX" 
    elseif id == 2 then return "http://194.169.201.177:8085/live3.mp3" 
    elseif id == 3 then return "http://194.169.201.177:8085/liveDial.mp3" 
    elseif id == 4 then return "http://194.169.201.177:8085/liveser.mp3" 
    elseif id == 5 then return "http://rtve.stream.flumotion.com/rtve/radio1.mp3.m3u" 
    elseif id == 7 then return "http://streaming.tst.es/stcasx/va90winlive2001/play.asx" 
    end 
end 
  
sound = {} 
  
addEvent( "playsound", true ) 
addEventHandler( "playsound", getRootElement(), function( veh, id, player ) 
    if getElementData( player, "radio" ) == false then 
    outputChatBox(tostring(id)) 
    outputChatBox(tostring(getPlayerName(player))) 
    x, y, z = getElementPosition( veh ) 
    path = getSoundPath( id ) 
    sound[player] = {} 
    sound[player].theSound = playSound3D( path, x, y, z, false ) 
    sound[player].path = path 
    sound[player].x = x 
    sound[player].y = y 
    sound[player].z = z 
    if volumebar then volume = guiScrollBarGetScrollPosition (volumebar) / 50 else volume = 2.5 end 
    sound[player].volume = volume 
    sound[player].timer = setTimer( actualizarPosicionSonido, 50, 0, sound[player].theSound, getPedOccupiedVehicle( player ) ) 
    setSoundMaxDistance( sound[player], maxdistance ) 
    setElementData( player, "radio", true ) 
    setSoundVolume( sound[player], sound[5] or 1 ) 
    else 
    stopSound( sound[ player ] ) 
    killTimer( sound[player].timer ) 
    sound[ player ] = nil 
    setElementData( player, "radio", false ) 
    end 
end 
) 

Tell me if it outputs the sound ID and the player name to chatbox.

Link to comment

Thanks for the effort, solidsnake, :)

if any other knows how to solve this, please post it. Thanks in advice.

Also changed something and the error changed also, here it is the code:

    addEvent( "playsound", true ) 
    addEventHandler( "playsound", getRootElement(), function( veh, id, player ) 
        if getElementData( player, "radio" ) == false then 
        sound = {} 
        data = sound[ player ] 
        outputDebugString(tostring(id)) 
        outputDebugString(tostring(getPlayerName(player)).." inició la radio") 
        x, y, z = getElementPosition( veh ) 
        path = getSoundPath( id ) 
        data.theSound = playSound3D( path, x, y, z, false ) 
        data.path = path 
        data.x = x 
        data.y = y 
        data.z = z 
        if volumebar then volume = guiScrollBarGetScrollPosition (volumebar) / 50 else volume = 2.5 end 
        data.volume = volume 
        data.timer = setTimer( actualizarPosicionSonido, 50, 0, data.theSound, getPedOccupiedVehicle( player ) ) 
        setSoundMaxDistance( data, maxdistance ) 
        setElementData( player, "radio", true ) 
        setSoundVolume( sound[player], sound[5] or 1 ) 
        else 
        stopSound( sound[ veh ] ) 
        killTimer( data.timer ) 
        sound[ veh ] = nil 
        setElementData( player, "radio", false ) 
        end 
    end 
    ) 

Reports a nil value in the line 5

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