Jump to content

Attempt to index field '?' (a nil value)


golanu21

Recommended Posts

local tables = { 
[1]={-2421.69238, -582.35858, 133.61719, "Caine"}, 
} 
  
function renderIng(ID) 
    local x, y, z = getCameraMatrix( ) 
            local px, py, pz = tables[ID][1], tables[ID][2], tables[ID][3] 
            local distance = getDistanceBetweenPoints3D( px, py, pz, x, y, z ) 
            if distance <= 20 then 
                local text = tables[ID][4] 
                if text and ( distance < 2 or isLineOfSightClear( x, y, z, px, py, pz + 0.7, true, true, true, true, false, false, true, localPlayer ) ) then 
                    local sx, sy = getScreenFromWorldPosition( px, py, pz + 0.7 ) 
                    if sx and sy then 
                        local w = dxGetTextWidth( tostring( text ) ) 
                        local h = ( text and 2 or 1 ) * dxGetFontHeight( ) 
                        dxDrawText( tostring( text ), sx, sy, sx, sy, tocolor( 255, 255, 255, 255 ), 1, "default", "center", "center" ) 
                    end 
                end 
            end 
        end 
  
addEventHandler( "onClientRender", getRootElement( ),renderIng) 

7: Attempt to index field '?' (a nil value) 

Link to comment
function renderIng(ID) 
addEventHandler( "onClientRender", getRootElement( ),renderIng) 

ID there is nil. onClientRender doesn't send anything to the function.

local tables = { 
[1]={-2421.69238, -582.35858, 133.61719, "Caine"}, 
} 
  
function renderIng() 
    local x, y, z = getCameraMatrix( ) 
        for ID,v in ipairs(tables) do 
            local px, py, pz = tables[ID][1], tables[ID][2], tables[ID][3] 
            local distance = getDistanceBetweenPoints3D( px, py, pz, x, y, z ) 
            if distance <= 20 then 
                local text = tables[ID][4] 
                if text and ( distance < 2 or isLineOfSightClear( x, y, z, px, py, pz + 0.7, true, true, true, true, false, false, true, localPlayer ) ) then 
                    local sx, sy = getScreenFromWorldPosition( px, py, pz + 0.7 ) 
                    if sx and sy then 
                        local w = dxGetTextWidth( tostring( text ) ) 
                        local h = ( text and 2 or 1 ) * dxGetFontHeight( ) 
                        dxDrawText( tostring( text ), sx, sy, sx, sy, tocolor( 255, 255, 255, 255 ), 1, "default", "center", "center" ) 
                    end 
                end 
            end 
        end 
      end 
  
addEventHandler( "onClientRender", getRootElement( ),renderIng) 

Didn't test though.

Link to comment
function renderIng(ID) 
addEventHandler( "onClientRender", getRootElement( ),renderIng) 

ID there is nil. onClientRender doesn't send anything to the function.

local tables = { 
[1]={-2421.69238, -582.35858, 133.61719, "Caine"}, 
} 
  
function renderIng() 
    local x, y, z = getCameraMatrix( ) 
        for ID,v in ipairs(tables) do 
            local px, py, pz = tables[ID][1], tables[ID][2], tables[ID][3] 
            local distance = getDistanceBetweenPoints3D( px, py, pz, x, y, z ) 
            if distance <= 20 then 
                local text = tables[ID][4] 
                if text and ( distance < 2 or isLineOfSightClear( x, y, z, px, py, pz + 0.7, true, true, true, true, false, false, true, localPlayer ) ) then 
                    local sx, sy = getScreenFromWorldPosition( px, py, pz + 0.7 ) 
                    if sx and sy then 
                        local w = dxGetTextWidth( tostring( text ) ) 
                        local h = ( text and 2 or 1 ) * dxGetFontHeight( ) 
                        dxDrawText( tostring( text ), sx, sy, sx, sy, tocolor( 255, 255, 255, 255 ), 1, "default", "center", "center" ) 
                    end 
                end 
            end 
        end 
      end 
  
addEventHandler( "onClientRender", getRootElement( ),renderIng) 

Didn't test though.

Needed to change "ipairs" to "pairs."

local tables = { 
[1]={-2421.69238, -582.35858, 133.61719, "Caine"}, 
} 
  
function renderIng() 
    local x, y, z = getCameraMatrix( ) 
        for ID,v in pairs(tables) do 
            local px, py, pz = tables[ID][1], tables[ID][2], tables[ID][3] 
            local distance = getDistanceBetweenPoints3D( px, py, pz, x, y, z ) 
            if distance <= 20 then 
                local text = tables[ID][4] 
                if text and ( distance < 2 or isLineOfSightClear( x, y, z, px, py, pz + 0.7, true, true, true, true, false, false, true, localPlayer ) ) then 
                    local sx, sy = getScreenFromWorldPosition( px, py, pz + 0.7 ) 
                    if sx and sy then 
                        local w = dxGetTextWidth( tostring( text ) ) 
                        local h = ( text and 2 or 1 ) * dxGetFontHeight( ) 
                        dxDrawText( tostring( text ), sx, sy, sx, sy, tocolor( 255, 255, 255, 255 ), 1, "default", "center", "center" ) 
                    end 
                end 
            end 
        end 
      end 
  
addEventHandler( "onClientRender", getRootElement( ),renderIng) 

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