Jump to content

How to create Custom radar


redditing

Recommended Posts

To draw the radar on screen you should use:

To prevent the original radar from rendering you should use:

To query radar center and other relevant information map information you should use:

But I have to inform you that those functions alone will not make you a radar. You need to have a good understanding of how your radar should work, including the math behind it as well as the conventions to integrate it seamlessly into the Rockstar vision (north is into x=0,y=1 direction, etc).

For advanced effects you should use:

Here are neat references for already implemented radars or map scripts:

Since there are many threads on MTA forums about radar-logic that went unanswered feel free to post questions here. Maybe we can get this radar done together :) 

Edited by The_GTA
  • Like 1
  • Thanks 1
Link to comment
1 minute ago, redditing said:

U have 690 iq, thank u man

Thank you for this very nice compliment, redditing! ^^ I just happen to have a lot of experience with game design and MTA scripting.

Remember to ask any questions if you are stuck making the resource. I will be there to help you.

Link to comment
setPlayerHudComponentVisible("radar", false)

local screenW, screenH = guiGetScreenSize()

local w = 300
local s = 400
local screenX, screenY = guiGetScreenSize()
local minimap = dxCreateRenderTarget(s, s,true)

addEventHandler("onClientRender", root,
    function()
		local x, y = getElementPosition(getLocalPlayer())
		local rot = getElementRotation(getCamera())
		
        dxDrawRectangle(screenW * 0.0078, screenH * 0.7398, screenW * 0.1521, screenH * 0.2472, tocolor(255, 0, 0, 255), false)
        masked = dxDrawRectangle(screenW * 0.0099, screenH * 0.7435, screenW * 0.1479, screenH * 0.2398, tocolor(0, 0, 0, 255), false)
		dxDrawImageSection(screenW * 0.0099, screenH * 0.7435, screenW * 0.1479, screenH * 0.2398, x, y, 256.0, 256.0, "HUD/RADAR/mapa.png", rot)
		
		local mapa = dxCreateRenderTarget(s, s, true)
		dxDrawImage(0, screenY - w, s, w, minimap)
		dxSetRenderTarget(minimap, false)
	end
)

 

Okay I made this code but I have no idea what's next, will you help?

Link to comment
1 hour ago, redditing said:

Okay I made this code but I have no idea what's next, will you help?

Yes, let me comment on your code :) 

  • line 19: please do not create render targets each frame. you already did create the necessary render target in line 8.
  • line 17: you should not use a path in dxDrawImageSection; I recommend you to use dxCreateTexture to load images into memory; it creates a texture element that you can pass into dxDrawImageSection.
  • line 21: using dxSetRenderTarget at this point is wrong; it should be called at the start of the onClientRender event. then you can clear the render target again and use dxDrawImage at the end of onClientRender to draw your radar. I recommend to play around with render targets to understand how they work (they start from coordinate 0,0 if you draw inside them)

That's it for the existing code. After you have successfully improved the code based on the guidelines above I can give you the following advice:

  • try to calculate the coordinate on the map image (from 0 (beginning of image) to 1 (end of image)) that corresponds to the world coordinate x, y from the camera. imagine that the top left of the map image corresponds to -3000,3000 world coordinate and the bottom right to 3000,-3000 world coordinate. you could do this calculation even with school math knowledge plus trial&error. then draw a blip on the radar (location of the player?)

- Martin

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