Bilal135 Posted May 8, 2015 Share Posted May 8, 2015 I created a script so it creates nametag on the top of the head using dxCreateText. It creates the nametag near the leg. How can I make it appear on the top of player's head? thanks. local rootElement = getRootElement() local screenWidth, screenHeight = guiGetScreenSize() function NPCnametag() local sx,sy = getScreenFromWorldPosition (getElementPosition(localPlayer)) if sx then dxDrawText(""..getPlayerName(localPlayer),sx,sy,screenWidth, screenHeight,tocolor ( 255, 255, 0, 255 ), 1.4,"default-bold") end end function HandleTheRendering() addEventHandler("onClientRender",rootElement, NPCnametag) end addEventHandler("onClientResourceStart",rootElement, HandleTheRendering) Link to comment
Bilal135 Posted May 10, 2015 Author Share Posted May 10, 2015 I tried this, it should make the nametag color random of players which are not in a team, and which are in a team, they should have their team nametag colors. But it doesn't work. addEventHandler( "onClientRender",root, function( ) local px, py, pz, tx, ty, tz, dist px, py, pz = getCameraMatrix( ) for _, v in ipairs( getElementsByType 'player' ) do tx, ty, tz = getElementPosition( v ) dist = math.sqrt( ( px - tx ) ^ 2 + ( py - ty ) ^ 2 + ( pz - tz ) ^ 2 ) if dist < 30.0 then if isLineOfSightClear( px, py, pz, tx, ty, tz, true, false, false, true, false, false, false,localPlayer ) then local sx, sy, sz = getPedBonePosition( v, 6 ) local x,y = getScreenFromWorldPosition( sx, sy, sz + 0.3 ) if x then -- getScreenFromWorldPosition returns false if the point isn't on screen local team = getPlayerTeam(localPlayer) if team then local r, g, b = getTeamColor(team) setPlayerNametagColor(localPlayer, r, g, b) else local r, g, b = getPlayerNametagColor(localPlayer) dxDrawText( getPlayerName( localPlayer ), x, y, x, y, tocolor(255, 255, 0), 0.85 + ( 15 - dist ) * 0.04, "default-bold", "center" ) end end end end end ) Link to comment
Walid Posted May 10, 2015 Share Posted May 10, 2015 You need to add the color { r,g,b} here like this dxDrawText( getPlayerName( localPlayer ), x, y, x, y, tocolor(r, g, b), 0.85 + ( 15 - dist ) * 0.04, "default-bold", "center" ) Link to comment
Bilal135 Posted May 10, 2015 Author Share Posted May 10, 2015 Error: Lua 25 Unexpected Symbol near ) Link to comment
Death Posted May 10, 2015 Share Posted May 10, 2015 (edited) try this dxDrawText( getPlayerName( localPlayer ), x, y, x, y, tocolor(r, g, b, 255), 0.85 + ( 15 - dist ) * 0.04, "default-bold", "center" ) Edited May 10, 2015 by Guest Link to comment
Walid Posted May 10, 2015 Share Posted May 10, 2015 Error: Lua 25 Unexpected Symbol near ) there is 'end' missing Try this one: addEventHandler( "onClientRender",root, function( ) local px, py, pz, tx, ty, tz, dist px, py, pz = getCameraMatrix( ) for _, v in ipairs( getElementsByType 'player' ) do tx, ty, tz = getElementPosition( v ) dist = math.sqrt( ( px - tx ) ^ 2 + ( py - ty ) ^ 2 + ( pz - tz ) ^ 2 ) if dist < 30.0 then if isLineOfSightClear( px, py, pz, tx, ty, tz, true, false, false, true, false, false, false,localPlayer ) then local sx, sy, sz = getPedBonePosition( v, 6 ) local x,y = getScreenFromWorldPosition( sx, sy, sz + 0.3 ) if x then local team = getPlayerTeam(localPlayer) if team then r, g, b = getTeamColor(team) setPlayerNametagColor(localPlayer, r, g, b) else r, g, b = getPlayerNametagColor(localPlayer) end dxDrawText( getPlayerName(localPlayer), x, y, x, y, tocolor(r,g, b), 0.85 + ( 15 - dist ) * 0.04, "default-bold", "center" ) end end end end end ) Link to comment
Bilal135 Posted May 10, 2015 Author Share Posted May 10, 2015 Lol! Everyone has my name. Must be some bug in script. Please fix it. Link to comment
Walid Posted May 10, 2015 Share Posted May 10, 2015 it must be like this : addEventHandler( "onClientRender",root, function( ) local px, py, pz, tx, ty, tz, dist px, py, pz = getCameraMatrix( ) local players = getElementsByType ( "player" ) for _, v in ipairs(players) do tx, ty, tz = getElementPosition( v ) dist = math.sqrt( ( px - tx ) ^ 2 + ( py - ty ) ^ 2 + ( pz - tz ) ^ 2 ) if dist < 30.0 then if isLineOfSightClear( px, py, pz, tx, ty, tz, true, false, false, true, false, false, false,v ) then local sx, sy, sz = getPedBonePosition( v, 6 ) local x,y = getScreenFromWorldPosition( sx, sy, sz + 0.3 ) if x then local team = getPlayerTeam(v) if team then r, g, b = getTeamColor(team) setPlayerNametagColor(v, r, g, b) else r, g, b = getPlayerNametagColor(v) end dxDrawText( getPlayerName(v), x, y, x, y, tocolor(r,g, b), 0.85 + ( 15 - dist ) * 0.04, "default-bold", "center" ) end end end end end ) 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