Jump to content

How to set distance to this text?


Turbe$Z

Recommended Posts

function text_render ( ) 
	for i,v in pairs ( messages ) do 
		local x, y, z = unpack ( v ) 
		local sx, sy, _ = getScreenFromWorldPosition ( x, y, z ) 
		if sx then 
			dxDrawText ( i, sx+2, sy+2, sw, sh, tocolor ( 0, 0, 0, 255 ), 2.0, "default-bold" ) 
			dxDrawText ( i, sx, sy, sw, sh, tocolor ( 0, 136, 255, 255 ), 2.0, "default-bold" ) 
		end 
	end 
end
addEventHandler("onClientRender",getRootElement(),text_render) 

i want set max distance for this, but how? :S 

Edited by Turbo777
Link to comment
  • Moderators

 

local cameraX, cameraY, cameraZ  = getCameraMatrix ()
for i,v in pairs ( messages ) do 
    local x, y, z = unpack ( v ) 
  	if getDistanceBetweenPoints3D (cameraX, cameraY, cameraZ, x, y, z ) < 100 then
      local sx, sy = getScreenFromWorldPosition ( x, y, z ) 
      if sx then 
          dxDrawText ( i, sx+2, sy+2, sw, sh, tocolor ( 0, 0, 0, 255 ), 2.0, "default-bold" ) 
          dxDrawText ( i, sx, sy, sw, sh, tocolor ( 0, 136, 255, 255 ), 2.0, "default-bold" ) 
      end 
    end
end 

 

 

If you also want to scale the text according to the REAL distance, see:

 

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