Spectre Official Posted January 29, 2023 Share Posted January 29, 2023 (edited) My radar source is there; but radar areas, which is created with (createRadarArea) function, is not visible on the radar. How can I add it? 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 setPlayerHudComponentVisible("area_name", false) setPlayerHudComponentVisible("vehicle_name", false) setPlayerHudComponentVisible("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 January 29, 2023 by Vinyard code formatting Link to comment
Moderators Vinyard Posted January 29, 2023 Moderators Share Posted January 29, 2023 Moving this to the scripting section. Link to comment
Trust aka Tiffergan Posted January 29, 2023 Share Posted January 29, 2023 6 hours ago, Spectre7660 said: My radar source is there; but radar areas, which is created with (createRadarArea) function, is not visible on the radar. How can I add it? 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 setPlayerHudComponentVisible("area_name", false) setPlayerHudComponentVisible("vehicle_name", false) setPlayerHudComponentVisible("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) It looks like you are using the function createRadarArea to create a radar area, but it is not appearing on your radar. To make sure that the radar area is visible, you will need to make sure that it is being added to the element list that you are iterating through in the for loop starting on the following line: for k, v in ipairs(getElementsByType("blip")) do You will want to change this to include radar areas as well, for example: for k, v in ipairs(getElementsByType("blip", "radararea")) do This will ensure that the radar areas created with createRadarArea function are included in the list of elements being drawn on the radar. 1 Link to comment
Spectre Official Posted February 2, 2023 Author Share Posted February 2, 2023 On 30/01/2023 at 01:34, Trust aka Tiffergan said: It looks like you are using the function createRadarArea to create a radar area, but it is not appearing on your radar. To make sure that the radar area is visible, you will need to make sure that it is being added to the element list that you are iterating through in the for loop starting on the following line: for k, v in ipairs(getElementsByType("blip")) do You will want to change this to include radar areas as well, for example: for k, v in ipairs(getElementsByType("blip", "radararea")) do This will ensure that the radar areas created with createRadarArea function are included in the list of elements being drawn on the radar. Thanks for that, but how do I draw the radararea elements on the radar? Link to comment
Trust aka Tiffergan Posted February 2, 2023 Share Posted February 2, 2023 If the radar area created with the createRadarArea function is not visible, you may need to add it to the rendering process. To do this, you can modify the RADAR function that draws the radar on the screen and add code to draw the radar area. You can use the dxDrawMaterialLine3D function to draw the shape of the radar area on the radar. You will need to provide the position and size of the radar area, as well as the rotation angle, which can be obtained from the getElementRotation function. -- ... --# Blips local radarAreas = getElementsByType("radararea") for k, v in ipairs(radarAreas) do local x1, y1, z1, x2, y2, z2 = getRadarAreaSize(v) local minX, minY, minZ = math.min(x1, x2), math.min(y1, y2), math.min(z1, z2) local maxX, maxY, maxZ = math.max(x1, x2), math.max(y1, y2), math.max(z1, z2) local width, height, depth = maxX - minX, maxY - minY, maxZ - minZ local cx, cy, cz = (minX + maxX) / 2, (minY + maxY) / 2, (minZ + maxZ) / 2 local rot = getElementRotation(v) dxDrawMaterialLine3D(cx - width / 2, cy - height / 2, cz, cx + width / 2, cy - height / 2, cz, rt, 2, tocolor(255, 0, 0), cx, cy, cz, rot) dxDrawMaterialLine3D(cx + width / 2, cy - height / 2, cz, cx + width / 2, cy + height / 2, cz, rt, 2, tocolor(255, 0, 0), cx, cy, cz, rot) dxDrawMaterialLine3D(cx + width / 2, cy + height / 2, cz, cx - width / 2, cy + height / 2, cz, rt, 2, tocolor(255, 0, 0), cx, cy, cz, rot) dxDrawMaterialLine3D(cx - width / 2, cy + height / 2, cz, cx - width / 2, cy - height / 2, cz, rt, 2, tocolor(255, 0, 0), cx, cy, cz, rot) end -- ... This code will render the outline of each radar area in red color on the radar. You can modify the color and thickness of the lines as needed. Link to comment
Spectre Official Posted February 2, 2023 Author Share Posted February 2, 2023 46 minutes ago, Trust aka Tiffergan said: If the radar area created with the createRadarArea function is not visible, you may need to add it to the rendering process. To do this, you can modify the RADAR function that draws the radar on the screen and add code to draw the radar area. You can use the dxDrawMaterialLine3D function to draw the shape of the radar area on the radar. You will need to provide the position and size of the radar area, as well as the rotation angle, which can be obtained from the getElementRotation function. -- ... --# Blips local radarAreas = getElementsByType("radararea") for k, v in ipairs(radarAreas) do local x1, y1, z1, x2, y2, z2 = getRadarAreaSize(v) local minX, minY, minZ = math.min(x1, x2), math.min(y1, y2), math.min(z1, z2) local maxX, maxY, maxZ = math.max(x1, x2), math.max(y1, y2), math.max(z1, z2) local width, height, depth = maxX - minX, maxY - minY, maxZ - minZ local cx, cy, cz = (minX + maxX) / 2, (minY + maxY) / 2, (minZ + maxZ) / 2 local rot = getElementRotation(v) dxDrawMaterialLine3D(cx - width / 2, cy - height / 2, cz, cx + width / 2, cy - height / 2, cz, rt, 2, tocolor(255, 0, 0), cx, cy, cz, rot) dxDrawMaterialLine3D(cx + width / 2, cy - height / 2, cz, cx + width / 2, cy + height / 2, cz, rt, 2, tocolor(255, 0, 0), cx, cy, cz, rot) dxDrawMaterialLine3D(cx + width / 2, cy + height / 2, cz, cx - width / 2, cy + height / 2, cz, rt, 2, tocolor(255, 0, 0), cx, cy, cz, rot) dxDrawMaterialLine3D(cx - width / 2, cy + height / 2, cz, cx - width / 2, cy - height / 2, cz, rt, 2, tocolor(255, 0, 0), cx, cy, cz, rot) end -- ... This code will render the outline of each radar area in red color on the radar. You can modify the color and thickness of the lines as needed. line78: bad argument #2 to 'min' (number expected, got nil) I have to throw such errors because I have no coding knowledge, sorry. Link to comment
Spectre Official Posted February 8, 2023 Author Share Posted February 8, 2023 On 02/02/2023 at 19:23, Trust aka Tiffergan said: If the radar area created with the createRadarArea function is not visible, you may need to add it to the rendering process. To do this, you can modify the RADAR function that draws the radar on the screen and add code to draw the radar area. You can use the dxDrawMaterialLine3D function to draw the shape of the radar area on the radar. You will need to provide the position and size of the radar area, as well as the rotation angle, which can be obtained from the getElementRotation function. -- ... --# Blips local radarAreas = getElementsByType("radararea") for k, v in ipairs(radarAreas) do local x1, y1, z1, x2, y2, z2 = getRadarAreaSize(v) local minX, minY, minZ = math.min(x1, x2), math.min(y1, y2), math.min(z1, z2) local maxX, maxY, maxZ = math.max(x1, x2), math.max(y1, y2), math.max(z1, z2) local width, height, depth = maxX - minX, maxY - minY, maxZ - minZ local cx, cy, cz = (minX + maxX) / 2, (minY + maxY) / 2, (minZ + maxZ) / 2 local rot = getElementRotation(v) dxDrawMaterialLine3D(cx - width / 2, cy - height / 2, cz, cx + width / 2, cy - height / 2, cz, rt, 2, tocolor(255, 0, 0), cx, cy, cz, rot) dxDrawMaterialLine3D(cx + width / 2, cy - height / 2, cz, cx + width / 2, cy + height / 2, cz, rt, 2, tocolor(255, 0, 0), cx, cy, cz, rot) dxDrawMaterialLine3D(cx + width / 2, cy + height / 2, cz, cx - width / 2, cy + height / 2, cz, rt, 2, tocolor(255, 0, 0), cx, cy, cz, rot) dxDrawMaterialLine3D(cx - width / 2, cy + height / 2, cz, cx - width / 2, cy - height / 2, cz, rt, 2, tocolor(255, 0, 0), cx, cy, cz, rot) end -- ... This code will render the outline of each radar area in red color on the radar. You can modify the color and thickness of the lines as needed. line78: bad argument #2 to 'min' (number expected, got nil) I have to throw such errors because I have no coding knowledge, sorry. Link to comment
FLUSHBICEPS Posted February 8, 2023 Share Posted February 8, 2023 -- ... --# Blips local radarAreas = getElementsByType("radararea") for k, v in ipairs(radarAreas) do -- Get the size of the radar area local x1, y1, z1, x2, y2, z2 = getRadarAreaSize(v) -- Ensure that x1, y1, z1, x2, y2, z2 are all numbers if type(x1) == "number" and type(y1) == "number" and type(z1) == "number" and type(x2) == "number" and type(y2) == "number" and type(z2) == "number" then -- Calculate the minimum and maximum values for x, y, z local minX, minY, minZ = math.min(x1, x2), math.min(y1, y2), math.min(z1, z2) local maxX, maxY, maxZ = math.max(x1, x2), math.max(y1, y2), math.max(z1, z2) -- Calculate the width, height, and depth local width, height, depth = maxX - minX, maxY - minY, maxZ - minZ -- Calculate the center x, y, and z values local cx, cy, cz = (minX + maxX) / 2, (minY + maxY) / 2, (minZ + maxZ) / 2 -- Get the rotation of the radar area local rot = getElementRotation(v) -- Draw the lines for the radar area dxDrawMaterialLine3D(cx - width / 2, cy - height / 2, cz, cx + width / 2, cy - height / 2, cz, rt, 2, tocolor(255, 0, 0), cx, cy, cz, rot) dxDrawMaterialLine3D(cx + width / 2, cy - height / 2, cz, cx + width / 2, cy + height / 2, cz, rt, 2, tocolor(255, 0, 0), cx, cy, cz, rot) dxDrawMaterialLine3D(cx + width / 2, cy + height / 2, cz, cx - width / 2, cy + height / 2, cz, rt, 2, tocolor(255, 0, 0), cx, cy, cz, rot) dxDrawMaterialLine3D(cx - width / 2, cy + height / 2, cz, cx - width / 2, cy - height / 2, cz, rt, 2, tocolor(255, 0, 0), cx, cy, cz, rot) end end Link to comment
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now