Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --Creating a table for fully object orientedness :D
- test = {};
- test.hud = {};
- tCol = {};
- --Defining variables at the top, putting all of them inside the test.hud table
- --To keep it self containing
- test.hud.xPos = 150;
- test.hud.yPos = ScrH() - 150;
- --The test.hud:TeamColor() puts the function TeamColor() in the test.hud table
- --Refer to it by calling test.hud:TeamColor()
- function test.hud:teamColor()
- --Returning is better than constantly defining global variables
- return team.GetColor(LocalPlayer():Team());
- end;
- function test.hud:drawCircleFill( x, y, radius, col )
- local circle = {};
- local s, c;
- local quality = 10 + radius / 2;
- for i=1, quality do
- s = math.sin( math.rad( i * 360 ) / quality );
- c = math.cos( math.rad( i * 360 ) / quality );
- circle[i] = {
- x = x + c * radius,
- y = y + s * radius,
- u = 1,
- v = 1
- };
- end;
- surface.SetDrawColor( col );
- surface.DrawPoly( circle );
- end;
- function test.hud:DrawHealth()
- local health = math.Clamp( LocalPlayer():Health(), 0, 9999 );
- local circleAmount = math.floor( health / 100 * 10 );
- tCol = test.hud:teamColor()
- local r = math.Clamp(tCol.r, 50, 150 ) - 20
- local g = math.Clamp(tCol.g, 50, 150 ) - 20
- local b = math.Clamp(tCol.b, 50, 150 ) - 20
- local a = math.Clamp( (tCol.a/100)*health, 50, 255)
- --Doing this so we can get the size of the text to position it properly
- --You have to set the font to the proper font before
- --Calling surface.GetTextSize
- --Here's an example of calling a function in the test.hud table
- test.hud:drawCircleFill( test.hud.xPos, test.hud.yPos, 60, Color( r, g, b, 100));
- test.hud:drawCircleFill( test.hud.xPos, test.hud.yPos, 50, Color( 120, 120, 120, 200));
- for i=1, circleAmount do
- local xCircleDrawPos = test.hud.xPos + math.cos( ( CurTime() * 5.5 ) + math.rad( i * 360 ) / circleAmount ) * 100;
- local yCircleDrawPos = test.hud.yPos + math.sin( ( CurTime() * 4 ) + math.rad( i * 360 ) / circleAmount ) * 80;
- test.hud:drawCircleFill( xCircleDrawPos, yCircleDrawPos, 10,test.hud:teamColor());
- end;
- end;
- hook.Add( "HUDPaint", "test.hud:DrawHealth", test.hud.DrawHealth );
- --hook.Remove( "HUDPaint", "test.hud:DrawHealth");
- function test.hud:DrawSpeed()
- local speed = math.Round( LocalPlayer():GetVelocity():Length() / 10 );
- local circleAmount = math.floor( speed / 200 * 20 );
- local r = math.Clamp(tCol.r, 50, 150 ) - 20
- local g = math.Clamp(tCol.g, 50, 150 ) - 20
- local b = math.Clamp(tCol.b, 50, 150 ) - 20
- --Doing this so we can get the size of the text to position it properly
- --You have to set the font to the proper font before
- --Calling surface.GetTextSize
- --Here's an example of calling a function in the test.hud table
- test.hud:drawCircleFill( ScrW() - 150, test.hud.yPos, 60,Color( r, g, b, 100) );
- test.hud:drawCircleFill( ScrW() - 150, test.hud.yPos, 50, Color( 120, 120, 120, 200) );
- for i=1, circleAmount do
- local xCircleDrawPos = ScrW() - 150 + math.cos( ( CurTime() * -5.5 ) + math.rad( i * 360 ) / circleAmount ) * 100;
- local yCircleDrawPos = test.hud.yPos + math.sin( ( CurTime() * -4 ) + math.rad( i * 360 ) / circleAmount ) * 80;
- test.hud:drawCircleFill( xCircleDrawPos, yCircleDrawPos, 10, test.hud:teamColor() );
- end;
- end;
- hook.Add( "HUDPaint", "test.hud:DrawSpeed", test.hud.DrawSpeed );
- --hook.Remove( "HUDPaint", "test.hud:DrawSpeed");
Add Comment
Please, Sign In to add comment