Guest User

Untitled

a guest
Jan 20th, 2019
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.12 KB | None | 0 0
  1.     --Creating a table for fully object orientedness :D
  2.     test = {};
  3.     test.hud = {};
  4.     tCol = {};
  5.      
  6.     --Defining variables at the top, putting all of them inside the test.hud table
  7.     --To keep it self containing
  8.     test.hud.xPos = 150;
  9.     test.hud.yPos = ScrH() - 150;
  10.      
  11.     --The test.hud:TeamColor() puts the function TeamColor() in the test.hud table
  12.     --Refer to it by calling test.hud:TeamColor()
  13.     function test.hud:teamColor()
  14.             --Returning is better than constantly defining global variables
  15.             return team.GetColor(LocalPlayer():Team());
  16.     end;
  17.    
  18.    
  19.     function test.hud:drawCircleFill( x, y, radius, col )
  20.             local circle = {};
  21.             local s, c;
  22.             local quality = 10 + radius / 2;
  23.             for i=1, quality do
  24.                     s = math.sin( math.rad( i * 360 ) / quality );
  25.                     c = math.cos( math.rad( i * 360 ) / quality );
  26.                     circle[i] = {
  27.                             x = x + c * radius,
  28.                             y = y + s * radius,
  29.                             u = 1,
  30.                             v = 1
  31.                     };
  32.             end;
  33.             surface.SetDrawColor( col );
  34.             surface.DrawPoly( circle );
  35.     end;
  36.      
  37.     function test.hud:DrawHealth()
  38.             local health = math.Clamp( LocalPlayer():Health(), 0, 9999 );
  39.             local circleAmount = math.floor( health / 100 * 10 );
  40.             tCol = test.hud:teamColor()
  41.             local r = math.Clamp(tCol.r, 50, 150 ) - 20
  42.             local g = math.Clamp(tCol.g, 50, 150 ) - 20
  43.             local b = math.Clamp(tCol.b, 50, 150 ) - 20
  44.             local a = math.Clamp( (tCol.a/100)*health, 50, 255)
  45.  
  46.             --Doing this so we can get the size of the text to position it properly
  47.             --You have to set the font to the proper font before
  48.             --Calling surface.GetTextSize
  49.             --Here's an example of calling a function in the test.hud table
  50.  
  51.             test.hud:drawCircleFill( test.hud.xPos, test.hud.yPos, 60, Color( r, g, b, 100));
  52.             test.hud:drawCircleFill( test.hud.xPos, test.hud.yPos, 50, Color( 120, 120, 120, 200));
  53.      
  54.             for i=1, circleAmount do
  55.                     local xCircleDrawPos = test.hud.xPos + math.cos( ( CurTime() * 5.5 ) + math.rad( i * 360 ) / circleAmount ) * 100;
  56.                     local yCircleDrawPos = test.hud.yPos + math.sin( ( CurTime() * 4 ) + math.rad( i * 360 ) / circleAmount ) * 80;
  57.                     test.hud:drawCircleFill( xCircleDrawPos, yCircleDrawPos, 10,test.hud:teamColor());
  58.             end;
  59.     end;
  60.     hook.Add( "HUDPaint", "test.hud:DrawHealth", test.hud.DrawHealth );
  61.     --hook.Remove( "HUDPaint", "test.hud:DrawHealth");
  62.      
  63.     function test.hud:DrawSpeed()
  64.             local speed = math.Round( LocalPlayer():GetVelocity():Length() / 10 );
  65.             local circleAmount = math.floor( speed / 200 * 20 );
  66.             local r = math.Clamp(tCol.r, 50, 150 ) - 20
  67.             local g = math.Clamp(tCol.g, 50, 150 ) - 20
  68.             local b = math.Clamp(tCol.b, 50, 150 ) - 20
  69.            
  70.             --Doing this so we can get the size of the text to position it properly
  71.             --You have to set the font to the proper font before
  72.             --Calling surface.GetTextSize
  73.             --Here's an example of calling a function in the test.hud table
  74.             test.hud:drawCircleFill( ScrW() - 150, test.hud.yPos, 60,Color( r, g, b, 100) );
  75.             test.hud:drawCircleFill( ScrW() - 150, test.hud.yPos, 50, Color( 120, 120, 120, 200) );    
  76.             for i=1, circleAmount do
  77.                     local xCircleDrawPos = ScrW() - 150 + math.cos( ( CurTime() * -5.5 ) + math.rad( i * 360 ) / circleAmount ) * 100;
  78.                     local yCircleDrawPos = test.hud.yPos + math.sin( ( CurTime() * -4 ) + math.rad( i * 360 ) / circleAmount ) * 80;
  79.                     test.hud:drawCircleFill( xCircleDrawPos, yCircleDrawPos, 10, test.hud:teamColor() );
  80.             end;
  81.     end;
  82.     hook.Add( "HUDPaint", "test.hud:DrawSpeed", test.hud.DrawSpeed );
  83.     --hook.Remove( "HUDPaint", "test.hud:DrawSpeed");
Add Comment
Please, Sign In to add comment