Jump to content

dxDrawTextOnElement, dxDrawRectangle3D


TrickyTommy

Recommended Posts

Hi!
I am trying to make two things on my server:
    -license plates above cars, and rectangles above them too.
    -player nametags, and my nametag should not be visible for myself.
I have problems with both:
-the rectrangle is not getting drawn above the car
-i don't know how sould i make my nametag not visible for myself.


Current progress:
 

function Draw()

	local vehs = getElementsByType("vehicle")
	
	for k,v in ipairs(vehs) do
		dxDrawTextOnElement (v, getVehiclePlateText(v), 0.75, _, _, _, _, _, 2)
		local x, y, z = getElementPosition (v)
		dxDrawRectangle3D (x+1, y+1, z+1, 100, 25, tocolor(255, 0, 0, 0))
	end
	
	local players = getElementsByType("player")
	
	for k,v in ipairs(players) do
		dxDrawTextOnElement (v, getPlayerName(v), _, _, _, _, _, _, 1)
	end
	
end
addEventHandler ("onClientRender", getRootElement(), Draw)

 

Link to comment

try that, If doesn't work perfectly screenshot please.

 

function Draw()

	local vehs = getElementsByType("vehicle")
	
	for k,v in ipairs(vehs) do
		dxDrawTextOnElement (v, getVehiclePlateText(v), 0.75, _, _, _, _, _, 2)
		local x, y, z = getElementPosition (v)
    	local width = 100
    	local hight = 50
		dxDrawRectangle3D (x, y, z+, width, hight, tocolor(255, 0, 0, 0))
	end
	
	local players = getElementsByType("player")
	
	for k,v in ipairs(players) do
    	if v ~= localPlayer then
			dxDrawTextOnElement (v, getPlayerName(v), _, _, _, _, _, _, 1)
        end
	end
	
end
addEventHandler ("onClientRender", getRootElement(), Draw)

 

Link to comment
6 hours ago, N3xT said:

try that, If doesn't work perfectly screenshot please.

 


function Draw()

	local vehs = getElementsByType("vehicle")
	
	for k,v in ipairs(vehs) do
		dxDrawTextOnElement (v, getVehiclePlateText(v), 0.75, _, _, _, _, _, 2)
		local x, y, z = getElementPosition (v)
    	local width = 100
    	local hight = 50
		dxDrawRectangle3D (x, y, z+, width, hight, tocolor(255, 0, 0, 0))
	end
	
	local players = getElementsByType("player")
	
	for k,v in ipairs(players) do
    	if v ~= localPlayer then
			dxDrawTextOnElement (v, getPlayerName(v), _, _, _, _, _, _, 1)
        end
	end
	
end
addEventHandler ("onClientRender", getRootElement(), Draw)

 

think the solution for the nametag works, yet the rectangle is not visible.... :(

Link to comment

I modified the custom function a bit... but this is what it does. I hope this helps.

Also added another arg to set the background colour or hide it.

https://gfycat.com/UnimportantHiddenIberianmole

 

function Draw()
	local vehs = getElementsByType("vehicle")
	local players = getElementsByType("player")
	
	for k,v in ipairs(vehs) do
		if getPedOccupiedVehicle( localPlayer ) ~= v then
			dxDrawTextOnElement (v, getVehiclePlateText(v), 0.75, _, _, _, _, _, 2, _, tocolor(0,0,0,255))
		end
	end
	for k,v in ipairs(players) do
		if v ~= localPlayer then
			dxDrawTextOnElement (v, getPlayerName(v), _, _, _, _, _, _, 1)
		end
	end
end
addEventHandler ("onClientRender", getRootElement(), Draw)

function dxDrawTextOnElement(TheElement,text,height,distance,R,G,B,alpha,size,font,bgColor,checkBuildings,checkVehicles,checkPeds,checkDummies,seeThroughStuff,ignoreSomeObjectsForCamera,ignoredElement)
	local x, y, z = getElementPosition(TheElement)
	local x2, y2, z2 = getCameraMatrix()
	local distance = distance or 20
	local height = height or 1
	local checkBuildings = checkBuildings or true
	local checkVehicles = checkVehicles or false
	local checkPeds = checkPeds or false
	local checkObjects = checkObjects or true
	local checkDummies = checkDummies or true
	local seeThroughStuff = seeThroughStuff or false
	local ignoreSomeObjectsForCamera = ignoreSomeObjectsForCamera or false
	local ignoredElement = ignoredElement or nil
	if (isLineOfSightClear(x, y, z, x2, y2, z2, checkBuildings, checkVehicles, checkPeds , checkObjects,checkDummies,seeThroughStuff,ignoreSomeObjectsForCamera,ignoredElement)) then
		local sx, sy = getScreenFromWorldPosition(x, y, z+height)
		if(sx) and (sy) then
			local distanceBetweenPoints = getDistanceBetweenPoints3D(x, y, z, x2, y2, z2)
			if(distanceBetweenPoints < distance) then
				if bgColor then
					local tw = dxGetTextWidth( text, size or 1, font or "arial" )
					local tw = tw-((distanceBetweenPoints / distance)*(tw/2))
					local th = (12*size)-((distanceBetweenPoints / distance)*12)
					dxDrawRectangle( sx-(tw/2)-1, sy-(th/2)-1, tw+3, th+3 , bgColor)
				end
				dxDrawText(text, sx+2, sy+2, sx, sy, tocolor(R or 255, G or 255, B or 255, alpha or 255), (size or 1)-(distanceBetweenPoints / distance), font or "arial", "center", "center")
			end
		end
	end
end

 

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