Подписывайтесь на наш Telegram и не пропускайте важные новости! Перейти

Гайд Straight Throw - Компенсация броска гранаты.

Пользователь
Пользователь
Статус
Оффлайн
Регистрация
2 Ноя 2024
Сообщения
288
Реакции
34
Код:
Expand Collapse Copy
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);
}
 
Обратите внимание, пользователь заблокирован на форуме. Не рекомендуется проводить сделки.
Код:
Expand Collapse Copy
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);
}
а может все таки??

C++:
Expand Collapse Copy
void CMovement::StraightThrow( CUserCmd* pUserCmd ) noexcept
{
    if ( !CTX::pConfig->MISC.StraightThrow.Get( ) )
        return;
    
    if ( !Features::pEnginePrediction->IsThrowNade( ) )
        return;

    auto angThrowAngles = Features::pEnginePrediction->GetPostViewAngles( ) + Core::pEntitySystem->GetLocalPlayerPawn( )->GetAimPunchServices( )->GetAimPunchAngle( );
    if ( angThrowAngles[ EAxis::X ] > 90.0f )
        angThrowAngles[ EAxis::X ] -= 360.0f;
    else if ( angThrowAngles[ EAxis::X ] < -90.0f )
        angThrowAngles[ EAxis::X ] += 360.0f;
    
    angThrowAngles[ EAxis::X ] -= 10.0f * ( 90.0f - std::abs( angThrowAngles[ EAxis::X ] ) ) / 90.0f;
    
    const auto flBaseVelocity = Core::pEntitySystem->GetWeaponData( )->GetThrowVelocity( );
    auto flThrowVelocity = std::clamp( flBaseVelocity * 0.9f, 15.0f, 750.0f );
    const auto flThrowStrength = std::clamp( Core::pEntitySystem->GetThrowStrength( ), 0.0f, 1.0f );
    
    flThrowVelocity *= std::lerp( 0.3f, 1.0f, flThrowStrength );
    
    Math::Vector3D_t vecForward;
    Math::AngleVectors( angThrowAngles, &vecForward );
    
    const auto vecThrowDirection = vecForward * flThrowVelocity + Features::pEnginePrediction->GetPostAbsVelocity( ) * 1.25f;
    
    Math::QAngle_t angThrow;
    Math::VectorAngles( vecThrowDirection, angThrow );
    
    pUserCmd->pb.mutable_base( )->mutable_viewangles( )->set_x( pUserCmd->pb.mutable_base( )->mutable_viewangles( )->x( ) - ( angThrow[ EAxis::X ] - angThrowAngles[ EAxis::X ] ) );
    pUserCmd->pb.mutable_base( )->mutable_viewangles( )->set_y( pUserCmd->pb.mutable_base( )->mutable_viewangles( )->y( ) - ( angThrow[ EAxis::Y ] - angThrowAngles[ EAxis::Y ] ) );
}
 
Это типо супир тосс?
да

а может все таки??

C++:
Expand Collapse Copy
void CMovement::StraightThrow( CUserCmd* pUserCmd ) noexcept
{
    if ( !CTX::pConfig->MISC.StraightThrow.Get( ) )
        return;
   
    if ( !Features::pEnginePrediction->IsThrowNade( ) )
        return;

    auto angThrowAngles = Features::pEnginePrediction->GetPostViewAngles( ) + Core::pEntitySystem->GetLocalPlayerPawn( )->GetAimPunchServices( )->GetAimPunchAngle( );
    if ( angThrowAngles[ EAxis::X ] > 90.0f )
        angThrowAngles[ EAxis::X ] -= 360.0f;
    else if ( angThrowAngles[ EAxis::X ] < -90.0f )
        angThrowAngles[ EAxis::X ] += 360.0f;
   
    angThrowAngles[ EAxis::X ] -= 10.0f * ( 90.0f - std::abs( angThrowAngles[ EAxis::X ] ) ) / 90.0f;
   
    const auto flBaseVelocity = Core::pEntitySystem->GetWeaponData( )->GetThrowVelocity( );
    auto flThrowVelocity = std::clamp( flBaseVelocity * 0.9f, 15.0f, 750.0f );
    const auto flThrowStrength = std::clamp( Core::pEntitySystem->GetThrowStrength( ), 0.0f, 1.0f );
   
    flThrowVelocity *= std::lerp( 0.3f, 1.0f, flThrowStrength );
   
    Math::Vector3D_t vecForward;
    Math::AngleVectors( angThrowAngles, &vecForward );
   
    const auto vecThrowDirection = vecForward * flThrowVelocity + Features::pEnginePrediction->GetPostAbsVelocity( ) * 1.25f;
   
    Math::QAngle_t angThrow;
    Math::VectorAngles( vecThrowDirection, angThrow );
   
    pUserCmd->pb.mutable_base( )->mutable_viewangles( )->set_x( pUserCmd->pb.mutable_base( )->mutable_viewangles( )->x( ) - ( angThrow[ EAxis::X ] - angThrowAngles[ EAxis::X ] ) );
    pUserCmd->pb.mutable_base( )->mutable_viewangles( )->set_y( pUserCmd->pb.mutable_base( )->mutable_viewangles( )->y( ) - ( angThrow[ EAxis::Y ] - angThrowAngles[ EAxis::Y ] ) );
}
а может все таки следовало слить это до меня)))?
 
Назад
Сверху Снизу