developa Posted August 2, 2017 Share Posted August 2, 2017 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
Mr.Loki Posted August 2, 2017 Share Posted August 2, 2017 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
developa Posted August 2, 2017 Author Share Posted August 2, 2017 (edited) 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: Here the size is the same at 1420 meters, as at 10 meters. How to do that? Edited August 2, 2017 by developa Link to comment
Zorgman Posted August 2, 2017 Share Posted August 2, 2017 You want the image to have the same size no matter the distance? Link to comment
Zorgman Posted August 2, 2017 Share Posted August 2, 2017 (edited) On line 9 replace data.width, data.height with some fixed values i.e. 64, 64. The text looks like it should already retain same size. Edited August 2, 2017 by Zorgman Link to comment
developa Posted August 2, 2017 Author Share Posted August 2, 2017 (edited) 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: and 34 meters, I guess you can see the difference ... Edited August 2, 2017 by developa Link to comment
NeXuS™ Posted August 2, 2017 Share Posted August 2, 2017 You have to multiply it with a calculated value of the distance. 1 Link to comment
developa Posted August 2, 2017 Author Share Posted August 2, 2017 (edited) 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 August 2, 2017 by developa Link to comment
NeXuS™ Posted August 2, 2017 Share Posted August 2, 2017 Your english is quite hard to understand. Maybe try to describe it a bit better or make a post in your own language. Can you send your code that you have now? 1 Link to comment
developa Posted August 2, 2017 Author Share Posted August 2, 2017 (edited) 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 August 2, 2017 by developa Link to comment
Addlibs Posted August 2, 2017 Share Posted August 2, 2017 I think he wants the image to scale down with distance, so that it's the same size compared to the car at any given distance. 1 Link to comment
developa Posted August 2, 2017 Author Share Posted August 2, 2017 (edited) yeep!!! So that the image is the same size from any distance Edited August 2, 2017 by developa Link to comment
NeXuS™ Posted August 2, 2017 Share Posted August 2, 2017 (edited) 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 August 2, 2017 by NeXuS™ Fixed code 1 Link to comment
developa Posted August 2, 2017 Author Share Posted August 2, 2017 (edited) 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 August 2, 2017 by developa Link to comment
NeXuS™ Posted August 2, 2017 Share Posted August 2, 2017 Can you give me an IP so I can test it out on your server? 1 Link to comment
developa Posted August 2, 2017 Author Share Posted August 2, 2017 Yes, on private message Link to comment
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now