Jump to content

Help: Radar


.:HyPeX:.

Recommended Posts

Well there are some things im having trouble with:

-no rectangle is drawn.

-Objects are said perfectly and suddenly they're stop being counted (Just if you go far away from the point you respawn, DrawTable is 0.)

I'm testing this on a race resource.

  
local x,y = guiGetScreenSize() 
local lp = getLocalPlayer() 
local RcX, RcY = x*0.15, y*0.8 
local RW = ( x / y ) * 0.05 
local OS = x / 0.05 
local ObjectTable = {} 
local CollsTable = {} 
local DrawTable = {} 
local CollsDrawTable = {} 
function CheckDistanceAndDraw() 
outputChatBox(#DrawTable) 
outputChatBox(#ObjectTable) 
ObjectTable = {} 
DrawTable = {} 
CollsDrawTable = {} 
CollsTable = {} 
for i, v in ipairs (getElementsByType("object")) do 
ObjectTable[i] = v 
end 
CollsTable = {} 
for i=1, #ObjectTable do 
CollsTable[i] = getElementBoundingBox(ObjectTable[i]) 
end 
for i=1, #ObjectTable do 
local x1,y1,z1 = getElementPosition(getLocalPlayer()) 
local x2,y2,z2 = getElementPosition(ObjectTable[i]) 
local height = z1 - z2 
local distance = getDistanceBetweenPoints2D(x1,y1,x2,y2) 
if distance < 50 then 
        DrawTable[i] = ObjectTable[i] 
end 
end 
for i=1, #DrawTable do 
if not isElement(DrawTable[i]) then return end 
local val1,val2,val3,val4,val5,val6 = getElementBoundingBox(DrawTable[i]) 
CollsDrawTable[i] = {val1,val2,val3,val4,val5,val6} 
end 
end 
addEventHandler("onClientRender", getRootElement(), CheckDistanceAndDraw) 
  
function DrawRadar() 
    for i=1, #DrawTable do 
    local x1,y1,z1 = getElementPosition(lp) 
    local x2,y2,z2 = getElementPosition(DrawTable[i]) 
    local rotation = findRotation(x1,y1,x2,y2) 
    local distance = getDistanceBetweenPoints2D(x1,y1,x2,y2) 
    local minX, minY, minZ, maxX, maxY, maxZ = unpack(CollsDrawTable[i]) 
    local size = getObjectScale(DrawTable[i]) 
    local widthX = maxX - minX 
    local widthY = maxY - minY  
    local height = maxZ - minZ 
    local maxSize = 15 
    local maximum = 150 
    local widthX = ( ( widthX / size ) / maximum) * maxSize 
    local widthY = ( ( widthY / size ) / maximum) * maxSize 
    if rotation > 0 and rotation < 90 then 
    dxDrawRectangle( ( RcX + distance / RW ) - widthX, ( RcY + distance / RW ) - widthY, x * OS + widthX * 2, y * OS + widthY * 2, tocolor(255,255,255,255) ) 
    elseif rotation > 90 and rotation < 180 then 
    dxDrawRectangle( ( RcX + distance / RW ) - widthX, ( RcY - distance / RW ) - widthY, x * OS + widthX * 2, y * OS + widthY * 2, tocolor(255,255,255,255) ) 
    elseif rotation > 180 and rotation < 270 then 
    dxDrawRectangle( ( RcX - distance / RW ) - widthX, ( RcY - distance / RW ) - widthY, x * OS + widthX * 2, y * OS + widthY * 2, tocolor(255,255,255,255) ) 
    elseif rotation > 270 and rotation < 360 then 
    dxDrawRectangle( ( RcX - distance / RW ) - widthX, ( RcY + distance / RW ) - widthY, x * OS + widthX * 2, y * OS + widthY * 2, tocolor(255,255,255,255) ) 
    else 
    outputChatBox("ERROR") 
    end 
    end 
end 
  
function findRotation(x1,y1,x2,y2) 
  
  local t = -math.deg(math.atan2(x2-x1,y2-y1)) 
  if t < 0 then t = t + 360 end; 
  return t; 
  
end 

Edited by Guest
Link to comment
You are using two tables there, with one you check if the element exists, and with the other you try to get the type and bounding box.

Basically the first table will contain all objects in the map, the second one will only have the ones that are close enought.

EDIT:

q4o3cdr.png

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