Jump to content

RADAR DOES NOT APPEAR INSIDE


zRiaan

Recommended Posts

I have a problem with the radar and I do not know how to solve it, with the radar activated, I go into some interior and the radar, hud does not work, could you help me?

--# Client

local enableBlips = true
local renderNorthBlip = true
local alwaysRenderMap = false 

local worldW, worldH = 1800,1800 
local blip = 8 

local sx, sy = guiGetScreenSize()
local rt = dxCreateRenderTarget(290,175)
local xFactor, yFactor = sx/1366,sy/768
local yFactor = xFactor 

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

function getPointFromDistanceRotation(x, y, dist, angle) 
    local a = math.rad(90 - angle);
    local dx = math.cos(a) * dist;
    local dy = math.sin(a) * dist;
    return x+dx, y+dy;
end

function RADAR()
        --Radar config
        showPlayerHudComponent("area_name", false)
        showPlayerHudComponent("vehicle_name", false)
        showPlayerHudComponent("radar", false)
        local mW, mH = dxGetMaterialSize(rt)
        local x, y = getElementPosition(localPlayer)
        local X, Y = mW/2 -(x/(6000/worldW)), mH/2 +(y/(6000/worldH))
        local camX,camY,camZ = getElementRotation(getCamera())
        dxSetRenderTarget(rt, true)
        if alwaysRenderMap or getElementInterior(localPlayer) == 0 then
        dxDrawRectangle(0, 0, mW, mH, 0xFF7CA7D1) 
        dxDrawImage(X - worldW/2, mH/5 + (Y - worldH/2), worldW, worldH, "gfx/world.png", camZ, (x/(6000/worldW)), -(y/(6000/worldH)))
        --
        dxSetRenderTarget()
        dxDrawImage((18)*xFactor, sy-((216))*yFactor, (293)*xFactor, (177)*yFactor, "gfx/radarbg.png", 0, 0, 0, tocolor(0, 0, 0, 180))
        dxDrawImage((30+5)*xFactor, sy-((200+5))*yFactor, (270-10)*xFactor, (155)*yFactor, rt, 0, 0, 0, tocolor(255, 255, 255, 80))
        --# Blips
        local rx, ry, rz = getElementRotation(localPlayer)
        local lB = (33)*xFactor
        local rB = (8+290)*xFactor
        local tB = sy-(208)*yFactor
        local bB = tB + (155)*yFactor
        local cX, cY = (rB+lB)/2, (tB+bB)/2 +(35)*yFactor
        local toLeft, toTop, toRight, toBottom = cX-lB, cY-tB, rB-cX, bB-cY
        for k, v in ipairs(getElementsByType("blip")) do
            local bx, by = getElementPosition(v)
            local actualDist = getDistanceBetweenPoints2D(x, y, bx, by)
            local maxDist = getBlipVisibleDistance(v)
            if actualDist <= maxDist and getElementDimension(v)==getElementDimension(localPlayer) and getElementInterior(v)==getElementInterior(localPlayer) then
                local dist = actualDist/(6000/((worldW+worldH)/2))
                local rot = findRotation(bx, by, x, y)-camZ
                local bpx, bpy = getPointFromDistanceRotation(cX, cY, math.min(dist, math.sqrt(toTop^2 + toRight^2)), rot)
                local bpx = math.max(lB, math.min(rB, bpx))
                local bpy = math.max(tB, math.min(bB, bpy))
                local bid = getElementData(v, "customIcon") or getBlipIcon(v)
                local _, _, _, bcA = getBlipColor(v)
                local bcR, bcG, bcB = 255, 255, 255
                if getBlipIcon(v) == 0 then
                    bcR, bcG, bcB = getBlipColor(v)
                end
                local bS = getBlipSize(v)
                dxDrawImage(bpx -(blip*bS)*xFactor/2, bpy -(blip*bS)*yFactor/2, (blip*bS)*xFactor, (blip*bS)*yFactor, "gfx/blip/"..bid..".png", 0, 0, 0, tocolor(bcR, bcG, bcB, bcA))
            end
        end
        if renderNorthBlip then
            local rot = -camZ+180
            local bpx, bpy = getPointFromDistanceRotation(cX, cY, math.sqrt(toTop^2 + toRight^2), rot) 
            local bpx = math.max(lB, math.min(rB, bpx))
            local bpy = math.max(tB, math.min(bB, bpy)) 
            local dist = getDistanceBetweenPoints2D(cX, cY, bpx, bpy) 
            local bpx, bpy = getPointFromDistanceRotation(cX, cY, dist, rot) 
            if bpx and bpy then 
            local bpx = math.max(lB, math.min(rB, bpx))
            local bpy = math.max(tB, math.min(bB, bpy)) 
            dxDrawImage(bpx -(blip*2)/2,bpy -(blip*2)/2,blip*2,blip*2,"gfx/blip/4.png",0,0,0)
            end
        end
        dxDrawImage(cX -(blip*2)*xFactor/2,cY -(blip*2)*yFactor/2,(blip*2)*xFactor,(blip*2)*yFactor, "gfx/player.png", camZ-rz, 0, 0)
    end
end
addEventHandler("onClientRender", root, RADAR)

function Visible()
    if isVisible then
        addEventHandler("onClientRender", root, RADAR)
    else
        removeEventHandler("onClientRender", root, RADAR)
    end
    isVisible = not isVisible
end
bindKey ("F11", "down", Visible)

 

Edited by zRiaan
Link to comment
--# Client

local enableBlips = true
local renderNorthBlip = true
local alwaysRenderMap = false 

local worldW, worldH = 1800,1800 
local blip = 8 

local sx, sy = guiGetScreenSize()
local rt = dxCreateRenderTarget(290,175)
local xFactor, yFactor = sx/1366,sy/768
local yFactor = xFactor 

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

function getPointFromDistanceRotation(x, y, dist, angle) 
  local a = math.rad(90 - angle);
  local dx = math.cos(a) * dist;
  local dy = math.sin(a) * dist;
  return x+dx, y+dy;
end

function RADAR()
  --Radar config
  showPlayerHudComponent("area_name", false)
  showPlayerHudComponent("vehicle_name", false)
  showPlayerHudComponent("radar", false)
  local mW, mH = dxGetMaterialSize(rt)
  local x, y = getElementPosition(localPlayer)
  local X, Y = mW/2 -(x/(6000/worldW)), mH/2 +(y/(6000/worldH))
  local camX,camY,camZ = getElementRotation(getCamera())
  dxSetRenderTarget(rt, true)
  if alwaysRenderMap or getElementInterior(localPlayer) == 0 then
    dxDrawRectangle(0, 0, mW, mH, 0xFF7CA7D1) 
    dxDrawImage(X - worldW/2, mH/5 + (Y - worldH/2), worldW, worldH, "gfx/world.png", camZ, (x/(6000/worldW)), -(y/(6000/worldH)))
    --
    dxSetRenderTarget()
    dxDrawImage((18)*xFactor, sy-((216))*yFactor, (293)*xFactor, (177)*yFactor, "gfx/radarbg.png", 0, 0, 0, tocolor(0, 0, 0, 180))
    dxDrawImage((30+5)*xFactor, sy-((200+5))*yFactor, (270-10)*xFactor, (155)*yFactor, rt, 0, 0, 0, tocolor(255, 255, 255, 80))
  end -- //// the end is supposed to be here ////
  --# Blips
  local rx, ry, rz = getElementRotation(localPlayer)
  local lB = (33)*xFactor
  local rB = (8+290)*xFactor
  local tB = sy-(208)*yFactor
  local bB = tB + (155)*yFactor
  local cX, cY = (rB+lB)/2, (tB+bB)/2 +(35)*yFactor
  local toLeft, toTop, toRight, toBottom = cX-lB, cY-tB, rB-cX, bB-cY
  for k, v in ipairs(getElementsByType("blip")) do
    local bx, by = getElementPosition(v)
    local actualDist = getDistanceBetweenPoints2D(x, y, bx, by)
    local maxDist = getBlipVisibleDistance(v)
    if actualDist <= maxDist and getElementDimension(v)==getElementDimension(localPlayer) and getElementInterior(v)==getElementInterior(localPlayer) then
      local dist = actualDist/(6000/((worldW+worldH)/2))
      local rot = findRotation(bx, by, x, y)-camZ
      local bpx, bpy = getPointFromDistanceRotation(cX, cY, math.min(dist, math.sqrt(toTop^2 + toRight^2)), rot)
      local bpx = math.max(lB, math.min(rB, bpx))
      local bpy = math.max(tB, math.min(bB, bpy))
      local bid = getElementData(v, "customIcon") or getBlipIcon(v)
      local _, _, _, bcA = getBlipColor(v)
      local bcR, bcG, bcB = 255, 255, 255
      if getBlipIcon(v) == 0 then
        bcR, bcG, bcB = getBlipColor(v)
      end
      local bS = getBlipSize(v)
      dxDrawImage(bpx -(blip*bS)*xFactor/2, bpy -(blip*bS)*yFactor/2, (blip*bS)*xFactor, (blip*bS)*yFactor, "gfx/blip/"..bid..".png", 0, 0, 0, tocolor(bcR, bcG, bcB, bcA))
    end -- //// (this end is correct) ////
    -- //// end was incorrectly placed here ////
    if renderNorthBlip then
      local rot = -camZ+180
      local bpx, bpy = getPointFromDistanceRotation(cX, cY, math.sqrt(toTop^2 + toRight^2), rot) 
      local bpx = math.max(lB, math.min(rB, bpx))
      local bpy = math.max(tB, math.min(bB, bpy)) 
      local dist = getDistanceBetweenPoints2D(cX, cY, bpx, bpy) 
      local bpx, bpy = getPointFromDistanceRotation(cX, cY, dist, rot) 
      if bpx and bpy then 
        local bpx = math.max(lB, math.min(rB, bpx))
        local bpy = math.max(tB, math.min(bB, bpy)) 
        dxDrawImage(bpx -(blip*2)/2,bpy -(blip*2)/2,blip*2,blip*2,"gfx/blip/4.png",0,0,0)
      end
    end
    dxDrawImage(cX -(blip*2)*xFactor/2,cY -(blip*2)*yFactor/2,(blip*2)*xFactor,(blip*2)*yFactor, "gfx/player.png", camZ-rz, 0, 0)
  end
end
addEventHandler("onClientRender", root, RADAR)

function Visible()
  if isVisible then
    addEventHandler("onClientRender", root, RADAR)
  else
    removeEventHandler("onClientRender", root, RADAR)
  end
  isVisible = not isVisible
end
bindKey ("F11", "down", Visible)

There was a misplaced 'end' at the end of blips section instead of being at the end of map-render section. The above code is corrected, and I've included comments regarding where the error was, marked by -- //// comment //// to distinguish it from the original comments.

The code will not render the map when inside an interior. If you prefer the map to be rendered at any time, regardless of interior world, set the variable alwaysRenderMap to true.

P.S. Next time, when including any code, use [­code­] markup as it's easier to read.

Edited by MrTasty
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...