Jump to content

[Help] 3D Text


3B00DG4MER

Recommended Posts

Posted

Hello,I want today to Create a 3D Text Appears above the head of a ped

i have seen that in SUAR server

Thanks.

SAF/SAO - 30%

Skype: Themerzoug2020

in-game name:3B00DG4MER

xOG7h1J.png

Posted
local pedX, pedY, pedZ = 0, 0, 0 
local maxDistance = 12 -- the distance showing 3dtext 
  
addEventHandler ( "onClientRender", root, 
    function ( ) 
        local pX, pY, pZ = getElementPosition ( localPlayer ) 
        local distance = getDistanceBetweenPoints3D ( pX, pY, pZ, pedX, pedY, pedZ ) 
         
        if ( distance <= maxDistance ) then 
            local x, y = getScreenFromWorldPosition ( pedX, pedY, pedZ ) 
            if ( x and y ) then 
                dxDrawText( "text", x, y, _, _, tocolor( 255, 255, 255, 2555 ), 2, "default", "center", "center" ) 
            end 
        end 
    end 
) 

It should work, but I'm not sure, couse I was writing it kinda fast. :P

Posted
local pedX, pedY, pedZ = 0, 0, 0 
local maxDistance = 12 -- the distance showing 3dtext 
  
addEventHandler ( "onClientRender", root, 
    function ( ) 
        local pX, pY, pZ = getElementPosition ( localPlayer ) 
        local distance = getDistanceBetweenPoints3D ( pX, pY, pZ, pedX, pedY, pedZ ) 
         
        if ( distance <= maxDistance ) then 
            local x, y = getScreenFromWorldPosition ( pedX, pedY, pedZ ) 
            if ( x and y ) then 
                dxDrawText( "text", x, y, _, _, tocolor( 255, 255, 255, 2555 ), 2, "default", "center", "center" ) 
            end 
        end 
    end 
) 

It should work, but I'm not sure, couse I was writing it kinda fast. :P

Don't Work

I tried to Attach the Text to a Ped

local ped = createPed          (21, 2000.6636962891, 1538.318359375, 13.5859375) 
  
addEventHandler ( "onClientRender", root, 
    function ( ) 
    local pX, pY, pZ = getElementPosition ( ped ) 
        local distance = getDistanceBetweenPoints3D ( pX, pY, pZ, pedX, pedY, pedZ ) 
        
        if ( distance <= maxDistance ) then 
            local x, y = getScreenFromWorldPosition ( pX, pY, pZ ) 
            if ( x and y ) then 
            dxDrawText( "Criminal", x, y, _, _, tocolor( 255, 255, 255, 2555 ), 2, "default", "center", "center" ) 
            end 
        end 
    end 
) 

But the same fix it with Ped PLease

SAF/SAO - 30%

Skype: Themerzoug2020

in-game name:3B00DG4MER

xOG7h1J.png

Posted
    local ped = createPed (21, 2000.6636962891, 1538.318359375, 13.5859375) 
      
    addEventHandler ( "onClientRender", root, 
        function ( ) 
            local pX, pY, pZ = getElementPosition ( player ) 
            local pedX, pedY, pedZ = getElementPosition ( ped ) 
            local distance = getDistanceBetweenPoints3D ( pX, pY, pZ, pedX, pedY, pedZ ) 
            
            if ( distance <= 12 ) then 
                local x, y = getScreenFromWorldPosition ( pedX, pedY, pedZ ) 
                if ( x and y ) then 
                dxDrawText( "Criminal", x, y, _, _, tocolor( 255, 255, 255, 2555 ), 2, "default", "center", "center" ) 
                end 
            end 
        end 
    ) 

Posted
    local ped = createPed (21, 2000.6636962891, 1538.318359375, 13.5859375) 
      
    addEventHandler ( "onClientRender", root, 
        function ( ) 
            local pX, pY, pZ = getElementPosition ( player ) 
            local pedX, pedY, pedZ = getElementPosition ( ped ) 
            local distance = getDistanceBetweenPoints3D ( pX, pY, pZ, pedX, pedY, pedZ ) 
            
            if ( distance <= 12 ) then 
                local x, y = getScreenFromWorldPosition ( pedX, pedY, pedZ ) 
                if ( x and y ) then 
                dxDrawText( "Criminal", x, y, _, _, tocolor( 255, 255, 255, 2555 ), 2, "default", "center", "center" ) 
                end 
            end 
        end 
    ) 

Problem with line "if (distance <= 12) then"

Attempt to compare Boolean with number

i think you must convert distance to number tonumber(distance) afaik

SAF/SAO - 30%

Skype: Themerzoug2020

in-game name:3B00DG4MER

xOG7h1J.png

  • Moderators
Posted

It is maybe also handy if you check if the ped still does exist. :idea:

if isElement(ped) then 

or you may will have trouble when the ped somehow is deleted.(by another script)

Do you want to improve your Lua programming skills and make less mistakes?   Start with Lua Language Server!   🙀

 

  Useful functions  3x 

  Tutorials  4x 

 

Posted
change
local pX, pY, pZ = getElementPosition ( player ) 

to

local pX, pY, pZ = getElementPosition ( localPlayer ) 

Thankkkks

Can you give a code which change Font (Not GTA sa Fonts,Import One)

SAF/SAO - 30%

Skype: Themerzoug2020

in-game name:3B00DG4MER

xOG7h1J.png

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