Jump to content

Rectangle radar blips


FuriouZ

Recommended Posts

Hello!

To be honest, I am this kind person who doesn't reallylike ask help. I'm trying to do as much as I can myself, but still..

Yes, I know there's already a thread about this, but I don't understand this. I even tryed to ask help from this thread author WASSIm, but he didn't respond.. :|

Anyways, probably a lot of people knows my GTA V Style radar ( here ) ,it has over 2000 downloads and people, who uses it, told me a lot of times that this radar need's blips support, Yes i know too that whidout blips there's actually no point of this resource..

So finally I decided to ask help here.

I hope that we can fix this problem together. :oops:

I found some lines from the internet, but there's a problem with the position

Screenshot:

mta-screen_2014-10-17_17-27-34.png

Here's the full code:

  
local screenW,screenH = guiGetScreenSize() 
local g_ScreenSize = {guiGetScreenSize()} 
local resW,resH = 1280,720 
local sW,sH =  (screenW/resW), (screenH/resH) 
--local g_ScreenSize =  {(screenW/resW), (screenH/resH)} 
local icons = {} 
for k = 1,65 do 
icons[k] = dxCreateTexture("blips/"..k..".png") 
end 
local blips = {} 
  
    local turn = true 
    local alpha = 255 
     
addEventHandler( "onClientResourceStart", resourceRoot, 
    function() 
        --setPlayerHudComponentVisible ( "radar", false ) 
        --# Create Textures 
        hudMaskFX = dxCreateShader("mask.fx") 
        radarTexture = dxCreateTexture("img/radar_map.jpg") 
        maskTexture = dxCreateTexture("img/radar_mask.png") 
        checkTextures = ( hudMaskFX and radarTexture and maskTexture ) 
  
        if not ( checkTextures ) then 
            outputChatBox( "[GTA V Radar]: Could not create textures. Please use debugscript 3" ) 
        else 
            dxSetShaderValue( hudMaskFX, "sPicTexture", radarTexture ) 
            dxSetShaderValue( hudMaskFX, "sMaskTexture", maskTexture ) 
        end 
    end 
) 
  
    function drawRadar() 
        if not ( checkTextures ) then return end 
            dxSetShaderValue( hudMaskFX, "sMaskTexture", maskTexture ) 
         
        local x,y = getElementPosition( localPlayer ) 
        local zoom = 13      
            x = ( x ) / 6000 
            y = ( y ) / -6000 
        dxSetShaderValue( hudMaskFX, "gUVPosition", x,y ) 
        dxSetShaderValue( hudMaskFX, "gUVScale", 1/zoom, 1/zoom ) 
         
         
  
     
        --# Get rotations 
        local _, _, c_Rot = getElementRotation( getCamera()); 
        local _, _, p_Rot = getElementRotation( localPlayer )        
            dxSetShaderValue( hudMaskFX, "gUVRotAngle", math.rad( -c_Rot )) 
         
        local playerHealth = math.floor( getElementHealth( localPlayer )) 
        local playerArmor = math.floor( getPedArmor( localPlayer )) 
        local playerOxygen = math.floor( getPedOxygenLevel( localPlayer )) 
            if ( playerHealth  <= 50) then 
                HP_Colour = tocolor(200, 0, 0, 190) 
                HP_Alpha = tocolor(200, 0, 0, 100) 
            else 
                HP_Colour = tocolor(102, 204, 102, 190) 
                HP_Alpha = tocolor(102, 204, 102, 100)               
            end 
            if ( playerHealth >= 101 ) then 
                maxHealth = 200 
            else 
                maxHealth = 100 
            end              
         
        --# Alpha 
        dxDrawRectangle(23.5*sW, 676.5*sH, 130.5*sW, 9.2*sH, HP_Alpha)       
        dxDrawRectangle(156.6*sW, 676.5*sH, 65*sW, 9.2*sH, tocolor(0, 102, 255, 100)) 
        dxDrawRectangle(225*sW, 676.5*sH, 62.6*sW, 9.2*sH, tocolor(255, 255, 0, 100)) 
         
        --# Bars 
        dxDrawRectangle(23.5*sW, 676.5*sH, 130.5*sW/maxHealth*playerHealth, 9.2*sH, HP_Colour)       
        dxDrawRectangle(156.6*sW, 676.5*sH, 65*sW/100*playerArmor, 9.2*sH, tocolor(0, 102, 255, 190)) 
        dxDrawRectangle(225*sW, 676.5*sH, 62.6*sW/1000*playerOxygen, 9.2*sH, tocolor(255, 255, 0, 190))           
         
        --# Minimap      
        dxDrawImage(18*sW, 530*sH, 275*sW, 160*sH, "img/radar_cover.png", 0, 0, 0, tocolor(255, 255, 255, 255)) 
        dxDrawImage(23*sW, 536*sH, 265*sW, 135*sH, hudMaskFX, 0,0,0, tocolor(255,255,255, 200)) 
        dxDrawImage(144*sW, 595*sH, 20*sW, 20*sH, "img/radar_player.png", -p_Rot+c_Rot, 0, 0, tocolor(255, 255, 255, 255)) 
  
        --# Blips 
        --local MimgW,MimgH  = dxGetMaterialSize(hudMaskFX) 
        local MimgW,MimgH  = 265*sW, 135*sH 
     setTimer(function () 
                blips = {} 
                    for i, v in ipairs( getElementsByType('blip') ) do 
                            local icon = getBlipIcon(v) 
                        if icon > 3 then 
                            local px,py = getElementPosition(v) 
                            local blip_x = (3000+px)/6000*MimgW 
                            local blip_y = (3000-py)/6000*MimgH 
                            local rot = getPedCameraRotation( localPlayer ) 
                            table.insert(blips,{x = blip_x, y = blip_y,icon = icon}) 
                        end 
                    end 
     end,1000,0) 
                local rot = getPedCameraRotation( localPlayer )  
                        for i, v in ipairs( blips ) do 
                                dxDrawImage(v.x-20/2, v.y-20/2, 20 , 20 ,icons[v.icon],rot) 
                        end 
         
        --# Wanted 
        local g_wl = getPlayerWantedLevel( localPlayer ) 
        if ( g_wl > 0 ) then 
            if ( turn == true ) then 
                alpha = alpha + 5 
                    if ( alpha > 180 ) then 
                        alpha = 180 
                        turn = false 
        end 
        elseif ( turn == false ) then 
            alpha = alpha - 5 
                if ( alpha < 0 ) then 
                    alpha = 0 
                    turn = true 
                end 
        end 
        dxDrawRectangle(23*sW, 536*sH, 265*sW, 135*sH, tocolor(0, 102, 255, alpha)) 
        else return end      
        end 
addEventHandler( "onClientRender", root, drawRadar) 
  
function findRotation(x1,y1,x2,y2) 
  local t = -math.deg(math.atan2(x2-x1,y2-y1)) 
  if t < 0 then t = t + 360 end 
  return t 
end 
  
addEventHandler( "onClientResourceStop", resourceRoot, 
    function() 
        setPlayerHudComponentVisible ( "radar", true ) 
    end) 
     

Blips part:

        --# Blips 
        --local MimgW,MimgH  = dxGetMaterialSize(hudMaskFX) 
        local MimgW,MimgH  = 265*sW, 135*sH 
     setTimer(function () 
                blips = {} 
                    for i, v in ipairs( getElementsByType('blip') ) do 
                            local icon = getBlipIcon(v) 
                        if icon > 3 then 
                            local px,py = getElementPosition(v) 
                            local blip_x = (3000+px)/6000*MimgW 
                            local blip_y = (3000-py)/6000*MimgH 
                            local rot = getPedCameraRotation( localPlayer ) 
                            table.insert(blips,{x = blip_x, y = blip_y,icon = icon}) 
                        end 
                    end 
     end,1000,0) 
                local rot = getPedCameraRotation( localPlayer )  
                        for i, v in ipairs( blips ) do 
                                dxDrawImage(v.x-20/2, v.y-20/2, 20 , 20 ,icons[v.icon],rot) 
                        end 

I really hope, that we can bring first fully working, UNCOMPLIED radar FOR FREE to EVERY PLAYER

Link to comment

LuCaS, you don't even know what does he need. He needs BLIPS not only PLAYER BLIPS.

He needs the math part.

  
                            local blip_x = (3000/6000)*MimgW 
                            local blip_y = (3000-py)/6000*MimgH 
  

This part.

Let me know if they are there are not

Link to comment
LuCaS, you don't even know what does he need. He needs BLIPS not only PLAYER BLIPS.

He needs the math part.

  
                            local blip_x = (3000/6000)*MimgW 
                            local blip_y = (3000-py)/6000*MimgH 
  

This part.

Let me know if they are there are not

Thanks, but now they are all in the same pos :|

whole map size is 3072x3072, but i have there

local blip_x = (3000/6000)*MimgW

local blip_y = (3000-py)/6000*MimgH

It can be too one problem maybe ?

mta-screen_2014-10-18_10-24-44.png

Link to comment

Um i did some math, hope it is good, probably not best solution but....

As this isnt exactly "perfect" (turning circle into rectangle) i'd check wich easing function would suit best here...

i think it should work pretty good, report results.

Usage: GetPositionOnRec(rot,sx,sy,cx,cy,enx,eny)

rot: Rotation of your blip (Like you have the 360 angle now)

sx: start corner X corner of rectangle

sy: start corner Y corner of rectangle

cx: center X of rectangle

cy: center Y of rectangle

enx: end corner X of rectangle

eny: end corner Y of rectangle

(Note: Start corner should be upper left and ending lower right)

  
function GetPositionOnRec(rot,sx,sy,cx,cy,enx,eny) 
local start = {sx, sy} -- Start corner of map drawn 
local endp = {enx,eny} -- end corner of map drawn 
local center = {cx, cy} -- Center of map 
if rot < 360 and rot > 315 then 
    local progress = (rot - 315) / 45 
    sy,sx = start[2],interpolateBetween(start[1],0,0,center[1],0,0,progress,"Linear") 
elseif rot > 0 and rot < 45 then 
    local progress = (rot) / 45 
    sy,sx = start[2],interpolateBetween(center[1],0,0,endp[1],0,0,progress,"Linear") 
elseif rot > 45 and rot < 90 then 
    local progress = (rot-45) / 45 
    sx,sy = endp[1],interpolateBetween(start[2],0,0,center[2],0,0,progress,"Linear") 
elseif rot > 90 and rot < 135 then 
    local progress = (rot-90) / 45 
    sx,sy = endp[1],interpolateBetween(center[2],0,0,endp[2],0,0,progress,"Linear") 
elseif rot > 135 and rot < 180 then 
    local progress = (rot-135) / 45 
    sy,sx = endp[2],interpolateBetween(endp[1],0,0,center[1],0,0,progress,"Linear") 
elseif rot > 180 and rot < 225 then 
    local progress = (rot-180) / 45 
    sy,sx = endp[2],interpolateBetween(center[1],0,0,start[1],0,0,progress,"Linear") 
elseif rot > 225 and rot < 270 then 
    local progress = (rot-225) / 45 
    sx,sy = start[1],interpolateBetween(endp[2],0,0,center[2],0,0,progress,"Linear") 
elseif rot > 270 and rot < 315 then 
    local progress = (rot-270) / 45 
    sx,sy = start[1],interpolateBetween(center[2],0,0,start[2],0,0,progress,"Linear") 
end 
local Dx,Dy = sx,sy 
return Dx,Dy 
end 
  

EDIT: Readed your radar's known bug. Just set a max value to be drawn-

if val > x then

val = x

end

Edited by Guest
Link to comment
Um i did some math, hope it is good, probably not best solution but....

As this isnt exactly "perfect" (turning circle into rectangle) i'd check wich easing function would suit best here...

i think it should work pretty good, report results.

Usage: GetPositionOnRec(rot,sx,sy,cx,cy,enx,eny)

rot: Rotation of your blip (Like you have the 360 angle now)

sx: start corner X corner of rectangle

sy: start corner Y corner of rectangle

cx: center X of rectangle

cy: center Y of rectangle

enx: end corner X of rectangle

eny: end corner Y of rectangle

(Note: Start corner should be upper left and ending lower right)

  
  
function GetPositionOnRec(rot,sx,sy,cx,cy,enx,eny) 
local start = {sx, sy} -- Start corner of map drawn 
local endp = {enx,eny} -- end corner of map drawn 
local center = {cx, cy} -- Center of map 
local rot = rot 
local sx,sy = 0,0 
if rot < 360 and rot > 315 then 
    sy,sx = start[2],interpolateBetween(start[1],0,0,center[1],0,0,progress,"OutQuad") 
    local progress = (rot - 315) / 45 
elseif rot > 0 and rot < 45 then 
    sy,sx = start[2],interpolateBetween(center[1],0,0,endp[1],0,0,progress,"InQuad") 
    local progress = (rot) / 45 
elseif rot > 45 and rot < 90 then 
    sx,sy = endp[1],interpolateBetween(start[2],0,0,center[2],0,0,progress,"OutQuad") 
    local progress = (rot-45) / 45 
elseif rot > 90 and rot < 135 then 
    sx,sy = endp[1],interpolateBetween(center[2],0,0,endp[2],0,0,progress,"InQuad") 
    local progress = (rot-90) / 45 
elseif rot > 135 and rot < 180 then 
    sy,sx = endp[2],interpolateBetween(endp[1],0,0,center[1],0,0,progress,"OutQuad") 
    local progress = (rot-135) / 45 
elseif rot > 180 and rot < 225 then 
    sy,sx = endp[2],interpolateBetween(center[1],0,0,start[1],0,0,progress,"InQuad") 
    local progress = (rot-180) / 45 
elseif rot > 225 and rot < 270 then 
    sx,sy = start[1],interpolateBetween(endp[2],0,0,center[2],0,0,progress,"OutQuad") 
    local progress = (rot-225) / 45 
elseif rot > 270 and rot < 315 then 
    sx,sy = start[1],interpolateBetween(center[2],0,0,start[2],0,0,progress,"InQuad") 
    local progress = (rot-270) / 45 
end 
local Dx,Dy = sx,sy 
return Dx,Dy 
end 
  

EDIT: Readed your radar's known bug. Just set a max value to be drawn-

if val > x then

val = x

end

This is quite complicated, can you give a an example, how i should draw blips ?

Thanks!

Link to comment
This is quite complicated, can you give a an example, how i should draw blips ?

Thanks!

Yeah, its not that hard, i wrote that code just now.

This should draw a simulation rectangle and a blip going arround with your ped rotation.

EDIT: My bad, i did some miscalculations and errors while writing down the code :mrgreen:

fully working example now. (Also fixed the function wich makes the magic, so please check.

  
  
local x,y = guiGetScreenSize() 
local sx,sy = x*0.1,y*0.8 
local cx,cy = x*0.15,y*0.85 
local enx,eny = x*0.2,y*0.9 
  
local bpwidth = x*0.01 
local bpheight = y*0.01 
  
function onMyRender() 
local a,b,rot = getElementRotation(getLocalPlayer()) 
local dx,dy = GetPositionOnRec(rot,sx,sy,cx,cy,enx,eny) 
dxDrawRectangle(sx,sy,enx-sx,eny-sy,tocolor(150,150,150,100)) -- Radar simulation 
dxDrawRectangle(dx-(bpwidth/2),dy-(bpheight/2),bpwidth,bpheight,tocolor(255,0,0,255),true) -- random blip 
end 
addEventHandler("onClientRender",root, onMyRender) 
  
function GetPositionOnRec(rot,sx,sy,cx,cy,enx,eny) 
local start = {sx, sy} -- Start corner of map drawn 
local endp = {enx,eny} -- end corner of map drawn 
local center = {cx, cy} -- Center of map 
if rot < 360 and rot > 315 then 
    local progress = (rot - 315) / 45 
    sy,sx = start[2],interpolateBetween(start[1],0,0,center[1],0,0,progress,"Linear") 
elseif rot > 0 and rot < 45 then 
    local progress = (rot) / 45 
    sy,sx = start[2],interpolateBetween(center[1],0,0,endp[1],0,0,progress,"Linear") 
elseif rot > 45 and rot < 90 then 
    local progress = (rot-45) / 45 
    sx,sy = endp[1],interpolateBetween(start[2],0,0,center[2],0,0,progress,"Linear") 
elseif rot > 90 and rot < 135 then 
    local progress = (rot-90) / 45 
    sx,sy = endp[1],interpolateBetween(center[2],0,0,endp[2],0,0,progress,"Linear") 
elseif rot > 135 and rot < 180 then 
    local progress = (rot-135) / 45 
    sy,sx = endp[2],interpolateBetween(endp[1],0,0,center[1],0,0,progress,"Linear") 
elseif rot > 180 and rot < 225 then 
    local progress = (rot-180) / 45 
    sy,sx = endp[2],interpolateBetween(center[1],0,0,start[1],0,0,progress,"Linear") 
elseif rot > 225 and rot < 270 then 
    local progress = (rot-225) / 45 
    sx,sy = start[1],interpolateBetween(endp[2],0,0,center[2],0,0,progress,"Linear") 
elseif rot > 270 and rot < 315 then 
    local progress = (rot-270) / 45 
    sx,sy = start[1],interpolateBetween(center[2],0,0,start[2],0,0,progress,"Linear") 
end 
local Dx,Dy = sx,sy 
return Dx,Dy 
end 

Link to comment
I noticed that when running just the camera, the red dot (north) does not move.

And the rest of blips, they also managed to put?

hugs

That's becouse its measuring the ped's element rotation, not the camera rotation ^^. Its not north dot, i was just searching for a changing rotation value to test.

Link to comment
This is quite complicated, can you give a an example, how i should draw blips ?

Thanks!

Yeah, its not that hard, i wrote that code just now.

This should draw a simulation rectangle and a blip going arround with your ped rotation.

EDIT: My bad, i did some miscalculations and errors while writing down the code :mrgreen:

fully working example now. (Also fixed the function wich makes the magic, so please check.

  
  
local x,y = guiGetScreenSize() 
local sx,sy = x*0.1,y*0.8 
local cx,cy = x*0.15,y*0.85 
local enx,eny = x*0.2,y*0.9 
  
local bpwidth = x*0.01 
local bpheight = y*0.01 
  
function onMyRender() 
local a,b,rot = getElementRotation(getLocalPlayer()) 
local dx,dy = GetPositionOnRec(rot,sx,sy,cx,cy,enx,eny) 
dxDrawRectangle(sx,sy,enx-sx,eny-sy,tocolor(150,150,150,100)) -- Radar simulation 
dxDrawRectangle(dx-(bpwidth/2),dy-(bpheight/2),bpwidth,bpheight,tocolor(255,0,0,255),true) -- random blip 
end 
addEventHandler("onClientRender",root, onMyRender) 
  
function GetPositionOnRec(rot,sx,sy,cx,cy,enx,eny) 
local start = {sx, sy} -- Start corner of map drawn 
local endp = {enx,eny} -- end corner of map drawn 
local center = {cx, cy} -- Center of map 
if rot < 360 and rot > 315 then 
    local progress = (rot - 315) / 45 
    sy,sx = start[2],interpolateBetween(start[1],0,0,center[1],0,0,progress,"Linear") 
elseif rot > 0 and rot < 45 then 
    local progress = (rot) / 45 
    sy,sx = start[2],interpolateBetween(center[1],0,0,endp[1],0,0,progress,"Linear") 
elseif rot > 45 and rot < 90 then 
    local progress = (rot-45) / 45 
    sx,sy = endp[1],interpolateBetween(start[2],0,0,center[2],0,0,progress,"Linear") 
elseif rot > 90 and rot < 135 then 
    local progress = (rot-90) / 45 
    sx,sy = endp[1],interpolateBetween(center[2],0,0,endp[2],0,0,progress,"Linear") 
elseif rot > 135 and rot < 180 then 
    local progress = (rot-135) / 45 
    sy,sx = endp[2],interpolateBetween(endp[1],0,0,center[1],0,0,progress,"Linear") 
elseif rot > 180 and rot < 225 then 
    local progress = (rot-180) / 45 
    sy,sx = endp[2],interpolateBetween(center[1],0,0,start[1],0,0,progress,"Linear") 
elseif rot > 225 and rot < 270 then 
    local progress = (rot-225) / 45 
    sx,sy = start[1],interpolateBetween(endp[2],0,0,center[2],0,0,progress,"Linear") 
elseif rot > 270 and rot < 315 then 
    local progress = (rot-270) / 45 
    sx,sy = start[1],interpolateBetween(center[2],0,0,start[2],0,0,progress,"Linear") 
end 
local Dx,Dy = sx,sy 
return Dx,Dy 
end 

Thank you ALOT !

One big step done :)

I really appreciate your help

mta-screen_2014-10-19_11-19-27.png

mta-screen_2014-10-19_11-19-31.png

mta-screen_2014-10-19_11-19-33.png

but now, how to do the real blips ? I mean, not like the North blip, like the blips should be

I hope you understand :roll:

Link to comment

Well i think you have to replace the global blip system using exports. (I.e. create your own blip system.)

Another method i think it could be getting all blips wich are created in blip system done by MTA (just thought about that now)

  
local blips = getElementsByType("blip") 
  

You should then later on while drawing get all of its properties with all blip functions.

PD: I'm unsure if it is Blip or blip, please check.

https://wiki.multitheftauto.com/wiki/CreateBlip

https://wiki.multitheftauto.com/wiki/Element

EDIT: Yep, its "blip".

Enjoy scripting!

https://wiki.multitheftauto.com/wiki/Element/Blip

Link to comment
  • 1 month later...

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