animeisgay

lmaobox hitmarker lua

Mar 11th, 2022
904
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.67 KB | None | 0 0
  1. local hit = false;
  2. local time = 0;
  3. local alpha = 0;
  4.  
  5. local function FireGameEvent( event )
  6.     if( event:GetName( ) == "player_hurt" ) then
  7.         local victim = entities.GetByUserID( event:GetInt( "userid" ) );
  8.         local attacker = entities.GetByUserID( event:GetInt( "attacker" ) );
  9.         local me = entities.GetLocalPlayer( );
  10.  
  11.         if( victim ~= nil and attacker ~= nil ) then
  12.             if( victim ~= me and attacker == me ) then
  13.                 hit = true;
  14.                 time = os.clock( );
  15.                 alpha = 255;
  16.             end
  17.         end
  18.     end
  19. end
  20.  
  21. local function Draw( )
  22.     if( hit ) then
  23.         local diff = os.clock( ) - time;
  24.         if( diff > 0.5 ) then
  25.             alpha = alpha - ( 255 / 0.5 * globals.FrameTime( ) );
  26.         end
  27.  
  28.         if( alpha <= 0 ) then
  29.             hit = false;
  30.             time = 0;
  31.             alpha = 0;
  32.             return;
  33.         end
  34.  
  35.         local width, height = draw.GetScreenSize( );
  36.  
  37.         local x = width / 2;
  38.         local y = height / 2;
  39.         local linesize = 10;
  40.  
  41.         draw.Color( 200, 200, 200, math.floor( alpha ) );
  42.  
  43.         draw.Line( x - linesize, y - linesize, x - 4, y - 4 );
  44.         draw.Line( x + linesize, y - linesize, x + 4, y - 4 );
  45.         draw.Line( x - linesize, y + linesize, x - 4, y + 4 );
  46.         draw.Line( x + linesize, y + linesize, x + 4, y + 4 );
  47.     end
  48. end
  49.  
  50. client.AllowListener( "player_hurt" );
  51.  
  52. callbacks.Unregister( "FireGameEvent", "hitmarkereventcb" );
  53. callbacks.Register( "FireGameEvent", "hitmarkereventcb", FireGameEvent );
  54. callbacks.Unregister( "Draw", "hitmarkereventdraw" );
  55. callbacks.Register( "Draw", "hitmarkereventdraw", Draw );
Advertisement
Add Comment
Please, Sign In to add comment