Jump to content

[HELP] Nametag Script


Recommended Posts

Posted

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) 

"Get busy living or get busy dying"

Posted

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 
) 

"Get busy living or get busy dying"

Posted

You need to add the color { r,g,b} here

9a68973687.png

like this

dxDrawText( getPlayerName( localPlayer ), x, y, x, y, tocolor(r, g, b), 0.85 + ( 15 - dist ) * 0.04, "default-bold", "center" ) 

Do not yield your back to your enemy, might feel something strange in your ass.

Two things are infinite the universe and human stupidity and i'm not sure about the universe.

UF: IsTextInGridList | GetGridListRowIndexFromText | Table.removeValue | removeHex | dxDrawTriangle

Skype: SaSuki102 | About Me | Youtube channel | Lua Tips & Tricks | Lua Strings | Lua Tables | Lua Operators

Posted (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 by Guest
Posted
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 
) 

Do not yield your back to your enemy, might feel something strange in your ass.

Two things are infinite the universe and human stupidity and i'm not sure about the universe.

UF: IsTextInGridList | GetGridListRowIndexFromText | Table.removeValue | removeHex | dxDrawTriangle

Skype: SaSuki102 | About Me | Youtube channel | Lua Tips & Tricks | Lua Strings | Lua Tables | Lua Operators

Posted

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 
) 

Do not yield your back to your enemy, might feel something strange in your ass.

Two things are infinite the universe and human stupidity and i'm not sure about the universe.

UF: IsTextInGridList | GetGridListRowIndexFromText | Table.removeValue | removeHex | dxDrawTriangle

Skype: SaSuki102 | About Me | Youtube channel | Lua Tips & Tricks | Lua Strings | Lua Tables | Lua Operators

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