Fix aimbot
cv_aimbot now indicates the aimbot fov
This commit is contained in:
parent
772f4a1d7a
commit
77e8b04214
@ -6,11 +6,8 @@
|
|||||||
#include "../include/cvars.h"
|
#include "../include/cvars.h"
|
||||||
#include "../include/util.h"
|
#include "../include/util.h"
|
||||||
|
|
||||||
enum aimbot_settings {
|
/* Game units to add to the entity origin to get the head */
|
||||||
OFF = 0,
|
#define HEAD_OFFSET 0.8f
|
||||||
CLOSEST = 1,
|
|
||||||
LOWEST_HEALTH = 2, /* TODO */
|
|
||||||
};
|
|
||||||
|
|
||||||
static vec3_t get_closest_delta(vec3_t viewangles) {
|
static vec3_t get_closest_delta(vec3_t viewangles) {
|
||||||
vec3_t view_height;
|
vec3_t view_height;
|
||||||
@ -19,8 +16,8 @@ static vec3_t get_closest_delta(vec3_t viewangles) {
|
|||||||
/* TODO: Compensate aim punch */
|
/* TODO: Compensate aim punch */
|
||||||
|
|
||||||
/* These 2 vars are used to store the best target across iterations.
|
/* These 2 vars are used to store the best target across iterations.
|
||||||
* NOTE: The default value of best_fov is the aimbot fov */
|
* NOTE: The default value of best_fov will be the aimbot fov */
|
||||||
float best_fov = 5.0f;
|
float best_fov = cv_aimbot->value;
|
||||||
vec3_t best_delta = { 0, 0, 0 };
|
vec3_t best_delta = { 0, 0, 0 };
|
||||||
|
|
||||||
for (int i = 1; i <= i_engine->GetMaxClients(); i++) {
|
for (int i = 1; i <= i_engine->GetMaxClients(); i++) {
|
||||||
@ -29,14 +26,19 @@ static vec3_t get_closest_delta(vec3_t viewangles) {
|
|||||||
if (!is_alive(ent) || is_friend(ent))
|
if (!is_alive(ent) || is_friend(ent))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
/* TODO: Get bones origin */
|
/* TODO: Get bones origin instead of calculating from ent origin */
|
||||||
const vec3_t head_pos = vec_add(ent->origin, vec3(0, 0, 0.6f));
|
const vec3_t head_pos = vec_add(ent->origin, vec3(0, 0, HEAD_OFFSET));
|
||||||
const vec3_t enemy_angle = vec_to_ang(vec_sub(head_pos, local_eyes));
|
const vec3_t enemy_angle = vec_to_ang(vec_sub(head_pos, local_eyes));
|
||||||
|
|
||||||
const vec3_t delta = vec_sub(enemy_angle, viewangles);
|
const vec3_t delta = vec_sub(enemy_angle, viewangles);
|
||||||
vec_norm(delta);
|
vec_norm(delta);
|
||||||
|
|
||||||
const float fov = hypotf(delta.x, delta.y);
|
float fov = hypotf(delta.x, delta.y);
|
||||||
|
if (fov > 360.0f) {
|
||||||
|
fov = remainderf(fov, 360.0f);
|
||||||
|
if (fov > 180.0f)
|
||||||
|
fov = 360.0f - fov;
|
||||||
|
}
|
||||||
|
|
||||||
if (fov < best_fov) {
|
if (fov < best_fov) {
|
||||||
best_fov = fov;
|
best_fov = fov;
|
||||||
@ -48,14 +50,14 @@ static vec3_t get_closest_delta(vec3_t viewangles) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void aimbot(usercmd_t* cmd) {
|
void aimbot(usercmd_t* cmd) {
|
||||||
const int setting = cv_aimbot->value;
|
if (!CVAR_ON(aimbot) || !(cmd->buttons & IN_ATTACK))
|
||||||
if (setting == OFF || !(cmd->buttons & IN_ATTACK))
|
|
||||||
return;
|
return;
|
||||||
|
|
||||||
/* Calculate delta with the engine viewangles, not with the cmd ones */
|
/* Calculate delta with the engine viewangles, not with the cmd ones */
|
||||||
vec3_t engine_viewangles;
|
vec3_t engine_viewangles;
|
||||||
i_engine->GetViewAngles(engine_viewangles);
|
i_engine->GetViewAngles(engine_viewangles);
|
||||||
|
|
||||||
|
/* TODO: Add setting for lowest health */
|
||||||
vec3_t best_delta = get_closest_delta(engine_viewangles);
|
vec3_t best_delta = get_closest_delta(engine_viewangles);
|
||||||
if (!vec_is_zero(best_delta)) {
|
if (!vec_is_zero(best_delta)) {
|
||||||
/* NOTE: We can divide the best delta here to add smoothing */
|
/* NOTE: We can divide the best delta here to add smoothing */
|
||||||
@ -66,4 +68,7 @@ void aimbot(usercmd_t* cmd) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
vec_copy(cmd->viewangles, engine_viewangles);
|
vec_copy(cmd->viewangles, engine_viewangles);
|
||||||
|
|
||||||
|
/* NOTE: Uncomment to disable silent aim */
|
||||||
|
/* i_engine->SetViewAngles(engine_viewangles); */
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user