Jump to content

[HELP] dxRadar Blip problem


verebes122

Recommended Posts

Hello guys! I have an issue with my radar script and I can't fix it. I wanted to draw the server's blips to the player's minimap, but i don't know how to calculate the X,Y coordinates on the radar when I rotate my camera.

That's my client side script:

local c = exports.gw_core
local screenX,screenY = guiGetScreenSize()
local fonts = c:getFonts()
local options = c:getOptions()

local s = c:getSize(300)
local bx,by = c:getSize(50), screenY - c:getSize(50)-s
local x,y = c:getSize(60), screenY - c:getSize(40) - s
local arrowSize = c:getSize(30)
local bs = s*2
local mapTarget = dxCreateRenderTarget(bs,bs)
local map = dxCreateTexture('world.jpg')
local blipTarget = dxCreateRenderTarget(3000,3000)

setPlayerHudComponentVisible ( 'radar',false)

function getMapCord(element)
    local x,y = getElementPosition(element)
    local imgSize = 3072
    return ((x + 3000) / 6000) * imgSize, (-(y - 3000) / 6000) * imgSize
end


local blip = createBlip (1962.291015625,-1751.20703125,13.3828125, 0)

addEventHandler('onClientRender',root,function()
    local _,_,r = getElementRotation(getCamera())
    local _,_,pr = getElementRotation(localPlayer)
    local posX,posY = getMapCord(localPlayer)
    dxSetRenderTarget(blipTarget)
        dxDrawImageSection ( posX - bs/2, posY - bs/2, bs,bs,posX - bs/2, posY - bs/2, bs,bs,map,r)
        for k,v in pairs(getElementsByType('blip')) do
            local blipX,blipY = getMapCord(v)
            dxDrawImage(blipX - 10, blipY - 10, 20, 20, 'player.png');  -- I don't have blip images yet
        end
    dxSetRenderTarget()

    dxDrawRectangle ( bx,by,s+c:getSize(20),s+c:getSize(20), options.panelDark)
    dxDrawImageSection ( x,y,s,s,posX - s/2, posY - s/2, s,s,blipTarget)
    dxDrawImage ( x + s/2 - arrowSize/2, y + s/2 - arrowSize/2, arrowSize,arrowSize,'player.png',r-pr,0,0)
end)

 

There's the problem in the game : 

d1a6ZZT.png

Edited by verebes122
Grammar
Link to comment
  • Moderators

You need to rotate the blip too, around center of the map.

You can change the rotation point.

Quote
  • rotationCenterOffsetX: the absolute X offset from the image center for which to rotate the image from.
  • rotationCenterOffsetY: the absolute Y offset from the image center for which to rotate the image from.

https://wiki.multitheftauto.com/wiki/DxDrawImage

Link to comment
  • Moderators
16 hours ago, verebes122 said:

I know i can rotate the image, but i don't want it. I just want to place it to the right place when i rotate the map. If i rotate the blip it will rotate upside down, and I don't want that.

Then, you need the rot difference between localPlayer and blip: findRotation

And the distance between localPlayer and blip: getDistanceBetweenPoints2D

When you get it, convert game distance to screen pixel distance.

Then, you can calculate the blip position, from the center of the map: getPointFromDistanceRotation

And finally, you need to limit the blip x and y coords, to stay inside the map rectangle.

blipScreenX = math.max(MAP_RECTANGLE_START_X, math.min(MAP_RECTANGLE_END_X, blipScreenX))
blipScreenY = math.max(MAP_RECTANGLE_START_Y, math.min(MAP_RECTANGLE_END_Y, blipScreenX))

 

Link to comment
        for k,v in pairs(getElementsByType('blip')) do
            local blipPosX,blipPosY = getElementPosition(v)
            local blipX,blipY = getMapCord(v)
            
            local rotationBetween = findRotation(playerX,playerY,blipPosX,blipPosY)
            local distanceBetween = getDistanceBetweenPoints2D (playerX,playerY,blipPosX,blipPosY)

            local blipScreenX,blipScreenY = getPointFromDistanceRotation(playerX,playerY,distanceBetween,rotationBetween)

            local MAP_RECTANGLE_START_X, MAP_RECTANGLE_START_Y = x,y
            local MAP_RECTANGLE_END_X, MAP_RECTANGLE_END_Y = x + s, y + s

            blipScreenX = math.max(MAP_RECTANGLE_START_X, math.min(MAP_RECTANGLE_END_X, blipScreenX))
            blipScreenY = math.max(MAP_RECTANGLE_START_Y, math.min(MAP_RECTANGLE_END_Y, blipScreenY))
    
            dxDrawImage(blipScreenX- 10, blipScreenY - 10, 20, 20, 'player.png');  -- I don't have blip images yet
        end

 

I think I didn't understood something, because it's not showing blip in my minimap. What's wrong with this code?

 

Link to comment
  • Moderators
1 hour ago, verebes122 said:

I think I didn't understood something, because it's not showing blip in my minimap. What's wrong with this code?

Almoost.

 

for k,v in pairs(getElementsByType('blip')) do
	local blipPosX,blipPosY = getElementPosition(v)
	local blipX,blipY = getMapCord(v)
	
	local rotationBetween = findRotation(playerX,playerY,blipPosX,blipPosY)
	local distanceBetween_GAME = getDistanceBetweenPoints2D (playerX,playerY,blipPosX,blipPosY)
	local distanceBetween_PIXELS = distanceBetween_GAME * (3072/6000) -- distance * (map image size / game world size)

 	-- in this case, now we use getPointFromDistanceRotation to calculate pixels, and not ingame coordinates
	local blipScreenX,blipScreenY = getPointFromDistanceRotation(x+s/2,x+s/2,distanceBetween_PIXELS,rotationBetween)

	blipScreenX = math.max(x, math.min(x+s, blipScreenX))
	blipScreenY = math.max(y, math.min(y+s, blipScreenY))

	dxDrawImage(blipScreenX- 10, blipScreenY - 10, 20, 20, 'player.png');  -- I don't have blip images yet
end

 

Something like this, but it's a bit difficult to say exactly without testing it...

(btw are you hungarian? If yes, I can tell you in hungarian, in more detail)

Edited by Patrick
  • Thanks 1
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...