Advertisement
Guest User

Untitled

a guest
Feb 11th, 2018
240
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.64 KB | None | 0 0
  1. #include <sourcemod>
  2. #include <sdktools>
  3.  
  4. int g_HaloSprite;
  5. int g_LaserBeam;
  6.  
  7. public void OnPluginStart()
  8. {
  9.     RegConsoleCmd( "sm_hitboxtest", Command_HitboxTest );
  10.     RegConsoleCmd( "sm_bboxtest", Command_BBoxTest );
  11.     RegConsoleCmd( "sm_clipraytest", Command_ClipRayTest );
  12. }
  13.  
  14. public void OnMapStart()
  15. {
  16.     g_HaloSprite = PrecacheModel( "materials/sprites/glow01.vmt" );
  17.     g_LaserBeam = PrecacheModel( "materials/sprites/laserbeam.vmt" );
  18. }
  19.  
  20. public Action Command_HitboxTest( int client, int args )
  21. {
  22.     float startpos[3];
  23.     GetClientEyePosition( client, startpos );
  24.     float angles[3];
  25.     GetClientEyeAngles( client, angles );
  26.    
  27.     TR_EnumerateEntities( startpos, angles, false, RayType_Infinite, HitPlayerHBox, client );
  28. }
  29.  
  30. public Action Command_BBoxTest( int client, int args )
  31. {
  32.     float startpos[3];
  33.     GetClientEyePosition( client, startpos );
  34.     float angles[3];
  35.     GetClientEyeAngles( client, angles );
  36.    
  37.     TR_EnumerateEntities( startpos, angles, false, RayType_Infinite, HitPlayerBBox, client );
  38. }
  39.  
  40. public Action Command_ClipRayTest( int client, int args )
  41. {
  42.     float start[3];
  43.     GetClientAbsOrigin( client, start );
  44.     float end[3];
  45.     GetClientEyePosition( client, end );
  46.    
  47.     TR_ClipRayToEntity( start, end, MASK_ALL, RayType_EndPoint, client );
  48.     TR_GetEndPosition( end );
  49.    
  50.     PrintToChatAll( "Hit myself at (%.2f, %.2f, %.2f)", end[0], end[1], end[2] );
  51.    
  52.     return Plugin_Handled;
  53. }
  54.  
  55. public bool HitPlayerBBox( int entity, int client )
  56. {
  57.     if( 0 < entity <= MaxClients && entity != client )
  58.     {
  59.         TR_ClipCurrRayToEntity( MASK_PLAYERSOLID, entity );
  60.        
  61.         float pos[3];
  62.         TR_GetEndPosition( pos );
  63.        
  64.         PrintToChatAll( "Hit %N (%i)! Collided at (%.2f, %.2f, %.2f) | Fraction: %.2f", entity, entity, pos[0], pos[1], pos[2], TR_GetFraction() );
  65.        
  66.         float startpos[3];
  67.         GetClientEyePosition( client, startpos );
  68.        
  69.         TE_SetupBeamPoints( startpos, pos, g_LaserBeam, g_HaloSprite, 0, 0, 20.0, 1.0, 1.0, 0, 0.0, { 0, 255, 0, 255 }, 0 );
  70.         TE_SendToAll( 0.0 );
  71.        
  72.         return false;
  73.     }
  74.    
  75.     return true;
  76. }
  77.  
  78. public bool HitPlayerHBox( int entity, int client )
  79. {
  80.     if( 0 < entity <= MaxClients && entity != client )
  81.     {
  82.         Handle tr = TR_ClipCurrRayToEntityEx( MASK_ALL, entity );
  83.        
  84.         float pos[3];
  85.         TR_GetEndPosition( pos, tr );
  86.        
  87.         PrintToChatAll( "Hit %N (%i)! Collided at (%.2f, %.2f, %.2f) | Fraction: %.2f", entity, entity, pos[0], pos[1], pos[2], TR_GetFraction( tr ) );
  88.        
  89.         delete tr;
  90.        
  91.         float startpos[3];
  92.         GetClientEyePosition( client, startpos );
  93.        
  94.         TE_SetupBeamPoints( startpos, pos, g_LaserBeam, g_HaloSprite, 0, 0, 20.0, 1.0, 1.0, 0, 0.0, { 255, 0, 0, 255 }, 0 );
  95.         TE_SendToAll( 0.0 );
  96.        
  97.         return false;
  98.     }
  99.    
  100.     return true;
  101. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement