Jump to content

distance


developa

Recommended Posts

 

Hello, will anyone help me with this code snippet? The point is that from a distance (50 meters, for example), you can see the same thing at a distance of 5 meters

http://imgur.com/a/U4lmJ

 

code:

function dxDrawImageOnElement()
	local playerPosition = {getElementPosition(localPlayer)}
	local elementPosition = {getElementPosition(data.element)}
	local distance = math.floor(getDistanceBetweenPoints3D(elementPosition[1], elementPosition[2], elementPosition[3], playerPosition[1], playerPosition[2], playerPosition[3]))
	
	local coords = {getScreenFromWorldPosition(elementPosition[1], elementPosition[2], elementPosition[3]+0.3)}
	if coords[1] and coords[2] and isLineOfSightClear(elementPosition[1], elementPosition[2], elementPosition[3], playerPosition[1], playerPosition[2], playerPosition[3], false, false, false, false, true, false, false, nil) then
		dxDrawText(distance.."m", coords[1], coords[2] + sy/38, coords[1], coords[2], tocolor(255, 255, 255, 255), 2, "default-bold", "center", "center", false, false)
		dxDrawImage(coords[1], coords[2], data.width, data.height, data.image..".png", 0, 0, 0, tocolor(255, 255, 255, 255), false)
	end
end

 

Link to comment

You already calculated the distance so all you have to do it check if the distance is less than 50 or 5

function dxDrawImageOnElement()
	local playerPosition = {getElementPosition(localPlayer)}
	local elementPosition = {getElementPosition(data.element)}
	local distance = math.floor(getDistanceBetweenPoints3D(elementPosition[1], elementPosition[2], elementPosition[3], playerPosition[1], playerPosition[2], playerPosition[3]))
	local coords = {getScreenFromWorldPosition(elementPosition[1], elementPosition[2], elementPosition[3]+0.3)}
	local clear = isLineOfSightClear(elementPosition[1], elementPosition[2], elementPosition[3], playerPosition[1], playerPosition[2], playerPosition[3], false, false, false, false, true, false, false, nil)
	
	if coords[1] and clear and distance <= 50 then -- Check if the distance is less than "50"
		dxDrawText(distance.."m", coords[1], coords[2] + sy/38, coords[1], coords[2], tocolor(255, 255, 255, 255), 2, "default-bold", "center", "center", false, false)
		dxDrawImage(coords[1], coords[2], data.width, data.height, data.image..".png", 0, 0, 0, tocolor(255, 255, 255, 255), false)
	end
end

 

Since you are scripting with tables like this I suggest you learn to use OOP and Vectors it's very similar and much simpler to use. For example:

function dxDrawImageOnElement()
	local player = localPlayer.position
	local elem = Vector3(getElementPosition(data.element))
	local distance = (player-elem).length
	local coords = Vector2(getScreenFromWorldPosition(elem+Vector3(0,0,0.3)))
	local clear = isLineOfSightClear(elem, player, false, false, false, false, true, false, false, nil)
	
	if coords.x and clear then
		dxDrawText(distance.."m", coords.x, coords.y + sy/38, coords.x, coords.y, tocolor(255, 255, 255, 255), 2, "default-bold", "center", "center", false, false)
		dxDrawImage(coords.x, coords.y, data.width, data.height, data.image..".png", 0, 0, 0, tocolor(255, 255, 255, 255), false)
	end
end

 

Link to comment

 

I do not mean to see the draw, only about the size when we are at 1420 meters for example, so that the size is the same as 10 meters. example:

 

Uxedjhg.png

 

Here the size is the same at 1420 meters, as at 10 meters. How to do that?

Edited by developa
Link to comment

But do not you understand? This image itself increases with respect to the distance change of height and width does not give anything because it only reduces the picture but does not work for a distance !!

for example, 3 meters:

obizVdo.jpg

 

and 34 meters, I guess you can see the difference ...

K7nb0Et.jpg

Edited by developa
Link to comment
4 minutes ago, NeXuS™ said:

You have to multiply it with a calculated value of the distance.

 

Now, the picture is very big and as I try to divide it he will decrease with respect to the distance, and I do not want it. I just want to get the effect when I stand at 5 meters, at 1000 meters was the same.

Edited by developa
Link to comment

I want to get this effect: I stand on a vehicle, five meters away, I go away thirty meters and the picture is the same, not enlarge at all. Sorry for my english, i'm not from this country. By dividing the height and width of the image, the distance decreases - it is not expected. I just want this picture, no matter how many meters it is from, it was always the same.

function dxDrawImageOnElement()
	local playerPosition = {getElementPosition(localPlayer)}
	local elementPosition = {getElementPosition(data.element)}
	local distance = math.floor(getDistanceBetweenPoints3D(elementPosition[1], elementPosition[2], elementPosition[3], playerPosition[1], playerPosition[2], playerPosition[3]))
	local clear = isLineOfSightClear(elementPosition[1], elementPosition[2], elementPosition[3], playerPosition[1], playerPosition[2], playerPosition[3], false, false, false, false, true, false, false, nil)
	
	local coords = {getScreenFromWorldPosition(elementPosition[1], elementPosition[2], elementPosition[3]+0.3)}
	if coords[1] and coords[2] and clear then
		dxDrawText(distance.."m", coords[1], coords[2], coords[1], coords[2], tocolor(255, 255, 255, 255), 0.9, font, "center", "center", false, false)
		dxDrawImage(coords[1], coords[2], data.width/distance, data.height/distance, data.image..".png", 0, 0, 0, tocolor(255, 255, 255, 255), false)
	end
end

 

Edited by developa
Link to comment

Try this.

function dxDrawImageOnElement()
	local playerPosition = {getElementPosition(localPlayer)}
	local elementPosition = {getElementPosition(data.element)}
	local distance = math.floor(getDistanceBetweenPoints3D(elementPosition[1], elementPosition[2], elementPosition[3], playerPosition[1], playerPosition[2], playerPosition[3]))
	local clear = isLineOfSightClear(elementPosition[1], elementPosition[2], elementPosition[3], playerPosition[1], playerPosition[2], playerPosition[3], false, false, false, false, true, false, false, nil)
	
	local coords = {getScreenFromWorldPosition(elementPosition[1], elementPosition[2], elementPosition[3]+0.3)}
	if coords[1] and coords[2] and clear then
		local maxWidth = data.width
		local maxHeight = data.height
    	local reachMaxAt = 5 -- How far you have to be to get the maxWidth and maxHeight as the actual width and height
    	local nonflooderDistance = getDistanceBetweenPoints3D(elementPosition[1], elementPosition[2], elementPosition[3], playerPosition[1], playerPosition[2], playerPosition[3])
		local actualWidth = data.width*(reachMaxAt/nonflooderDistance) > maxWidth and maxWidth or data.width*(reachMaxAt/nonflooderDistance)
		local actualHeight = data.height*(reachMaxAt/nonflooderDistance) > maxHeight and maxHeight or data.height*(reachMaxAt/nonflooderDistance)
		dxDrawText(distance.."m", coords[1], coords[2], coords[1], coords[2], tocolor(255, 255, 255, 255), 0.9, font, "center", "center", false, false)
		dxDrawImage(coords[1], coords[2], actualWidth, actualHeight, data.image..".png", 0, 0, 0, tocolor(255, 255, 255, 255), false)
	end
end

 

Edited by NeXuS™
Fixed code
  • Like 1
Link to comment

How to create 3d image with get screen from world position,  but with the same image size,  even if i am away from that position. 
100 dist from image = size=200, 
200 dist from image = 
The same sizes of image as on 100 dist

Image is always as big as i want even if i am much distance from that position

Edited by developa
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...