Jump to content

Radar blip


WASSIm.

Recommended Posts

  • Moderators

You just have to calculate the pos like every others blip but before you render em, just verify if the position is out of the rectangle. If it is then replace the pos by the max. And do the reverse for the min pos they can have on the screen.

local blipX = --some maths here to calculate the absolute X position of the blip 
local blipY = --some maths here to get the calculate Y position of the blip 
  
--for the X axe 
if blipX < radarX then blipX = radarX end --left side 
if blipX > radarX + radarWidth then blipX = radarX + radarWidth end --right side 
  
--for the Y axe 
if blipY < radarY then blipY = radarY end --top side 
if blipY > radarY + radarWidth then blipY = radarY + radarWidth end --bottom side 
  
--render everything 

For better performance, you can use elseif instead of two if in a row as I did (was a bit lazy :P )

We also can replace the if statements I did by using math.min (I'm writing it so check my post later, I just let you with the if version atm).

EDIT: Here is the version with math.min and math.max:

local blipX = --some maths here to calculate the absolute X position of the blip 
local blipY = --some maths here to get the calculate Y position of the blip 
  
blipX = math.max(radarX, math.min(radarX + radarWidth, blipX) 
blipY = math.max(radarY, math.min(radarY + radarHeight, blipY) 

I didn't tested it but I hope I didn't made mistakes in this version :D

Edited by Guest
Link to comment
  • Moderators

Well it wasn't what you asked us for. I thought you already did the math part.

Well I would say you need to find the ratio of you map file (probably by watching the difference between what returns getElementPosition, your position on the default map get the position (pixels) to be at the same place of your map file)

Note: the pos: 0, 0 is the middle of the map.

The part above has to be done outside of the radar script. To get the ratioX and ratioY (should be equal if the map is a square, and it should be).

Once you got them (and I suppose your map file is 3000x3000 pixels):

local mapImgWidth, mapImgHeight = 3000, 3000 
local ratioX, ratioY = --[[value here]], --[[value here]] 
local x, y = getElementPosition(localPlayer) 
local tempMapX, tempMapY = x*ratioX, y*ratioY --the position in pixels on your map file ( with the middle of this file as origin (0, 0) ) 
local mapX, mapY = tempMapX + mapImgWidth/2, tempMapY + mapImgHeight/2  --the position in pixels on your map file ( with the upper left corner of this image as origin (0, 0) ) 
--so now we have the real position in pixels, we draw the the map: 
dxDrawImageSection(radarX, radarY, radarWidth, radarHeight, mapX - mapWidth/2, mapY - mapWidth/2, mapX + mapWidth/2, mapY + mapWidth/2, "images/map.png") 

Please read and try to understand that code (also tell me if it works ^^). This code will only draw the right part of the map according to the player position (btw, ratioX and ratioY have to be correct). And the player is always in the center of the radar.

Once you got that, you can easily calculate the blips positions aswell. But I won't give you the code because it's currently taking me too much time.

EDIT: Damn it ! You stole code while I was writing. Which is making my big post almost useless ... np.

I can't test it (I mean I don't have enough time for that). What's the problem ?? (details explaination + screens if needed)

Link to comment
  • Moderators
thanks its working but i have some bugs

Well idk which bug it is but I already can see one:

        local blipX = (posX+(width/2))+cblipx-(blipsize/2) 
        local blipY = (posY+(height/2))+cblipy-(blipsize/2) 
        
        local blipX = math.max(posX, math.min(posX + width, blipX)) 
        local blipY = math.max(posY, math.min(posY + height, blipY)) 

You are creating these local variables twice, which is forbidden.

        local blipX = (posX+(width/2))+cblipx-(blipsize/2) 
        local blipY = (posY+(height/2))+cblipy-(blipsize/2) 
        
        blipX = math.max(posX, math.min(posX + width, blipX)) 
        blipY = math.max(posY, math.min(posY + height, blipY)) 

(I removed the local keywords on line 4 and 5). This bug is now fixed and the two variable will still be locals variables.

Link to comment
  • Moderators
its not on his position on i closed it

Can you please rewrite this in english please ?

Then what shows the red arrow ?

and look at blip then on bar health

Not my fault, you were supposed to give the radar height to my math.min for the Y axe and by that I mean only the height of the image being rendered:

        blipX = math.max(posX, math.min(posX + width/scale, blipX)) --pretty sure u need to do that too for the X 
        blipY = math.max(posY, math.min(posY + height/scale, blipY)) 

Link to comment
  • Moderators

Yeah ok, it's just because the code you stole was designed for a circular radar. And in this code, the author used this lines of code to prevent blip icons going outside the radar:

        local dist = getDistanceBetweenPoints2D(px, py, bx, by) 
        if dist > range then 
            dist = tonumber(range) 
        end 

(range is defined on top of the script to 100)

so just remove that lines to let our code (math.min and math.max on the blip position) prevents them (the blips) to go outside the radar.

Link to comment
  • Moderators

I really don't understand the position and size calculation in this code, it's kinda different from the blip one but it should looks like the same.

Specially this:

dxDrawRectangle(radarX, radarY, rw/2, -rh/2, tocolor(rr, rg, rb, ra), false) 

why -rh/2 ? is it like a random fix you tried ? If yes, then remove it in my code too (replace - by a + on line 8):

local radarX = ((rmapX+(rmapW/2))+cradarx) 
local radarY = ((rmapY+(rmapH/2))+cradary) 
-- keep the position inside 
radarX = math.max(rmapX, math.min(rmapX + rmapW, radarX)) 
radarY = math.max(rmapY , math.min(rmapY + rmapH, radarY)) 
-- keep the size inside 
local radarW = math.max(rmapX, math.min(rmapX + rmapW, rmapX + rw/2)) 
local radarH = math.max(rmapY , math.min(rmapY + rmapH, rmapX - rh/2)) 
if (isRadarAreaFlashing(radar)) then 
    ra = ra*math.abs(getTickCount()%1000-500)/500 
end 
dxDrawRectangle(radarX, radarY, radarW, radarH, tocolor(rr, rg, rb, ra), false) 

Link to comment
  • Moderators

Ok I think I did it, the only way to be sure is to test it. I checked the code 3 times line per line and in my head it does work xD

Add this right under the loop for the blips (or right over if you want the blips to be rendered over the radar areas).

for k, radararea in ipairs(getElementsByType("radararea")) do 
        local rint = getElementInterior(radararea) 
        local rdim = getElementDimension(radararea) 
        if pi == rint and pd == rdim then 
            local rx, ry = getElementPosition(radararea) 
            local rw, rh = getRadarAreaSize(radararea) 
            local rx2, ry2 = rx + rw, ry + rh 
  
            local dist = getDistanceBetweenPoints2D(px, py, rx, ry) 
            local dist2 = getDistanceBetweenPoints2D(px, py, rx2, ry2) 
  
            --- As I already said, I don't understand this part, but if you are sure it's working nice for blips then it should work --- 
            --top left corner 
            local angle = 180 + findRotation(px, py, rx, ry) 
            local crx, cry = getDistanceRotation(0, 0, range*(dist/range)/2, angle) 
  
            local rX = math.max(rmapX, math.min(rmapX + rmapW, (rmapX+(rmapW/2))+crx)) 
            local rY = math.max(rmapY, math.min(rmapY + rmapH, (rmapY+(rmapH/2))+cry)) 
            -- bottom right corner 
            local angle2 = 180 + findRotation(px, py, rx2, ry2) 
            local crx2, cry2 = getDistanceRotation(0, 0, range*(dist2/range)/2, angle2) 
  
            local rX2 = math.max(rmapX, math.min(rmapX + rmapW, (rmapX+(rmapW/2))+crx2)) 
            local rY2 = math.max(rmapY, math.min(rmapY + rmapH, (rmapY+(rmapH/2))+cry2)) 
            ---------------------------------------------------------------------------------------------------------------------------- 
  
            if rX ~= rX2 and rY ~= rY2 then --means it's out of the radar 
                local rr, rg, rb, ra = getRadarAreaColor(radararea) 
                local rW, rH = rX2 - rX, rY2 - rY 
  
                --- I dunno if that part really does what it should. I assume it does. --- 
                if (isRadarAreaFlashing(radararea)) then 
                    ra = ra*math.abs(getTickCount()%1000-500)/500 
                end 
                -------------------------------------------------------------------------- 
  
                dxDrawRectangle(rX, rY, rW, rh, tocolor(rr, rg, rb, ra)) 
            end 
        end 
    end 

Note: Do not create the radar area with a too high alpha if you want to see the map under the rectangles.

I really hope it will work :D

EDIT: Fixed typo at line 32 (cf. next post)

Edited by Guest
Link to comment

@OP: The MTA forums aren't here for personal advantage. If you want to get support, then don't remove your code. There are other people having same issues and you're just not making it any better here for anyone. That's just a disgrace.

Link to comment
@OP: The MTA forums aren't here for personal advantage. If you want to get support, then don't remove your code. There are other people having same issues and you're just not making it any better here for anyone. That's just a disgrace.

why ? for other stolen it ? just them can get exmple how make blip or how make radar area on radar

Link to comment

That's not what I meant. The thing I meant was that you removed all your code from this thread, which is kind of considered as a bad habit. You don't need to release your code, just don't remove the code in the thread you post. That's just ridiculous. I've had many of my help threads out there too with all kinds of code; doesn't mean I have to delete it all. It's very unlikely for them to be able to make something work by copy-pasting the code from forums anyways; the code is considered as material for further questions related to the same issues, this way we don't always have to give the same answers again when people can use the search tool and search for that issue.

Just keep this in your mind next time you come around asking for help.

Link to comment
Guest
This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...