Jump to content

dxDrawLine scaling


Recommended Posts

Hi all! I'm trying to make a box ESP script but i have problems with the lines being too big.

Here is 2 pics to help understand the problem:

Here everything is nice when i'm close to the ped:

zgn.png

But here the lines are too big when i'm far away:

4erj.png

Here is my code so far:

function render() 
    for i,v in ipairs(getElementsByType("ped"))do 
        local x1,y1,z1 = getElementPosition(localPlayer) 
        local x2,y2,z2 = getElementPosition(v) 
        local fDistance = getDistanceBetweenPoints3D(x1,y1,z1,x2,y2,z2) 
  
        if(v ~= localPlayer)then 
            local sx,sy = getScreenFromWorldPosition(x2,y2,z2) 
            dxDrawLine(sx-80, sy-200, sx-80, sy+200, tocolor(255, 0, 0, 255), 2) 
            dxDrawLine(sx-80, sy-200, sx+80, sy-200, tocolor(255, 0, 0, 255), 2) 
        end 
    end 
end 
addEventHandler("onClientRender", root, render) 

Edited by Guest
Link to comment
  • Moderators

The problem is that you can't really compare distance with camera size.(as far as I know)

But you can try:

You have two screenshots, create two times this structure.

One close and another one far away.

This is just a sample:

The size of the small one is: 50 px

The size of the large one is: 200 px

The distance is: 10 units.

  
200 - 50  = 150 -- differences 
  
--differences/ units = 
150 / 10 = 15  -- amount of size de-increase per unit 
  
  
local newsize = size -(units * 15)   
if newsize > 0 then 
-- do something. 
end 

Link to comment

IIYAMA, I don't know what you're talking about. The size of the camera is 0 because camera is at one definite point. It doesn't have a size.

megaman54, it's simple to figure out logically. When you are further from the object, it looks smaller. That means, if the distance is bigger, the observable size is smaller. The arithmetic operation whose result is closer to zero with bigger operand is division. So you need to divide the size by distance to get the visible size.

Link to comment

You could use

getElementBoundingBox 

Something like this:

local minx, miny, minz, mx, my, mz = getElementBoundingBox(value) 
                local x, y, z = getElementPosition(value) 
                dxDrawLine3D(minx+x, miny+y, mz+z+5, minx+x, my+y ,mz+z+5, tocolor(255, 0, 0, 255), 15, false, 0) 
                dxDrawLine3D(minx+x, miny+y, mz+z+5, mx+x, miny+y ,mz+z+5, tocolor(255, 0, 0, 255), 15, false, 0) 
                dxDrawLine3D(mx+x, my+y, mz+z+5, minx+x, my+y ,mz+z+5, tocolor(255, 0, 0, 255), 15, false, 0) 
                dxDrawLine3D(mx+x, miny+y, mz+z+5, mx+x, my+y ,mz+z+5, tocolor(255, 0, 0, 255), 15, false, 0) 

[This will create a square arround the player, used this for a predator missle]

This will resize automatic, as i saw on your picture, you are tryting to make a info box right?

Link to comment
You could use
getElementBoundingBox 

Something like this:

local minx, miny, minz, mx, my, mz = getElementBoundingBox(value) 
                local x, y, z = getElementPosition(value) 
                dxDrawLine3D(minx+x, miny+y, mz+z+5, minx+x, my+y ,mz+z+5, tocolor(255, 0, 0, 255), 15, false, 0) 
                dxDrawLine3D(minx+x, miny+y, mz+z+5, mx+x, miny+y ,mz+z+5, tocolor(255, 0, 0, 255), 15, false, 0) 
                dxDrawLine3D(mx+x, my+y, mz+z+5, minx+x, my+y ,mz+z+5, tocolor(255, 0, 0, 255), 15, false, 0) 
                dxDrawLine3D(mx+x, miny+y, mz+z+5, mx+x, my+y ,mz+z+5, tocolor(255, 0, 0, 255), 15, false, 0) 

[This will create a square arround the player, used this for a predator missle]

This will resize automatic, as i saw on your picture, you are tryting to make a info box right?

Yes something like that but 2D. Isn't there anyway to scale them in 2D?

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