Jump to content

radar


RenanPG

Recommended Posts

hi everybody, i want to create my own radar and hide the original.

addEventHandler('onClientHUDRender', root, function(source) 
  local px, py = getElementPosition(source) 
  dxDrawImageSection(2, 2, 400, 350, px, py, 3000, 3000, 'mapa.jpg')  
end) 

so, i dont know how to convert coordinates of map, to teh coordinates of the image.

player: -1500, 1300 <- pX, pY on the map.

map coordinates: the drawed image dont accept negative values of coordinates. the map is 3000x3000 pixels.

Link to comment
  • Moderators

As far I know, a map of 3000 x 3000 has a ratio of 1:100 (1px = 100 gta units)

So paste this function somewhere into your script:

local mapWidth, mapHeight = 3000, 3000 
local ratio = 1/100 --100 gta units = 1 pixel 
  
function gtaToMapCoordinates(x, y) 
    return x*ratio + mapWidth/2, y*ratio + mapHeight/2 
end 

And use it like that to get the posistion of the player on the image:

... 
local px, py = getElementPosition(localPlayer) 
--convert gta coordinates into  
local mpx, mpy = gtaToMapCoordinates(px, py) 
... 

Link to comment
As far I know, a map of 3000 x 3000 has a ratio of 1:100 (1px = 100 gta units)

So paste this function somewhere into your script:

local mapWidth, mapHeight = 3000, 3000 
local ratio = 1/100 --100 gta units = 1 pixel 
  
function gtaToMapCoordinates(x, y) 
    return x*ratio + mapWidth/2, y*ratio + mapHeight/2 
end 

And use it like that to get the posistion of the player on the image:

... 
local px, py = getElementPosition(localPlayer) 
--convert gta coordinates into  
local mpx, mpy = gtaToMapCoordinates(px, py) 
... 

Only for the knowledge, how can I know how many gta units have 1px?

Link to comment
  • Moderators
Only for the knowledge, how can I know how many gta units have 1px?

Haha, I dunno either. :mrgreen: I just found that ratio when I was helping someone (can't find the thread back) in a code I didn't made.

But if I had to, I would process like this:

1 - Find in GTA a spot that is really far from the center of the map (i.e: near the top right corner of the map)

2 - Find an easy spot to let us pick the right pixel on the map image (i.e: a corner of a building)

3 - Get the coordinates X and Y of the spot in the game and the coordinates of the pixel on the map image.

4 - Do some math to get the ratio.

Well, I just gave it a try !

I used this image (6000 x 6000 px): Click here

And I did the 3 first steps (click on it to see the fullsize):

8dxz.png

:arrow:it's 70 not 71 sorry

Now we just need to de math part:

We know that the image size is 6000 x 6000 px and the coordinates (0, 0) is the top left corner of the image.

We also know that (2832, 2931) in GTA corresponds to (5831, 70) on the image file and that (0, 0) in GTA corresponds to (3000, 3000) on the image (if the map is well centered in the image ofc).

First we need to be in the same referential (both the same origin (0, 0)). So we will just substract 3000 to x (of the pixel) and substract y (of the pixel) to 3000

3000 - x = 3000 - 5831 = 2831 --looks really close to the x position of the spot in GTA unit Oo 
3000 - y = 3000 - 70 = 2930 -- omg, looks really close to the y position of the spot in GTA unit !! 

Well the randomness wanted that the image I found has exactly a ratio of 1:1 ! (1px = 1 GTA unit)

So to get back on what I said:

As far I know, a map of 3000 x 3000 has a ratio of 1:100 (1px = 100 gta units)

I was maybe drunk when I read the code and assumed the ratio was 1:100

The same map at 3000 x 3000 px has a ratio of 1:2

This probably worth writing a tutorial.

Best regards,

Citizen

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