Skip to content

Instantly share code, notes, and snippets.

@feliksz
Last active August 30, 2022 21:15
#include "../../util/input.hpp"
#include "../../util/math.hpp"
#include "../../util/render.hpp"
#include "walkbot.hpp"
void c_walkbot::paint( )
{
const auto local_player = g_interfaces.entity_list->get_client_entity( g_interfaces.engine->get_local_player( ) );
if ( !local_player )
return;
if ( g_input.is_key_pressed( VK_UP ) )
m_points.push_back( local_player->m_origin( ) );
if ( g_input.is_key_down( VK_RIGHT ) )
m_points.clear( );
if ( m_points.empty( ) )
return;
for ( size_t i = 0; i < m_points.size(); i++ )
{
const auto screen_position = g_math.world_to_screen( m_points.at(i) );
g_render.string( screen_position, fonts::general, std::to_string(i), color_t( 255, 0, 0, 255 ), true );
}
}
void c_walkbot::move( usercmd_t* cmd )
{
const auto local_player = reinterpret_cast<c_base_player*>( g_interfaces.entity_list->get_client_entity( g_interfaces.engine->get_local_player( ) ) );
if ( g_input.is_key_down( VK_LEFT ) )
{
if ( m_current_point == -1 )
m_current_point = find_nearest_point( local_player );
if ( m_current_point == m_points.size( ) )
{
m_current_point = 0;
std::reverse( m_points.begin( ), m_points.end( ) );
}
go_to( cmd, m_points.at( m_current_point ) );
}
}
int c_walkbot::find_nearest_point( c_base_player* local_player )
{
auto nearest_point = -1;
auto best_distance = 100000.f;
for ( size_t i = 0; i < m_points.size( ); i++ )
{
const auto distance = local_player->m_origin( ).dist_to( m_points.at( i ) );
if ( distance < best_distance )
{
best_distance = distance;
nearest_point = i;
}
}
return nearest_point;
}
void c_walkbot::go_to( usercmd_t* cmd, vec3_t point )
{
const auto local_player = g_interfaces.entity_list->get_client_entity( g_interfaces.engine->get_local_player( ) );
if ( !local_player )
return;
if ( local_player->m_origin( ).dist_to( point ) < 10)
m_current_point++;
vec3_t final_view_angle;
g_math.vector_angles( point - local_player->m_origin( ), final_view_angle );
g_math.normalize_angles( final_view_angle );
g_math.clamp_angles( final_view_angle );
g_interfaces.engine->set_view_angles( final_view_angle );
cmd->forwardmove = 450.f;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment