Начинающий
- Статус
- Оффлайн
- Регистрация
- 2 Ноя 2024
- Сообщения
- 188
- Реакции
- 17
Код:
void c_movement::straight_throw(c_user_cmd* user_cmd) {
if (!g_cfg->misc.m_straight_throw)
return;
auto* local = g_ctx->m_local_pawn;
if (!local || !local->is_alive())
return;
if (local->m_move_type() == 8)
return;
auto* weapon = local->get_active_weapon();
if (!weapon) return;
auto* wdata = weapon->get_weapon_data();
if (!wdata) return;
if (wdata->m_weapon_type() != 9)
return;
auto* grenade = reinterpret_cast<c_base_cs_grenade*>(weapon);
const bool attack1 = (user_cmd->m_button_state.m_button_state & IN_ATTACK) != 0;
const bool attack2 = (user_cmd->m_button_state.m_button_state & IN_SECOND_ATTACK) != 0;
const bool throwing = grenade->m_pin_pulled() || grenade->m_throw_time() > 0.f;
if (!attack1 && !attack2 && !throwing)
return;
float pitch = user_cmd->pb.mutable_base()->viewangles().x();
float yaw = user_cmd->pb.mutable_base()->viewangles().y();
float throw_pitch = pitch - (90.f - std::abs(pitch)) * 10.f / 90.f;
float pitch_rad = throw_pitch * (M_PI / 180.f);
float yaw_rad = yaw * (M_PI / 180.f);
vec3_t throw_dir = {
std::cos(pitch_rad) * std::cos(yaw_rad),
std::cos(pitch_rad) * std::sin(yaw_rad),
-std::sin(pitch_rad)
};
float throw_strength = std::clamp(grenade->m_throw_strength(), 0.f, 1.f);
float fl_velocity = std::clamp(wdata->m_throw_velocity() * 0.9f, 15.f, 750.f);
fl_velocity = fl_velocity * (throw_strength * 0.7f + 0.3f);
vec3_t player_vel = local->m_vec_abs_velocity();
vec3_t vec_throw = {
throw_dir.x * fl_velocity + player_vel.x * 1.45f,
throw_dir.y * fl_velocity + player_vel.y * 1.45f,
throw_dir.z * fl_velocity + player_vel.z * 1.45f
};
float len_2d = std::sqrt(vec_throw.x * vec_throw.x + vec_throw.y * vec_throw.y);
float target_pitch = -std::atan2(vec_throw.z, len_2d) * (180.f / M_PI);
float target_yaw = std::atan2(vec_throw.y, vec_throw.x) * (180.f / M_PI);
float yaw_diff = yaw - target_yaw;
float pitch_diff = pitch - target_pitch - 10.f;
while (yaw_diff > 180.f) yaw_diff -= 360.f;
while (yaw_diff < -180.f) yaw_diff += 360.f;
while (pitch_diff > 90.f) pitch_diff -= 45.f;
while (pitch_diff < -90.f) pitch_diff += 45.f;
float new_yaw = yaw + yaw_diff;
float new_pitch = std::clamp(pitch + pitch_diff, -89.f, 89.f);
user_cmd->pb.mutable_base()->mutable_viewangles()->set_x(new_pitch);
user_cmd->pb.mutable_base()->mutable_viewangles()->set_y(new_yaw);
}