Jump to content

[Help] How to create a custom radar gps

Recommended Posts

I want to create a custom radar on which I can add blips and radarareas but I can't even get near that since I'm having trouble with the math, this is what I did so far 

-- Removing the hud radar --
local function hideRadar()
	setPlayerHudComponentVisible("radar", false)

-- GPS --
local screenW, screenH = guiGetScreenSize()
local mapImgWidth, mapImgHeight = 3072 , 3072 -- size of the world.jpg texture
local minimapX, minimapY = 696, 364 -- test size of the radar
local rt = dxCreateRenderTarget(541, 454)
addEventHandler("onClientRender", root, function()
    local x, y = getElementPosition(getLocalPlayer()) -- player x, y coords 
    local camX, camY, camZ = getElementRotation(getCamera()) -- player x, y ,z camera coords
    local plRotX, plRotY, plRotZ = getElementRotation(getLocalPlayer()) -- player rotation coords
    local minimapW, minimapH = dxGetMaterialSize(rt)
    dxDrawImageSection(0, 0, mapImgWidth, mapImgHeight, 0, 0, mapImgWidth, mapImgHeight, ":gps_remake/images/world.jpg")
    dxDrawImage(minimapW/2 - 30/2, minimapH/2 - 30/2, 30, 30, ":gps_remake/images/player.png", camZ- plRotZ)
    dxDrawImage(minimapX, minimapY, minimapW, minimapH, rt);

How do I show the player location with the dxDrawImageSection

Link to post

Hello, Here is the way I would have begin (tested in-game). Hope it can help.

local screenW, screenH = guiGetScreenSize()
local map_w = 1536 		-- size of the map image (mine is 1536 x 1536)
local game_w = 6000		-- equivalency with the game size (here whole gtasa map = 6000 x 6000)
local radar_w = 400 	-- size of the radar on screen
local rt = dxCreateRenderTarget(map_w , map_w) -- same size of the map image

addEventHandler("onClientRender", root, function()
    local x_game, y_game = getElementPosition(localPlayer) -- game positions of the player

	local x_map = (map_w * (x_game + 3000)) / game_w -- scale the x to map's resolution
	local y_map = -(map_w * (y_game + 3000)) / game_w -- scale the y to map's resolution
	-- player in-game position will be -3000 to +3000 for both axes, so I add +3000 to have proper relation between game size and map size
	-- I add a negative value to y_map. If not, the map will move in the wrong direction for Y axe (inverted)

		dxDrawImageSection(0, 0, map_w, map_w, x_map - (radar_w / 2), y_map - (radar_w / 2), radar_w, radar_w, "map.jpg")
		-- first it draws the whole map (0,0 to map_w, map_w). 
		-- the section will be the size you want for the radar less the mid-distance to place the x, y player position to the center
		dxDrawCircle(map_w / 2, map_w / 2, 30) -- some circle drawn in the middle which symbolize the main player

    dxDrawImage(screenW/2 - radar_w/2, screenH/2 - radar_w/2, radar_w, radar_w, rt);

Have a nice day.

Edited by Mkl
  • Like 1
Link to post

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