Эксперт
- Статус
- Оффлайн
- Регистрация
- 8 Авг 2018
- Сообщения
- 2,231
- Реакции
- 631
Код:
bool HitChance(C_BasePlayer* pEnt, C_BaseCombatWeapon* pWeapon, QAngle Angle, int chance, CUserCmd* cmd)
{
int traces_hit = 0;
auto local = g_LocalPlayer;
if (!local)
return false;
Vector forward, right, up;
const Vector eye_position = local->GetEyePos();
Math::AngleVectors(Angle, forward, right, up); // maybe add an option to not account for punch.
int cNeededHits = static_cast<int>(256.f * (chance / 100.f));
auto weapon = local->m_hActiveWeapon();
if (!weapon)
return false;
if (g_Options.rage_hitchance <= 0)
return true;
c_prediction_system::Get().repredict(g_LocalPlayer, cmd);
float weapon_spread = weapon->GetSpread();
float weapon_cone = weapon->GetInaccuracy();
const auto get_bullet_location = [&](int seed) {
RandomSeed(seed + 1);
float a = Math::RandomFloat(0.f, 1.f);
float b = Math::RandomFloat(0.f, 2.f * M_PI);
float c = Math::RandomFloat(0.f, 1.f);
float d = Math::RandomFloat(0.f, 2.f * M_PI);
if (pWeapon->m_Item().m_iItemDefinitionIndex() == WEAPON_REVOLVER)
{
a = 1.f - a * a;
c = 1.f - c * c;
}
const float generated_spread = a * weapon_spread;
const float generated_cone = c * weapon_cone;
const Vector spread = Vector(
std::cos(b) * generated_spread + std::cos(d) * generated_cone,
std::sin(b) * generated_spread + std::sin(d) * generated_cone,
0.f
);
return Vector(forward + right * -spread.x + up * -spread.y).Normalized();
};
const auto round_acc = [](const float accuracy) { return roundf(accuracy * 1000.f) / 1000.f; };
const auto sniper = weapon->m_Item().m_iItemDefinitionIndex() == WEAPON_AWP || weapon->m_Item().m_iItemDefinitionIndex() == WEAPON_G3SG1
|| weapon->m_Item().m_iItemDefinitionIndex() == WEAPON_SCAR20 || weapon->m_Item().m_iItemDefinitionIndex() == WEAPON_SSG08;
for (int i = 1; i <= 255; i++) {
QAngle spread_angle;
Vector bullet_end;
Math::VectorAngles(get_bullet_location(i), spread_angle);
Math::AngleVectors(Angle - (spread_angle - Angle), bullet_end);
trace_t trace;
Ray_t ray;
ray.Init(eye_position, eye_position + bullet_end * weapon->GetCSWeaponData()->flRange);
g_EngineTrace->ClipRayToEntity(ray, MASK_SHOT, pEnt, &trace);
if (trace.hit_entity == pEnt)
++traces_hit;
if (traces_hit >= static_cast<int>(chance * 2.55f))
return true;
}
return false;
}
Проблема в том, что при хитшансе 100 я стреляю почти ноускопами со скара или скаута и бывает обоймами миссаю, код правильный, так что ничего не могу сделать. В чём проблема?

