Advertisement
Guest User

radar

a guest
May 23rd, 2019
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.00 KB | None | 0 0
  1. --------------------------------------------------------------------------------------------------
  2. -- Distributed under the Creative Commons Attribution-NonCommercial 4.0 International license --
  3. -- Version: (release) 1.0.0 --
  4. -- Original author: Kacper "MrTasty (aka Addon)" Stasiak --
  5. -- Special thanks to: Doomed_Space_Marine (useful functions) --
  6. -- robhol (useful functions) --
  7. --------------------------------------------------------------------------------------------------
  8.  
  9. --Features
  10. local enableBlips = true
  11. local renderNorthBlip = false
  12. local alwaysRenderMap = false --true = always render map, false = only render when in interior world 0 (radar will stay, only the map will stop rendering)
  13. local alwaysRenderOxygen = false --true = always render oxygen, false = only when oxygen not full/local player in water
  14. local disableGTASAhealth = true --Disable GTASA's HUD health display
  15. local disableGTASAarmor = true --Disable GTASA's HUD armour display
  16. local disableGTASAoxygen = true --Disable GTASA's HUD oxygen display
  17.  
  18. --Dimensions & Sizes
  19. local worldW, worldH = 2832, 2832 --map image dimensions - if map image changed, please edit appropriately
  20. local blip = 15 --Blip size, pixels relative to 1366x768 resolution
  21.  
  22.  
  23. ------------------------------------------------------------------------------------
  24. --Do not modify anything below unless you're absolutely sure of what you're doing.--
  25. ------------------------------------------------------------------------------------
  26.  
  27. local sx, sy = guiGetScreenSize()
  28. local rt = dxCreateRenderTarget(290, 175)
  29. local xFactor, yFactor = sx/1366, sy/768
  30. local yFactor = xFactor --otherwise the radar looses it's 2:3 ratio.
  31.  
  32.  
  33. -- Useful functions --
  34. function findRotation(x1,y1,x2,y2) --Author: Doomed_Space_Marine & robhol
  35. local t = -math.deg(math.atan2(x2-x1,y2-y1))
  36. if t < 0 then t = t + 360 end;
  37. return t;
  38. end
  39. function getPointFromDistanceRotation(x, y, dist, angle) --Author: robhol
  40. local a = math.rad(90 - angle);
  41. local dx = math.cos(a) * dist;
  42. local dy = math.sin(a) * dist;
  43. return x+dx, y+dy;
  44. end
  45.  
  46. function drawRadar()
  47. if getPedOccupiedVehicle(localPlayer) then
  48. setPlayerHudComponentVisible("radar", false)
  49. if disableGTASAhealth then setPlayerHudComponentVisible("health", false) end
  50. if disableGTASAarmor then setPlayerHudComponentVisible("armour", false) end
  51. if disableGTASAoxygen then setPlayerHudComponentVisible("breath", false) end
  52. if (not isPlayerMapVisible()) then
  53. local mW, mH = dxGetMaterialSize(rt)
  54. local x, y = getElementPosition(localPlayer)
  55. local X, Y = mW/2 -(x/(6000/worldW)), mH/2 +(y/(6000/worldH))
  56. local camX,camY,camZ = getElementRotation(getCamera())
  57. dxSetRenderTarget(rt, true)
  58. if alwaysRenderMap or getElementInterior(localPlayer) == 0 then
  59. dxDrawRectangle(0, 0, mW, mH, 0xFF7CA7D1) --render background
  60. dxDrawImage(X - worldW/2, mH/5 + (Y - worldH/2), worldW, worldH, "image/world.jpg", camZ, (x/(6000/worldW)), -(y/(6000/worldH)), tocolor(255, 255, 255, 255))
  61. end
  62. dxSetRenderTarget()
  63. dxDrawRectangle((9)*xFactor, sy-((220+3))*yFactor, (275)*xFactor, (165)*yFactor, tocolor(0, 0, 0, 150))
  64. dxDrawImage((09)*xFactor, sy-((220+3))*yFactor, (285-10)*xFactor, (165)*yFactor, rt, 0, 0, 0, tocolor(255, 255, 255, 150))
  65. local health = math.max(math.min(getElementHealth(localPlayer)/(0.232018558500192*getPedStat(localPlayer, 24) -32.018558511152), 1), 0)
  66. local armor = math.max(math.min(getPedArmor(localPlayer)/100, 1), 0)
  67. local oxygen = math.max(math.min(getPedOxygenLevel(localPlayer)/(1.5*getPedStat(localPlayer, 225) +1000), 1), 0)
  68. local r, g, b
  69. if health >= 0.25 then
  70. else
  71. end
  72. if alwaysRenderOxygen or (oxygen < 1 or isElementInWater(localPlayer)) then
  73. else
  74. end
  75. local rx, ry, rz = getElementRotation(localPlayer)
  76. local lB = (15)*xFactor
  77. local rB = (3+275)*xFactor
  78. local tB = sy-(230)*yFactor
  79. local bB = tB + (175)*yFactor
  80. local cX, cY = (rB+lB)/2, (tB+bB)/2 +(35)*yFactor
  81. local toLeft, toTop, toRight, toBottom = cX-lB, cY-tB, rB-cX, bB-cY
  82. for k, v in ipairs(getElementsByType("blip")) do
  83. local bx, by = getElementPosition(v)
  84. local actualDist = getDistanceBetweenPoints2D(x, y, bx, by)
  85. local maxDist = getBlipVisibleDistance(v)
  86. if actualDist <= maxDist and getElementDimension(v)==getElementDimension(localPlayer) and getElementInterior(v)==getElementInterior(localPlayer) then
  87. local dist = actualDist/(6000/((worldW+worldH)/2))
  88. local rot = findRotation(bx, by, x, y)-camZ
  89. local bpx, bpy = getPointFromDistanceRotation(cX, cY, math.min(dist, math.sqrt(toTop^2 + toRight^2)), rot)
  90. local bpx = math.max(lB, math.min(rB, bpx))
  91. local bpy = math.max(tB, math.min(bB, bpy))
  92. local bid = getElementData(v, "customIcon") or getBlipIcon(v)
  93. local _, _, _, bcA = getBlipColor(v)
  94. local bcR, bcG, bcB = 255, 255, 255
  95. if getBlipIcon(v) == 0 then
  96. bcR, bcG, bcB = getBlipColor(v)
  97. end
  98. local bS = getBlipSize(v)
  99. dxDrawImage(bpx -(blip*bS)*xFactor/2, bpy -(blip*bS)*yFactor/2, (blip*bS)*xFactor, (blip*bS)*yFactor, "image/blip/"..bid..".png", 0, 0, 0, tocolor(bcR, bcG, bcB, bcA))
  100. end
  101. end
  102. if renderNorthBlip then
  103. local rot = -camZ+180
  104. local bpx, bpy = getPointFromDistanceRotation(cX, cY, math.sqrt(toTop^2 + toRight^2), rot) --get position
  105. local bpx = math.max(lB, math.min(rB, bpx))
  106. local bpy = math.max(tB, math.min(bB, bpy)) --cap position to screen
  107. local dist = getDistanceBetweenPoints2D(cX, cY, bpx, bpy) --get distance to the capped position
  108. local bpx, bpy = getPointFromDistanceRotation(cX, cY, dist, rot) --re-calculate position based on new distance
  109. if bpx and bpy then --if position was obtained successfully
  110. local bpx = math.max(lB, math.min(rB, bpx))
  111. local bpy = math.max(tB, math.min(bB, bpy)) --cap position just in case
  112. dxDrawImage(bpx -(blip*2)/2, bpy -(blip*2)/2, blip*2, blip*2, "image/blip/4.png", 0, 0, 0) --draw north (4) blip
  113.  
  114. local vida1 = math.floor(getElementHealth(getLocalPlayer()))
  115. local vida2 = getPedMaxHealth(getLocalPlayer())
  116. local colete = math.floor(getPedArmor(getLocalPlayer()))
  117.  
  118. dxDrawRectangle(x*11, y*715, x*89, y*12, tocolor(255, 0, 0, 150), false)
  119. dxDrawRectangle(x*11, y*715, x*89/vida2*vida1, y*12, tocolor(255, 0, 0, 255), false)
  120.  
  121. dxDrawRectangle(x*102, y*715, x*89, y*12, tocolor(89, 89, 89, 150), false)
  122. dxDrawRectangle(x*102, y*715, x*89/100*colete, y*12, tocolor(100, 100, 100, 255), false)
  123. end
  124. end
  125. dxDrawImage(cX -(blip*2)*xFactor/2, cY -(blip*2)*yFactor/2, (blip*2)*xFactor, (blip*2)*yFactor, "image/player.png", camZ-rz, 0, 0)
  126. end
  127. end
  128. end
  129. addEventHandler("onClientRender", root, drawRadar)
  130.  
  131. addEventHandler("onClientResourceStop", resourceRoot, function()
  132. setPlayerHudComponentVisible("radar", false)
  133. if disableGTASAhealth then setPlayerHudComponentVisible("health", false) end
  134. if disableGTASAarmor then setPlayerHudComponentVisible("armour", false) end
  135. if disableGTASAoxygen then setPlayerHudComponentVisible("breath", false) end
  136. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement