Volltron Posted June 9, 2021 Share Posted June 9, 2021 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) end addEventHandler("onClientResourceStart",resourceRoot,hideRadar) -- 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) dxSetRenderTarget(rt,true) 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) dxSetRenderTarget() dxDrawImage(minimapX, minimapY, minimapW, minimapH, rt); end ) How do I show the player location with the dxDrawImageSection Link to comment
Mkl Posted June 10, 2021 Share Posted June 10, 2021 (edited) 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) dxSetRenderTarget(rt,true) 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 dxSetRenderTarget() dxDrawImage(screenW/2 - radar_w/2, screenH/2 - radar_w/2, radar_w, radar_w, rt); end ) Have a nice day. Edited June 10, 2021 by Mkl 1 Link to comment
Volltron Posted June 13, 2021 Author Share Posted June 13, 2021 Thank you a lot for teaching me 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