Advertisement
Guest User

Untitled

a guest
Nov 22nd, 2017
153
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.19 KB | None | 0 0
  1. float best_head_yaw( void )
  2. {
  3. // get a ptr to our local player
  4. entity_t* local = entity_t::get_local( );
  5.  
  6. // lambda function that gets the closest target by fov
  7. auto get_target_entity = [ & ] ( void )
  8. {
  9. // values that we use to compare the entities
  10. float best_fov = 360.0f;
  11. int best_target = -1;
  12.  
  13. // iterate through the entity_list
  14. for( int i = 0; i < 64; ++i )
  15. {
  16. // find entity
  17. entity_t* entity = entity_t::get_entity( i );
  18.  
  19. // entity is not nullptr, not a team mate, not dormant and is alive
  20. if( !entity || !entity->passes_sanity_checks( ) )
  21. continue;
  22.  
  23. // get that fov
  24. float fov_to_entity = csgo.m_math->get_fov( local, entity );
  25.  
  26. // some comparisons
  27. if( fov_to_entity < best_fov )
  28. {
  29. best_fov = fov_to_entity;
  30. best_target = i;
  31. }
  32. }
  33.  
  34. // ok now we have our entity
  35. return entity_t::get_entity( best_target );
  36. };
  37.  
  38. // we will require these eye positions
  39. vec3_t eye_position = local->get_eye_position( );
  40. vec3_t target_eye_position = get_target_entity( )->get_eye_position( );
  41.  
  42. // lets set up some basic values we need
  43. float best_damage = 100.0f;
  44.  
  45. // atan 1 * 4 = 3.1415...rad
  46. constexpr float calculated_pi = std::atan( 1.0f ) * 4.0f;
  47.  
  48. // this will result in a 45.0f deg step, modify if you want it to be more 'precise'
  49. constexpr float angle_step = ( calculated_pi * 2.0f ) / 8.0f;
  50.  
  51. // our result
  52. float yaw = 0.0f;
  53.  
  54. // iterate through 45.0f deg angles
  55. for( float n = 0.0f; n < ( calculated_pi * 2.0f ); n += angle_step )
  56. {
  57. // shoutout to aimtux for headpos calc
  58. vec3_t head_position( cos( n ) + eye_position.x,
  59. sin( n ) + eye_position.y,
  60. eye_position.z);
  61.  
  62.  
  63. // init our firebullet_t struct to pass to the autowall
  64. firebullet_t data;
  65. data.in = target_eye_position;
  66. data.filter.skip.push_back( get_target_entity( ) );
  67.  
  68. // figure out this by yourself :^)
  69. // hint: float autowall::trace( firebullet_t& data, vec3_t& pos );
  70. float damage = csgo.m_autowall->trace( data, head_position );
  71.  
  72. if( damage < best_damage )
  73. {
  74. best_damage = damage;
  75. yaw = n;
  76. }
  77. }
  78.  
  79. // return the best yaw angle
  80. return yaw;
  81. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement