like amiri in my mind
Пользователь
-
Автор темы
- #1
вдохновился -
и сделал хитчанс в 20 строк(без коментов то да)
Пожалуйста, авторизуйтесь для просмотра ссылки.
и сделал хитчанс в 20 строк(без коментов то да)
hitchance:
bool aim::simple_hitchance(float chance, Vector aim_angle,player_t* ent) {
//firstly define some variables
auto src = g_ctx.globals.eye_pos; //our origin of shoot for next tracing to our target
int hits = 0; //needed hits
int rays = 256; // use up to 256 for better accuracy calculating u can use less than 256 for example for high accuracy weapon
//48 rays may be enough for high accuracy weapon
auto wep_info = g_ctx.globals.weapon->get_csweapon_info(); //wep info
for (int i = 0; i < rays; i++)
{
auto spread = g_ctx.globals.inaccuracy + g_ctx.globals.spread; // curr spread def already known formule
//p2c spread randomizer calculation (better than skeet does)
Vector randomizer = { math::random_float(-(spread / 2), spread / 2),
math::random_float(-(spread / 2), spread / 2),
math::random_float(-(spread / 2), spread / 2) };
Vector forward;
math::angle_vectors(aim_angle, forward);
trace_t tr;
Ray_t ray;
//apply our p2c spread randomizer to our target
auto randomized_forward = forward + randomizer; //we look at our point then apply our randomly based spread
ray.Init(src, src + randomized_forward * wep_info->flRange);
m_trace()->ClipRayToEntity(ray, MASK_SHOT, ent, &tr);
//if we hit our randomized trace and hitbox is intersected then our hits++
if (tr.hit_entity == ent)
hits++;
}
//if we readched needed hits then chance is true
if (chance <= (hits / rays) * 100.f)
return true;
}