Advertisement
Guest User

Untitled

a guest
Jun 27th, 2017
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.63 KB | None | 0 0
  1. --[[
  2.     This is just a script somebody requested.
  3.     Credit goes to kurozael, aka Conna Wiles
  4.     you can reach me at kurozael@gmail.com.
  5. --]]
  6.  
  7. cooldown = {};
  8. cooldown.sizes = {};
  9.  
  10. -- A function to get a cooldown table.
  11. function cooldown:GetTable(width, height, bAdd)
  12.     local cooldownTable = self.sizes[width.." "..height];
  13.    
  14.     if (cooldownTable) then
  15.         return cooldownTable;
  16.     elseif (bAdd) then
  17.         return self:AddSize(width, height);
  18.     end;
  19. end;
  20.  
  21. -- A function to add a cooldown size.
  22. function cooldown:AddSize(width, height)
  23.     local verticies = {
  24.         {
  25.             {x = 0, y = -(height / 2), u = 0.5, v = 0},
  26.             {x = width / 2, y = -(height / 2), u = 1, v = 0, c = function()
  27.                 return -(width / 2), 0;
  28.             end},
  29.         },
  30.         {
  31.             {x = width / 2, y = -(height / 2), u = 1, v = 0},
  32.             {x = width / 2, y = 0, u = 1, v = 0.5, c = function()
  33.                 return 0, -(height / 2);
  34.             end},
  35.         },
  36.         {
  37.             {x = width / 2, y = 0, u = 1, v = 0.5},
  38.             {x = width / 2, y = height / 2, u = 1, v = 1, c = function()
  39.                 return 0, -(height / 2);
  40.             end},
  41.         },
  42.         {
  43.             {x = width / 2, y = height / 2, u = 1, v = 1},
  44.             {x = 0, y = height / 2, u = 0.5, v = 1, c = function()
  45.                 return width / 2, 0;
  46.             end},
  47.         },
  48.         {
  49.             {x = 0, y = height / 2, u = 0.5, v = 1},
  50.             {x = -(width / 2), y = height / 2, u = 0, v = 1, c = function()
  51.                 return width / 2, 0;
  52.             end},
  53.         },
  54.         {
  55.             {x = -(width / 2), y = height / 2, u = 0, v = 1},
  56.             {x = -(width / 2), y = 0, u = 0, v = 0.5, c = function()
  57.                 return 0, height / 2;
  58.             end},
  59.         },
  60.         {
  61.             {x = -(width / 2), y = 0, u = 0, v = 0.5},
  62.             {x = -(width / 2), y = -(height / 2), u = 0, v = 0, c = function()
  63.                 return 0, height / 2;
  64.             end},
  65.         },
  66.         {
  67.             {x = -(width / 2), y = -(height / 2), u = 0, v = 0},
  68.             {x = 0, y = -(height / 2), u = 0.5, v = 0, c = function()
  69.                 return -(width / 2), 0;
  70.             end},
  71.         },
  72.     };
  73.  
  74.     local editTable = table.Copy(verticies);
  75.    
  76.     self.sizes[width.." "..height] = {
  77.         verticies = verticies,
  78.         editTable = editTable
  79.     };
  80.    
  81.     return self.sizes[width.." "..height];
  82. end;
  83.  
  84. -- A function to draw a cooldown box.
  85. function cooldown:DrawBox(x, y, width, height, progress, color, bCenter, bReverse, endtime)
  86.     if (bReverse) then progress = 100 - progress; end;
  87.     if (!bReverse and (progress >= 100)) then return end
  88.     if (bReverse and (progress <= 0)) then return end
  89.     local cooldownTable = self:GetTable(width, height, true);
  90.     local octant = math.Clamp( (8 / 100) * progress, 0, 8 );
  91.    
  92.     if (!bCenter) then
  93.         x = x + (width / 2);
  94.         y = y + (height / 2);
  95.     end;
  96.    
  97.     surface.SetDrawColor(color.r, color.g, color.b, color.a);
  98.    
  99.     local polygons = { {x = x, y = y, u = 0.5, v = 0.5} };
  100.    
  101.     for i = 1, 8 do
  102.         if (math.ceil(octant) == i) then
  103.             local fraction = 1 - (i - octant);
  104.             local nx, ny = cooldownTable.editTable[i][2].c();
  105.            
  106.             cooldownTable.editTable[i][2].x = x + cooldownTable.verticies[i][2].x + nx + (-nx * fraction);
  107.             cooldownTable.editTable[i][2].y = y + cooldownTable.verticies[i][2].y + ny + (-ny * fraction);
  108.             cooldownTable.editTable[i][1].x = x + cooldownTable.verticies[i][1].x;
  109.             cooldownTable.editTable[i][1].y = y + cooldownTable.verticies[i][1].y;
  110.            
  111.             table.Add( polygons, cooldownTable.editTable[i] );
  112.         elseif (octant > i) then
  113.             for j = 1, 2 do
  114.                 cooldownTable.editTable[i][j].x = x + cooldownTable.verticies[i][j].x;
  115.                 cooldownTable.editTable[i][j].y = y + cooldownTable.verticies[i][j].y;
  116.             end;
  117.            
  118.             table.Add( polygons, cooldownTable.editTable[i] );
  119.         end;
  120.     end;
  121.    
  122.     surface.DrawPoly(polygons);
  123.    
  124.     local perc = math.ceil(endtime - CurTime())
  125.     draw.DrawText(tostring(perc), "HUDNumber3", x, y - height / 2, Color(100,100,100,255), TEXT_ALIGN_CENTER)
  126. end;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement