Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- float best_head_yaw( void )
- {
- // get a ptr to our local player
- entity_t* local = entity_t::get_local( );
- // lambda function that gets the closest target by fov
- auto get_target_entity = [ & ] ( void )
- {
- // values that we use to compare the entities
- float best_fov = 360.0f;
- int best_target = -1;
- // iterate through the entity_list
- for( int i = 0; i < 64; ++i )
- {
- // find entity
- entity_t* entity = entity_t::get_entity( i );
- // entity is not nullptr, not a team mate, not dormant and is alive
- if( !entity || !entity->passes_sanity_checks( ) )
- continue;
- // get that fov
- float fov_to_entity = csgo.m_math->get_fov( local, entity );
- // some comparisons
- if( fov_to_entity < best_fov )
- {
- best_fov = fov_to_entity;
- best_target = i;
- }
- }
- // ok now we have our entity
- return entity_t::get_entity( best_target );
- };
- // we will require these eye positions
- vec3_t eye_position = local->get_eye_position( );
- vec3_t target_eye_position = get_target_entity( )->get_eye_position( );
- // lets set up some basic values we need
- float best_damage = 100.0f;
- // atan 1 * 4 = 3.1415...rad
- constexpr float calculated_pi = std::atan( 1.0f ) * 4.0f;
- // this will result in a 45.0f deg step, modify if you want it to be more 'precise'
- constexpr float angle_step = ( calculated_pi * 2.0f ) / 8.0f;
- // our result
- float yaw = 0.0f;
- // iterate through 45.0f deg angles
- for( float n = 0.0f; n < ( calculated_pi * 2.0f ); n += angle_step )
- {
- // shoutout to aimtux for headpos calc
- vec3_t head_position( cos( n ) + eye_position.x,
- sin( n ) + eye_position.y,
- eye_position.z);
- // init our firebullet_t struct to pass to the autowall
- firebullet_t data;
- data.in = target_eye_position;
- data.filter.skip.push_back( get_target_entity( ) );
- // figure out this by yourself :^)
- // hint: float autowall::trace( firebullet_t& data, vec3_t& pos );
- float damage = csgo.m_autowall->trace( data, head_position );
- if( damage < best_damage )
- {
- best_damage = damage;
- yaw = n;
- }
- }
- // return the best yaw angle
- return yaw;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement