yoo bro, i see a big paster)()
-
Автор темы
- #1
Хитшанс не видит значения которые я ставлю, всегда 1:
C++:
{
// generate look-up-table to enhance performance.
build_seed_table();
const auto info = g_ctx.globals.weapon->get_csweapon_info();
if (!info)
{
final_hitchance = 0;
return true;
}
const auto hitchance_cfg = g_cfg.ragebot.weapon[g_ctx.globals.current_weapon].hitchance_amount;
// performance optimization.
if ((g_ctx.globals.eye_pos - final_target.data.point.point).Length() > info->flRange)
{
final_hitchance = 0;
return true;
}
static auto nospread = m_cvar()->FindVar(crypt_str("weapon_accuracy_nospread"));
if (nospread->GetBool())
{
final_hitchance = INT_MAX;
return true;
}
// setup calculation parameters.
const auto round_acc = [](const float accuracy) { return roundf(accuracy * 1000.f) / 1000.f; };
const auto sniper = g_ctx.globals.weapon->m_iItemDefinitionIndex() == WEAPON_AWP || g_ctx.globals.weapon->m_iItemDefinitionIndex() == WEAPON_G3SG1
|| g_ctx.globals.weapon->m_iItemDefinitionIndex() == WEAPON_SCAR20 || g_ctx.globals.weapon->m_iItemDefinitionIndex() == WEAPON_SSG08;
const auto crouched = g_ctx.local()->m_fFlags() & FL_DUCKING;
const auto on_ground = g_ctx.local()->m_fFlags() & FL_ONGROUND;
// calculate inaccuracy.
const auto weapon_inaccuracy = g_ctx.globals.weapon->get_inaccuracy();
// no need for hitchance, if we can't increase it anyway.
if (crouched)
{
if (round_acc(weapon_inaccuracy) == round_acc(sniper ? info->flInaccuracyCrouchAlt : info->flInaccuracyCrouch))
{
final_hitchance = INT_MAX;
return true;
}
}
// calculate start and angle.
static auto weapon_recoil_scale = m_cvar()->FindVar(crypt_str("weapon_recoil_scale"));
const auto aim_angle = math::calculate_angle(g_ctx.globals.eye_pos, final_target.data.point.point).Clamp();
auto forward = ZERO;
auto right = ZERO;
auto up = ZERO;
math::angle_vectors(aim_angle, &forward, &right, &up);
math::fast_vec_normalize(forward);
math::fast_vec_normalize(right);
math::fast_vec_normalize(up);
// keep track of all traces that hit the enemy.
auto current = 0;
// setup calculation parameters.
Vector total_spread, spread_angle, end;
float inaccuracy, spread_x, spread_y;
std::tuple<float, float, float>* seed;
// use look-up-table to find average hit probability.
for (int i = 0; i < 255; i++) // NOLINT(modernize-loop-convert)
{
// get seed.
seed = &precomputed_seeds[i];
// calculate spread.
inaccuracy = std::get<0>(*seed) * weapon_inaccuracy;
spread_x = std::get<2>(*seed) * inaccuracy;
spread_y = std::get<1>(*seed) * inaccuracy;
total_spread = (forward + right * spread_x + up * spread_y);
total_spread.Normalize();
// calculate angle with spread applied.
math::vector_angles(total_spread, spread_angle);
// calculate end point of trace.
math::angle_vectors(spread_angle, end);
end.Normalize();
end = g_ctx.globals.eye_pos + end * info->flRange;
trace_t ll;
Ray_t rr;
for (auto i = 0; i < 2; i++)
{
rr.Init(g_ctx.globals.eye_pos, end);
m_trace()->ClipRayToEntity(rr, 0x4600400B, final_target.record->player, &ll);
bool can_damage = (ll.hitgroup >= 0 && ll.hitgroup <= 8);
bool is_required_player = (ll.hit_entity == final_target.record->player);
if (can_damage && is_required_player)
++current;
}
if (hitbox_intersection(final_target.record->player, final_target.record->matrixes_data.main, final_target.data.hitbox, g_ctx.globals.eye_pos, end))
++current;
// abort if hitchance is already sufficent.
if ((static_cast<float>(current) / 255.f) >= hitchance_cfg / 100.f)
{
final_hitchance = (static_cast<float>(current) / 255.f) * 100.f;
return true;
}
// abort if we can no longer reach hitchance.
if ((static_cast<float>(current + 255 - i) / 255.f) < hitchance_cfg / 100.f)
{
final_hitchance = (static_cast<float>(current + 255 - i) / 255.f) * 100.f;
return false;
}
}
final_hitchance = (static_cast<float>(current) / 255.f) * 100.f;
return (static_cast<float>(current) / 255.f) >= hitchance_cfg / 100.f;
}