Advertisement
Guest User

Untitled

a guest
May 26th, 2018
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 27.03 KB | None | 0 0
  1. Display = {};
  2. Display.Width, Display.Height = guiGetScreenSize();
  3.  
  4. Minimap = {};
  5. Minimap.Width = 265;
  6. Minimap.Height = 190;
  7. Minimap.PosX = 20;
  8. Minimap.PosY = (Display.Height - 20) - Minimap.Height;
  9.  
  10. Minimap.IsVisible = true;
  11. Minimap.TextureSize = radarSettings['mapTextureSize'];
  12. Minimap.NormalTargetSize, Minimap.BiggerTargetSize = Minimap.Width, Minimap.Width * 2;
  13. Minimap.MapTarget = dxCreateRenderTarget(Minimap.BiggerTargetSize, Minimap.BiggerTargetSize, true);
  14. Minimap.RenderTarget = dxCreateRenderTarget(Minimap.NormalTargetSize * 3, Minimap.NormalTargetSize * 3, true);
  15. Minimap.MapTexture = dxCreateTexture(radarSettings['mapTexture']);
  16.  
  17. Minimap.CurrentZoom = 5;
  18. Minimap.MaximumZoom = 10;
  19. Minimap.MinimumZoom = 2;
  20.  
  21. Minimap.WaterColor = radarSettings['mapWaterColor'];
  22. Minimap.Alpha = radarSettings['alpha'];
  23. Minimap.PlayerInVehicle = false;
  24. Minimap.LostRotation = 0;
  25. Minimap.MapUnit = Minimap.TextureSize / 6000;
  26.  
  27. Bigmap = {};
  28. Bigmap.Width, Bigmap.Height = Display.Width - 40, Display.Height - 40;
  29. Bigmap.PosX, Bigmap.PosY = 20, 20;
  30. Bigmap.IsVisible = false;
  31. Bigmap.CurrentZoom = 2;
  32. Bigmap.MinimumZoom = 1.5;
  33. Bigmap.MaximumZoom = 5;
  34.  
  35. Fonts = {};
  36. Fonts.Roboto = dxCreateFont('files/fonts/roboto.ttf', 25, false, 'antialiased');
  37. Fonts.Icons = dxCreateFont('files/fonts/icons.ttf', 25, false, 'antialiased');
  38.  
  39. Stats = {};
  40. Stats.Bar = {};
  41. Stats.Bar.Width = Minimap.Width;
  42. Stats.Bar.Height = 10;
  43.  
  44. local playerX, playerY, playerZ = 0, 0, 0;
  45. local mapOffsetX, mapOffsetY, mapIsMoving = 0, 0, false;
  46.  
  47. addEventHandler('onClientResourceStart', resourceRoot,
  48.     function()
  49.         showPlayerHudComponent('radar', false);
  50.        
  51.         if (Minimap.MapTexture) then
  52.             dxSetTextureEdge(Minimap.MapTexture, 'border', tocolor(Minimap.WaterColor[1], Minimap.WaterColor[2], Minimap.WaterColor[3], 255));
  53.         end
  54.     end
  55. );
  56.  
  57. addEventHandler('onClientKey', root,
  58.     function(key, state)
  59.         if (state) then
  60.             if (key == 'F11') then
  61.                 cancelEvent();
  62.                 Bigmap.IsVisible = not Bigmap.IsVisible;
  63.                 showCursor(false);
  64.                
  65.                 if (Bigmap.IsVisible) then
  66.                     showPlayerHudComponent('all', false);
  67.                     showChat(false);
  68.                     playSoundFrontEnd(1);
  69.                     Minimap.IsVisible = false;
  70.                 else
  71.                     showPlayerHudComponent('all', true);
  72.                     showPlayerHudComponent('radar', false);
  73.                     showChat(true);
  74.                     playSoundFrontEnd(2);
  75.                     Minimap.IsVisible = true;
  76.                     mapOffsetX, mapOffsetY, mapIsMoving = 0, 0, false;
  77.                 end
  78.             elseif (key == 'mouse_wheel_down' and Bigmap.IsVisible) then
  79.                 Bigmap.CurrentZoom = math.min(Bigmap.CurrentZoom + 0.5, Bigmap.MaximumZoom);
  80.             elseif (key == 'mouse_wheel_up' and Bigmap.IsVisible) then
  81.                 Bigmap.CurrentZoom = math.max(Bigmap.CurrentZoom - 0.5, Bigmap.MinimumZoom);
  82.             elseif (key == 'lctrl' and Bigmap.IsVisible) then
  83.                 showCursor(not isCursorShowing());
  84.             end
  85.         end
  86.     end
  87. );
  88.  
  89. addEventHandler('onClientClick', root,
  90.     function(button, state, cursorX, cursorY)
  91.         if (not Minimap.IsVisible and Bigmap.IsVisible) then
  92.             if (button == 'left' and state == 'down') then
  93.                 if (cursorX >= Bigmap.PosX and cursorX <= Bigmap.PosX + Bigmap.Width) then
  94.                     if (cursorY >= Bigmap.PosY and cursorY <= Bigmap.PosY + Bigmap.Height) then
  95.                         mapOffsetX = cursorX * Bigmap.CurrentZoom + playerX;
  96.                         mapOffsetY = cursorY * Bigmap.CurrentZoom - playerY;
  97.                         mapIsMoving = true;
  98.                     end
  99.                 end
  100.             elseif (button == 'left' and state == 'up') then
  101.                 mapIsMoving = false;
  102.             end
  103.         end
  104.     end
  105. );
  106.  
  107. addEventHandler('onClientRender', root,
  108.     function()
  109.         if (not Minimap.IsVisible and Bigmap.IsVisible) then
  110.             dxDrawBorder(Bigmap.PosX, Bigmap.PosY, Bigmap.Width, Bigmap.Height, 2, tocolor(0, 0, 0, 200));
  111.            
  112.             local absoluteX, absoluteY = 0, 0;
  113.             local zoneName = 'Unknown';
  114.            
  115.             if (getElementInterior(localPlayer) == 0) then
  116.                 if (isCursorShowing()) then
  117.                     local cursorX, cursorY = getCursorPosition();
  118.                     local mapX, mapY = getWorldFromMapPosition(cursorX, cursorY);
  119.                    
  120.                     absoluteX = cursorX * Display.Width;
  121.                     absoluteY = cursorY * Display.Height;
  122.                    
  123.                     if (getKeyState('mouse1') and mapIsMoving) then
  124.                         playerX = -(absoluteX * Bigmap.CurrentZoom - mapOffsetX);
  125.                         playerY = absoluteY * Bigmap.CurrentZoom - mapOffsetY;
  126.                        
  127.                         playerX = math.max(-3000, math.min(3000, playerX));
  128.                         playerY = math.max(-3000, math.min(3000, playerY));
  129.                     end
  130.                    
  131.                     if (not mapIsMoving) then
  132.                         if (Bigmap.PosX <= absoluteX and Bigmap.PosY <= absoluteY and Bigmap.PosX + Bigmap.Width >= absoluteX and Bigmap.PosY + Bigmap.Height >= absoluteY) then
  133.                             zoneName = getZoneName(mapX, mapY, 0);
  134.                         else
  135.                             zoneName = 'Unknown';
  136.                         end
  137.                     else
  138.                         zoneName = 'Unknown';
  139.                     end
  140.                 else
  141.                     playerX, playerY, playerZ = getElementPosition(localPlayer);
  142.                     zoneName = getZoneName(playerX, playerY, playerZ);
  143.                 end
  144.                
  145.                 local playerRotation = getPedRotation(localPlayer);
  146.                 local mapX = (((3000 + playerX) * Minimap.MapUnit) - (Bigmap.Width / 2) * Bigmap.CurrentZoom);
  147.                 local mapY = (((3000 - playerY) * Minimap.MapUnit) - (Bigmap.Height / 2) * Bigmap.CurrentZoom);
  148.                 local mapWidth, mapHeight = Bigmap.Width * Bigmap.CurrentZoom, Bigmap.Height * Bigmap.CurrentZoom;
  149.  
  150.                 dxDrawImageSection(Bigmap.PosX, Bigmap.PosY, Bigmap.Width, Bigmap.Height, mapX, mapY, mapWidth, mapHeight, Minimap.MapTexture, 0, 0, 0, tocolor(255, 255, 255, Minimap.Alpha));
  151.                
  152.                 --> Radar area
  153.                 for _, area in ipairs(getElementsByType('radararea')) do
  154.                     local areaX, areaY = getElementPosition(area);
  155.                     local areaWidth, areaHeight = getRadarAreaSize(area);
  156.                     local areaR, areaG, areaB, areaA = getRadarAreaColor(area);
  157.                        
  158.                     if (isRadarAreaFlashing(area)) then
  159.                         areaA = areaA * math.abs(getTickCount() % 1000 - 500) / 500;
  160.                     end
  161.                    
  162.                     local areaX, areaY = getMapFromWorldPosition(areaX, areaY + areaHeight);
  163.                     local areaWidth, areaHeight = areaWidth / Bigmap.CurrentZoom * Minimap.MapUnit, areaHeight / Bigmap.CurrentZoom * Minimap.MapUnit;
  164.  
  165.                     --** Width
  166.                     if (areaX < Bigmap.PosX) then
  167.                         areaWidth = areaWidth - math.abs((Bigmap.PosX) - (areaX));
  168.                         areaX = areaX + math.abs((Bigmap.PosX) - (areaX));
  169.                     end
  170.                    
  171.                     if (areaX + areaWidth > Bigmap.PosX + Bigmap.Width) then
  172.                         areaWidth = areaWidth - math.abs((Bigmap.PosX + Bigmap.Width) - (areaX + areaWidth));
  173.                     end
  174.                    
  175.                     if (areaX > Bigmap.PosX + Bigmap.Width) then
  176.                         areaWidth = areaWidth + math.abs((Bigmap.PosX + Bigmap.Width) - (areaX));
  177.                         areaX = areaX - math.abs((Bigmap.PosX + Bigmap.Width) - (areaX));
  178.                     end
  179.                    
  180.                     if (areaX + areaWidth < Bigmap.PosX) then
  181.                         areaWidth = areaWidth + math.abs((Bigmap.PosX) - (areaX + areaWidth));
  182.                         areaX = areaX - math.abs((Bigmap.PosX) - (areaX + areaWidth));
  183.                     end
  184.                    
  185.                     --** Height
  186.                     if (areaY < Bigmap.PosY) then
  187.                         areaHeight = areaHeight - math.abs((Bigmap.PosY) - (areaY));
  188.                         areaY = areaY + math.abs((Bigmap.PosY) - (areaY));
  189.                     end
  190.                    
  191.                     if (areaY + areaHeight > Bigmap.PosY + Bigmap.Height) then
  192.                         areaHeight = areaHeight - math.abs((Bigmap.PosY + Bigmap.Height) - (areaY + areaHeight));
  193.                     end
  194.                    
  195.                     if (areaY + areaHeight < Bigmap.PosY) then
  196.                         areaHeight = areaHeight + math.abs((Bigmap.PosY) - (areaY + areaHeight));
  197.                         areaY = areaY - math.abs((Bigmap.PosY) - (areaY + areaHeight));
  198.                     end
  199.                    
  200.                     if (areaY > Bigmap.PosY + Bigmap.Height) then
  201.                         areaHeight = areaHeight + math.abs((Bigmap.PosY + Bigmap.Height) - (areaY));
  202.                         areaY = areaY - math.abs((Bigmap.PosY + Bigmap.Height) - (areaY));
  203.                     end
  204.                    
  205.                     --** Draw
  206.                     dxDrawRectangle(areaX, areaY, areaWidth, areaHeight, tocolor(areaR, areaG, areaB, areaA), false);
  207.                 end
  208.                
  209.                 --> Blips
  210.                 for _, blip in ipairs(getElementsByType('blip')) do
  211.                     local blipX, blipY, blipZ = getElementPosition(blip);
  212.  
  213.                     if (localPlayer ~= getElementAttachedTo(blip)) then
  214.                         local blipSettings = {
  215.                             ['color'] = {255, 255, 255, 255},
  216.                             ['size'] = getElementData(blip, 'blipSize') or 20,
  217.                             ['icon'] = getElementData(blip, 'blipIcon') or 'target',
  218.                             ['exclusive'] = getElementData(blip, 'exclusiveBlip') or false
  219.                         };
  220.                        
  221.                         if (blipSettings['icon'] == 'target' or blipSettings['icon'] == 'waypoint') then
  222.                             blipSettings['color'] = {getBlipColor(blip)};
  223.                         end
  224.                        
  225.                         local centerX, centerY = (Bigmap.PosX + (Bigmap.Width / 2)), (Bigmap.PosY + (Bigmap.Height / 2));
  226.                         local leftFrame = (centerX - Bigmap.Width / 2) + (blipSettings['size'] / 2);
  227.                         local rightFrame = (centerX + Bigmap.Width / 2) - (blipSettings['size'] / 2);
  228.                         local topFrame = (centerY - Bigmap.Height / 2) + (blipSettings['size'] / 2);
  229.                         local bottomFrame = (centerY + Bigmap.Height / 2) - (blipSettings['size'] / 2);
  230.                         local blipX, blipY = getMapFromWorldPosition(blipX, blipY);
  231.                        
  232.                         centerX = math.max(leftFrame, math.min(rightFrame, blipX));
  233.                         centerY = math.max(topFrame, math.min(bottomFrame, blipY));
  234.  
  235.                         dxDrawImage(centerX - (blipSettings['size'] / 2), centerY - (blipSettings['size'] / 2), blipSettings['size'], blipSettings['size'], 'files/images/blips/' .. blipSettings['icon'] .. '.png', 0, 0, 0, tocolor(blipSettings['color'][1], blipSettings['color'][2], blipSettings['color'][3], blipSettings['color'][4]));
  236.                     end
  237.                 end
  238.                
  239.                 for _, player in ipairs(getElementsByType('player')) do
  240.                     local otherPlayerX, otherPlayerY, otherPlayerZ = getElementPosition(player);
  241.                        
  242.                     if (localPlayer ~= player) then
  243.                         local playerIsVisible = false;
  244.                         local blipSettings = {
  245.                             ['color'] = {255, 255, 255, 255},
  246.                             ['size'] = 25,
  247.                             ['icon'] = 'player'
  248.                         };
  249.                        
  250.                         blipSettings['color'] = {getPlayerNametagColor(player)};
  251.  
  252.                         local blipX, blipY = getMapFromWorldPosition(otherPlayerX, otherPlayerY);
  253.                        
  254.                         if (blipX >= Bigmap.PosX and blipX <= Bigmap.PosX + Bigmap.Width) then
  255.                             if (blipY >= Bigmap.PosY and blipY <= Bigmap.PosY + Bigmap.Height) then
  256.                                 dxDrawImage(blipX - (blipSettings['size'] / 2), blipY - (blipSettings['size'] / 2), blipSettings['size'], blipSettings['size'], 'files/images/blips/' .. blipSettings['icon'] .. '.png', 0, 0, 0, tocolor(blipSettings['color'][1], blipSettings['color'][2], blipSettings['color'][3], blipSettings['color'][4]));
  257.                             end
  258.                         end
  259.                     end
  260.                 end
  261.                
  262.                 --> Local player
  263.                 local localX, localY, localZ = getElementPosition(localPlayer);
  264.                 local blipX, blipY = getMapFromWorldPosition(localX, localY);
  265.                        
  266.                 if (blipX >= Bigmap.PosX and blipX <= Bigmap.PosX + Bigmap.Width) then
  267.                     if (blipY >= Bigmap.PosY and blipY <= Bigmap.PosY + Bigmap.Height) then
  268.                         dxDrawImage(blipX - 10, blipY - 10, 20, 20, 'files/images/arrow.png', 360 - playerRotation);
  269.                     end
  270.                 end
  271.                
  272.                 --> GPS Location
  273.                 dxDrawRectangle(Bigmap.PosX, (Bigmap.PosY + Bigmap.Height) - 25, Bigmap.Width, 25, tocolor(0, 0, 0, 200));
  274.                 dxDrawText(zoneName, Bigmap.PosX + 10, (Bigmap.PosY + Bigmap.Height) - 25, Bigmap.PosX + 10 + Bigmap.Width - 20, (Bigmap.PosY + Bigmap.Height), tocolor(255, 255, 255, 255), 0.50, Fonts.Roboto, 'left', 'center');
  275.             else
  276.                 dxDrawRectangle(Bigmap.PosX, Bigmap.PosY, Bigmap.Width, Bigmap.Height, tocolor(0, 0, 0, 150));
  277.                 dxDrawText('GPS lost connection...', Bigmap.PosX, Bigmap.PosY + 20, Bigmap.PosX + Bigmap.Width, Bigmap.PosY + 20 + Bigmap.Height, tocolor(255, 255, 255, 255 * math.abs(getTickCount() % 2000 - 1000) / 1000), 0.40, Fonts.Roboto, 'center', 'center', false, false, false, true, true);
  278.                 dxDrawText('', Bigmap.PosX, Bigmap.PosY - 20, Bigmap.PosX + Bigmap.Width, Bigmap.PosY - 20 + Bigmap.Height, tocolor(255, 255, 255, 255 * math.abs(getTickCount() % 2000 - 1000) / 1000), 1.00, Fonts.Icons, 'center', 'center', false, false, false, true, true);
  279.                
  280.                 if (Minimap.LostRotation > 360) then
  281.                     Minimap.LostRotation = 0;
  282.                 end
  283.                
  284.                 dxDrawText('', (Bigmap.PosX + Bigmap.Width - 25), Bigmap.PosY, (Bigmap.PosX + Bigmap.Width - 25) + 25, Bigmap.PosY + 25, tocolor(255, 255, 255, 100), 0.50, Fonts.Icons, 'center', 'center', false, false, false, true, true, Minimap.LostRotation);
  285.                 Minimap.LostRotation = Minimap.LostRotation + 1;
  286.             end
  287.         elseif (Minimap.IsVisible and not Bigmap.IsVisible) then
  288.             if (radarSettings['showStats']) then
  289.                 Minimap.PosY = ((Display.Height - 20) - Stats.Bar.Height) - Minimap.Height;
  290.             else
  291.                 Minimap.PosY = (Display.Height - 20) - Minimap.Height;
  292.             end
  293.            
  294.             dxDrawBorder(Minimap.PosX, Minimap.PosY, Minimap.Width, Minimap.Height, 2, tocolor(0, 0, 0, 200));
  295.            
  296.             if (getElementInterior(localPlayer) == 0) then
  297.                 Minimap.PlayerInVehicle = getPedOccupiedVehicle(localPlayer);
  298.                 playerX, playerY, playerZ = getElementPosition(localPlayer);
  299.                
  300.                 --> Calculate positions
  301.                 local playerRotation = getPedRotation(localPlayer);
  302.                 local playerMapX, playerMapY = (3000 + playerX) / 6000 * Minimap.TextureSize, (3000 - playerY) / 6000 * Minimap.TextureSize;
  303.                 local streamDistance, pRotation = getRadarRadius(), getRotation();
  304.                 local mapRadius = streamDistance / 6000 * Minimap.TextureSize * Minimap.CurrentZoom;
  305.                 local mapX, mapY, mapWidth, mapHeight = playerMapX - mapRadius, playerMapY - mapRadius, mapRadius * 2, mapRadius * 2;
  306.                
  307.                 --> Set world
  308.                 dxSetRenderTarget(Minimap.MapTarget, true);
  309.                 dxDrawRectangle(0, 0, Minimap.BiggerTargetSize, Minimap.BiggerTargetSize, tocolor(Minimap.WaterColor[1], Minimap.WaterColor[2], Minimap.WaterColor[3], Minimap.Alpha), false);
  310.                 dxDrawImageSection(0, 0, Minimap.BiggerTargetSize, Minimap.BiggerTargetSize, mapX, mapY, mapWidth, mapHeight, Minimap.MapTexture, 0, 0, 0, tocolor(255, 255, 255, Minimap.Alpha), false);
  311.                
  312.                 --> Draw radar areas
  313.                 for _, area in ipairs(getElementsByType('radararea')) do
  314.                     local areaX, areaY = getElementPosition(area);
  315.                     local areaWidth, areaHeight = getRadarAreaSize(area);
  316.                     local areaMapX, areaMapY, areaMapWidth, areaMapHeight = (3000 + areaX) / 6000 * Minimap.TextureSize, (3000 - areaY) / 6000 * Minimap.TextureSize, areaWidth / 6000 * Minimap.TextureSize, -(areaHeight / 6000 * Minimap.TextureSize);
  317.                    
  318.                     if (doesCollide(playerMapX - mapRadius, playerMapY - mapRadius, mapRadius * 2, mapRadius * 2, areaMapX, areaMapY, areaMapWidth, areaMapHeight)) then
  319.                         local areaR, areaG, areaB, areaA = getRadarAreaColor(area);
  320.                        
  321.                         if (isRadarAreaFlashing(area)) then
  322.                             areaA = areaA * math.abs(getTickCount() % 1000 - 500) / 500;
  323.                         end
  324.                        
  325.                         local mapRatio = Minimap.BiggerTargetSize / (mapRadius * 2);
  326.                         local areaMapX, areaMapY, areaMapWidth, areaMapHeight = (areaMapX - (playerMapX - mapRadius)) * mapRatio, (areaMapY - (playerMapY - mapRadius)) * mapRatio, areaMapWidth * mapRatio, areaMapHeight * mapRatio;
  327.                        
  328.                         dxSetBlendMode('modulate_add');
  329.                         dxDrawRectangle(areaMapX, areaMapY, areaMapWidth, areaMapHeight, tocolor(areaR, areaG, areaB, areaA), false);
  330.                         dxSetBlendMode('blend');
  331.                     end
  332.                 end
  333.                
  334.                 --> Draw blip
  335.                 dxSetRenderTarget(Minimap.RenderTarget, true);
  336.                 dxDrawImage(Minimap.NormalTargetSize / 2, Minimap.NormalTargetSize / 2, Minimap.BiggerTargetSize, Minimap.BiggerTargetSize, Minimap.MapTarget, math.deg(-pRotation), 0, 0, tocolor(255, 255, 255, 255), false);
  337.                
  338.                 local serverBlips = getElementsByType('blip');
  339.                
  340.                 table.sort(serverBlips,
  341.                     function(b1, b2)
  342.                         return getBlipOrdering(b1) < getBlipOrdering(b2);
  343.                     end
  344.                 );
  345.                
  346.                 for _, blip in ipairs(serverBlips) do
  347.                     local blipX, blipY, blipZ = getElementPosition(blip);
  348.                    
  349.                     if (localPlayer ~= getElementAttachedTo(blip) and getElementInterior(localPlayer) == getElementInterior(blip) and getElementDimension(localPlayer) == getElementDimension(blip)) then
  350.                         local blipDistance = getDistanceBetweenPoints2D(blipX, blipY, playerX, playerY);
  351.                         local blipRotation = math.deg(-getVectorRotation(playerX, playerY, blipX, blipY) - (-pRotation)) - 180;
  352.                         local blipRadius = math.min((blipDistance / (streamDistance * Minimap.CurrentZoom)) * Minimap.NormalTargetSize, Minimap.NormalTargetSize);
  353.                         local distanceX, distanceY = getPointFromDistanceRotation(0, 0, blipRadius, blipRotation);
  354.                        
  355.                         local blipSettings = {
  356.                             ['color'] = {255, 255, 255, 255},
  357.                             ['size'] = getElementData(blip, 'blipSize') or 20,
  358.                             ['exclusive'] = getElementData(blip, 'exclusiveBlip') or false,
  359.                             ['icon'] = getElementData(blip, 'blipIcon') or 'target'
  360.                         };
  361.                        
  362.                         local blipX, blipY = Minimap.NormalTargetSize * 1.5 + (distanceX - (blipSettings['size'] / 2)), Minimap.NormalTargetSize * 1.5 + (distanceY - (blipSettings['size'] / 2));
  363.                         local calculatedX, calculatedY = ((Minimap.PosX + (Minimap.Width / 2)) - (blipSettings['size'] / 2)) + (blipX - (Minimap.NormalTargetSize * 1.5) + (blipSettings['size'] / 2)), (((Minimap.PosY + (Minimap.Height / 2)) - (blipSettings['size'] / 2)) + (blipY - (Minimap.NormalTargetSize * 1.5) + (blipSettings['size'] / 2)));
  364.                        
  365.                         if (blipSettings['icon'] == 'target' or blipSettings['icon'] == 'waypoint') then
  366.                             blipSettings['color'] = {getBlipColor(blip)};
  367.                         end
  368.                        
  369.                         if (blipSettings['exclusive'] == true) then
  370.                             blipX = math.max(blipX + (Minimap.PosX - calculatedX), math.min(blipX + (Minimap.PosX + Minimap.Width - blipSettings['size'] - calculatedX), blipX));
  371.                             blipY = math.max(blipY + (Minimap.PosY - calculatedY), math.min(blipY + (Minimap.PosY + Minimap.Height - blipSettings['size'] - 25 - calculatedY), blipY));
  372.                         end
  373.                        
  374.                         dxSetBlendMode('modulate_add');
  375.                         dxDrawImage(blipX, blipY, blipSettings['size'], blipSettings['size'], 'files/images/blips/' .. blipSettings['icon'] .. '.png', 0, 0, 0, tocolor(blipSettings['color'][1], blipSettings['color'][2], blipSettings['color'][3], blipSettings['color'][4]), false);
  376.                         dxSetBlendMode('blend');
  377.                     end
  378.                 end
  379.                
  380.                 for _, player in ipairs(getElementsByType('player')) do
  381.                     local otherPlayerX, otherPlayerY, otherPlayerZ = getElementPosition(player);
  382.                    
  383.                     if (localPlayer ~= player and streamDistance * Minimap.CurrentZoom) then
  384.                         local playerDistance = getDistanceBetweenPoints2D(otherPlayerX, otherPlayerY, playerX, playerY);
  385.                         local playerRotation = math.deg(-getVectorRotation(playerX, playerY, otherPlayerX, otherPlayerY) - (-pRotation)) - 180;
  386.                         local playerRadius = math.min((playerDistance / (streamDistance * Minimap.CurrentZoom)) * Minimap.NormalTargetSize, Minimap.NormalTargetSize);
  387.                         local distanceX, distanceY = getPointFromDistanceRotation(0, 0, playerRadius, playerRotation);
  388.                        
  389.                         local otherPlayerX, otherPlayerY = Minimap.NormalTargetSize * 1.5 + (distanceX - 10), Minimap.NormalTargetSize * 1.5 + (distanceY - 10);
  390.                         local calculatedX, calculatedY = ((Minimap.PosX + (Minimap.Width / 2)) - 10) + (otherPlayerX - (Minimap.NormalTargetSize * 1.5) + 10), (((Minimap.PosY + (Minimap.Height / 2)) - 10) + (otherPlayerY - (Minimap.NormalTargetSize * 1.5) + 10));
  391.                         local playerR, playerG, playerB = getPlayerNametagColor(player);
  392.                        
  393.                         otherPlayerX = math.max(otherPlayerX + (Minimap.PosX - calculatedX), math.min(otherPlayerX + (Minimap.PosX + Minimap.Width - 20 - calculatedX), otherPlayerX));
  394.                         otherPlayerY = math.max(otherPlayerY + (Minimap.PosY - calculatedY), math.min(otherPlayerY + (Minimap.PosY + Minimap.Height - 20 - calculatedY), otherPlayerY));
  395.                        
  396.                         dxSetBlendMode('modulate_add');
  397.                         dxDrawImage(otherPlayerX, otherPlayerY, 20, 20, 'files/images/blips/player.png', 0, 0, 0, tocolor(playerR, playerG, playerB, 255), false);
  398.                         dxSetBlendMode('blend');
  399.                     end
  400.                 end
  401.                
  402.                 --> Draw fully minimap
  403.                 dxSetRenderTarget();
  404.                 dxDrawImageSection(Minimap.PosX, Minimap.PosY, Minimap.Width, Minimap.Height, Minimap.NormalTargetSize / 2 + (Minimap.BiggerTargetSize / 2) - (Minimap.Width / 2), Minimap.NormalTargetSize / 2 + (Minimap.BiggerTargetSize / 2) - (Minimap.Height / 2), Minimap.Width, Minimap.Height, Minimap.RenderTarget, 0, -90, 0, tocolor(255, 255, 255, 255));
  405.                
  406.                 --> Local player
  407.                 dxDrawImage((Minimap.PosX + (Minimap.Width / 2)) - 10, (Minimap.PosY + (Minimap.Height / 2)) - 10, 20, 20, 'files/images/arrow.png', math.deg(-pRotation) - playerRotation);
  408.            
  409.                 --> GPS
  410.                 dxDrawRectangle(Minimap.PosX, Minimap.PosY + Minimap.Height - 25, Minimap.Width, 25, tocolor(0, 0, 0, 150));
  411.                 dxDrawText(getZoneName(playerX, playerY, playerZ), Minimap.PosX + 5, (Minimap.PosY + Minimap.Height - 25), Minimap.PosX + 5 + Minimap.Width - 10, Minimap.PosY + Minimap.Height, tocolor(255, 255, 255, 255), 0.40, Fonts.Roboto, 'right', 'center', true, false, false, true, true);
  412.                
  413.                 --> Zoom
  414.                 if (getKeyState('num_add') or getKeyState('num_sub')) then
  415.                     Minimap.CurrentZoom = math.max(Minimap.MinimumZoom, math.min(Minimap.MaximumZoom, Minimap.CurrentZoom + ((getKeyState('num_sub') and -1 or 1) * (getTickCount() - (getTickCount() + 50)) / 100)));
  416.                 end
  417.             else
  418.                 dxDrawRectangle(Minimap.PosX, Minimap.PosY, Minimap.Width, Minimap.Height, tocolor(0, 0, 0, 150));
  419.                 dxDrawText('GPS lost connection...', Minimap.PosX, Minimap.PosY + 20, Minimap.PosX + Minimap.Width, Minimap.PosY + 20 + Minimap.Height, tocolor(255, 255, 255, 255 * math.abs(getTickCount() % 2000 - 1000) / 1000), 0.40, Fonts.Roboto, 'center', 'center', false, false, false, true, true);
  420.                 dxDrawText('', Minimap.PosX, Minimap.PosY - 20, Minimap.PosX + Minimap.Width, Minimap.PosY - 20 + Minimap.Height, tocolor(255, 255, 255, 255 * math.abs(getTickCount() % 2000 - 1000) / 1000), 1.00, Fonts.Icons, 'center', 'center', false, false, false, true, true);
  421.                
  422.                 if (Minimap.LostRotation > 360) then
  423.                     Minimap.LostRotation = 0;
  424.                 end
  425.                
  426.                 dxDrawText('', (Minimap.PosX + Minimap.Width - 25), Minimap.PosY, (Minimap.PosX + Minimap.Width - 25) + 25, Minimap.PosY + 25, tocolor(255, 255, 255, 100), 0.50, Fonts.Icons, 'center', 'center', false, false, false, true, true, Minimap.LostRotation);
  427.                 Minimap.LostRotation = Minimap.LostRotation + 1;
  428.             end
  429.            
  430.             --> Stats
  431.             if (radarSettings['showStats']) then
  432.                 if (isElementInWater(localPlayer)) then
  433.                     Stats.Bar.Width = (Minimap.Width / 3);
  434.                 else
  435.                     Stats.Bar.Width = (Minimap.Width / 2);
  436.                 end
  437.                
  438.                 local healthColor;
  439.        
  440.                 if (getElementHealth(localPlayer) <= 20) then
  441.                     local healthPulseTick = getTickCount() % 600;
  442.                     healthColor = {healthPulseTick <= 300 and 255 or 200, healthPulseTick <= 300 and 100 or 100, healthPulseTick <= 300 and 100 or 100};
  443.                 end
  444.                
  445.                 dxDrawBorder(Minimap.PosX, Minimap.PosY + Minimap.Height + 2, Stats.Bar.Width, Stats.Bar.Height, 2, tocolor(0, 0, 0, 200));
  446.                 dxDrawBorder(Minimap.PosX + Stats.Bar.Width + 2, Minimap.PosY + Minimap.Height + 2, Stats.Bar.Width - 2, Stats.Bar.Height, 2, tocolor(0, 0, 0, 200));
  447.                 dxDrawRectangle(Minimap.PosX, Minimap.PosY + Minimap.Height + 2, Stats.Bar.Width, Stats.Bar.Height, tocolor(0, 0, 0, 140));
  448.                 dxDrawRectangle(Minimap.PosX + Stats.Bar.Width + 2, Minimap.PosY + Minimap.Height + 2, Stats.Bar.Width - 2, Stats.Bar.Height, tocolor(0, 0, 0, 140));
  449.            
  450.                 dxDrawRectangle(Minimap.PosX, Minimap.PosY + Minimap.Height + 2, Stats.Bar.Width / 100 * getElementHealth(localPlayer), Stats.Bar.Height, healthColor and tocolor(healthColor[1], healthColor[2], healthColor[3], 200) or tocolor(110, 200, 140, 200));
  451.                 dxDrawRectangle(Minimap.PosX + Stats.Bar.Width + 2, Minimap.PosY + Minimap.Height + 2, (Stats.Bar.Width - 2) / 100 * getPedArmor(localPlayer), Stats.Bar.Height, tocolor(75, 170, 210, 200));
  452.            
  453.                 if (isElementInWater(localPlayer)) then
  454.                     dxDrawBorder(Minimap.PosX + (Stats.Bar.Width * 2) + 2, Minimap.PosY + Minimap.Height + 2, Stats.Bar.Width - 2, Stats.Bar.Height, 2, tocolor(0, 0, 0, 200));
  455.                     dxDrawRectangle(Minimap.PosX + (Stats.Bar.Width * 2) + 2, Minimap.PosY + Minimap.Height + 2, Stats.Bar.Width - 2, Stats.Bar.Height, tocolor(0, 0, 0, 140));
  456.                     dxDrawRectangle(Minimap.PosX + (Stats.Bar.Width * 2) + 2, Minimap.PosY + Minimap.Height + 2, (Stats.Bar.Width - 2) / 1000 * getPedOxygenLevel(localPlayer), Stats.Bar.Height, tocolor(230, 230, 30, 200));
  457.                 end
  458.             end
  459.         end
  460.     end
  461. );
  462.  
  463. function doesCollide(x1, y1, w1, h1, x2, y2, w2, h2)
  464.     local horizontal = (x1 < x2) ~= (x1 + w1 < x2) or (x1 > x2) ~= (x1 > x2 + w2);
  465.     local vertical = (y1 < y2) ~= (y1 + h1 < y2) or (y1 > y2) ~= (y1 > y2 + h2);
  466.    
  467.     return (horizontal and vertical);
  468. end
  469.  
  470. function getRadarRadius()
  471.     if (not Minimap.PlayerInVehicle) then
  472.         return 180;
  473.     else
  474.         local vehicleX, vehicleY, vehicleZ = getElementVelocity(Minimap.PlayerInVehicle);
  475.         local currentSpeed = (1 + (vehicleX ^ 2 + vehicleY ^ 2 + vehicleZ ^ 2) ^ (0.5)) / 2;
  476.    
  477.         if (currentSpeed <= 0.5) then
  478.             return 180;
  479.         elseif (currentSpeed >= 1) then
  480.             return 360;
  481.         end
  482.        
  483.         local distance = currentSpeed - 0.5;
  484.         local ratio = 180 / 0.5;
  485.        
  486.         return math.ceil((distance * ratio) + 180);
  487.     end
  488. end
  489.  
  490. function getPointFromDistanceRotation(x, y, dist, angle)
  491.     local a = math.rad(90 - angle);
  492.     local dx = math.cos(a) * dist;
  493.     local dy = math.sin(a) * dist;
  494.    
  495.     return x + dx, y + dy;
  496. end
  497.  
  498. function getRotation()
  499.     local cameraX, cameraY, _, rotateX, rotateY = getCameraMatrix();
  500.     local camRotation = getVectorRotation(cameraX, cameraY, rotateX, rotateY);
  501.    
  502.     return camRotation;
  503. end
  504.  
  505. function getVectorRotation(X, Y, X2, Y2)
  506.     local rotation = 6.2831853071796 - math.atan2(X2 - X, Y2 - Y) % 6.2831853071796;
  507.    
  508.     return -rotation;
  509. end
  510.  
  511. function dxDrawBorder(x, y, w, h, size, color, postGUI)
  512.     size = size or 2;
  513.    
  514.     dxDrawRectangle(x - size, y, size, h, color or tocolor(0, 0, 0, 180), postGUI);
  515.     dxDrawRectangle(x + w, y, size, h, color or tocolor(0, 0, 0, 180), postGUI);
  516.     dxDrawRectangle(x - size, y - size, w + (size * 2), size, color or tocolor(0, 0, 0, 180), postGUI);
  517.     dxDrawRectangle(x - size, y + h, w + (size * 2), size, color or tocolor(0, 0, 0, 180), postGUI);
  518. end
  519.  
  520. function getMinimapState()
  521.     return Minimap.IsVisible;
  522. end
  523.  
  524. function getBigmapState()
  525.     return Bigmap.IsVisible;
  526. end
  527.  
  528. function getMapFromWorldPosition(worldX, worldY)
  529.     local centerX, centerY = (Bigmap.PosX + (Bigmap.Width / 2)), (Bigmap.PosY + (Bigmap.Height / 2));
  530.     local mapLeftFrame = centerX - ((playerX - worldX) / Bigmap.CurrentZoom * Minimap.MapUnit);
  531.     local mapRightFrame = centerX + ((worldX - playerX) / Bigmap.CurrentZoom * Minimap.MapUnit);
  532.     local mapTopFrame = centerY - ((worldY - playerY) / Bigmap.CurrentZoom * Minimap.MapUnit);
  533.     local mapBottomFrame = centerY + ((playerY - worldY) / Bigmap.CurrentZoom * Minimap.MapUnit);
  534.    
  535.     centerX = math.max(mapLeftFrame, math.min(mapRightFrame, centerX));
  536.     centerY = math.max(mapTopFrame, math.min(mapBottomFrame, centerY));
  537.    
  538.     return centerX, centerY;
  539. end
  540.  
  541. function getMapFromWorldPosition(worldX, worldY)
  542.     local mapX = (Bigmap.PosX + Bigmap.Width / 2) + ((worldX - playerX) * Bigmap.CurrentZoom) * Minimap.MapUnit;
  543.     local mapY = (Bigmap.PosY + Bigmap.Height / 2) - ((worldY - playerY) * Bigmap.CurrentZoom) * Minimap.MapUnit;
  544.    
  545.     return mapX, mapY;
  546. end
  547.  
  548. function getWorldFromMapPosition(mapX, mapY)
  549.     local worldX = playerX + ((mapX - (Bigmap.PosX + Bigmap.Width / 2)) / Bigmap.CurrentZoom) / Minimap.MapUnit;
  550.     local worldY = playerY - ((mapY - (Bigmap.PosY + Bigmap.Height / 2)) / Bigmap.CurrentZoom) / Minimap.MapUnit;
  551.    
  552.     return worldX, worldY;
  553. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement