golanu21 Posted January 6, 2014 Share Posted January 6, 2014 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
Gallardo9944 Posted January 6, 2014 Share Posted January 6, 2014 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
xXMADEXx Posted January 7, 2014 Share Posted January 7, 2014 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
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