What's new

Welcome to HvH Forum!

SignUp Now! Download Free HvH CS2/CS:GO Cheats, CFG, LUA/JS Scripts, And More!


SignUp Now!

Source Code how to fix strafe in supremacy

wex
User ID
20119
Messages
44
Reactions
1,087
Level
26
I tried to make wsad autostrafe in supremacy, but nothing changes, help plz
 
Rookie HvHer
User ID
10533
Messages
83
Reactions
23
Level
15
strafe:
void Movement::Strafe() {
    vec3_t velocity;
    float  delta, abs_delta, velocity_angle, velocity_delta, correct;

    // don't strafe while noclipping or on ladders..
    if (g_cl.m_local->m_MoveType() == MOVETYPE_NOCLIP || g_cl.m_local->m_MoveType() == MOVETYPE_LADDER)
        return;

    // disable strafing while pressing shift.
    // don't strafe if not holding primary jump key.
    if ((g_cl.m_buttons & IN_SPEED) || !(g_cl.m_buttons & IN_JUMP) || (g_cl.m_flags & FL_ONGROUND))
        return;

    // jumpscout.
    if (g_input.GetKeyState(g_menu.main.movement.fakewalk.get()) || !g_cl.m_pressing_move) {
        FullStop();
        return;
    }

    // get networked velocity ( maybe absvelocity better here? ).
    // meh, should be predicted anyway? ill see.
    velocity = g_cl.m_local->m_vecVelocity();

    // get the velocity len2d ( speed ).
    m_speed = velocity.length_2d();

    // compute the ideal strafe angle for our velocity.
    m_ideal = (m_speed > 0.f) ? math::rad_to_deg(std::asin(15.f / m_speed)) : 90.f;
    m_ideal2 = (m_speed > 0.f) ? math::rad_to_deg(std::asin(30.f / m_speed)) : 90.f;

    // some additional sanity.
    math::clamp(m_ideal, 0.f, 90.f);
    math::clamp(m_ideal2, 0.f, 90.f);

    // save entity bounds ( used much in circle-strafer ).
    m_mins = g_cl.m_local->m_vecMins();
    m_maxs = g_cl.m_local->m_vecMaxs();

    // save our origin
    m_origin = g_cl.m_local->m_vecOrigin();

    // for changing direction.
    // we want to change strafe direction every call.
    m_switch_value *= -1.f;

    // for allign strafer.
    ++m_strafe_index;

    // wasd strafer.
    if (g_menu.main.movement.autostrafe.get() == 2 && g_cl.m_pressing_move) {
        // list of directions.
        enum EDirections {
            FORWARDS = 0,
            BACKWARDS = 180,
            LEFT = 90,
            RIGHT = -90,
            BACK_LEFT = 135,
            BACK_RIGHT = -135,
            FORWARD_LEFT = 45,
            FORWARD_RIGHT = -45
        };

        float wish_dir{ };

        // get pressed movement keys.
        bool holding_w = g_cl.m_buttons & IN_FORWARD;
        bool holding_a = g_cl.m_buttons & IN_MOVELEFT;
        bool holding_s = g_cl.m_buttons & IN_BACK;
        bool holding_d = g_cl.m_buttons & IN_MOVERIGHT;

        // get wish direction based on key presses.
        if (holding_w) {
            if (holding_a) {
                wish_dir += EDirections::FORWARD_LEFT;
            }
            else if (holding_d) {
                wish_dir += EDirections::FORWARD_RIGHT;
            }
            else {
                wish_dir += EDirections::FORWARDS;
            }
        }
        else
            if (holding_s) {
                if (holding_a) {
                    wish_dir += EDirections::BACK_LEFT;
                }
                else if (holding_d) {
                    wish_dir += EDirections::BACK_RIGHT;
                }
                else {
                    wish_dir += EDirections::BACKWARDS;
                }

                // we don't want to go forwards if we're trying to go backwards.
                g_cl.m_cmd->m_forward_move = 0.f;
            }
            else if (holding_a) {
                wish_dir += EDirections::LEFT;
            }
            else if (holding_d) {
                wish_dir += EDirections::RIGHT;
            }

        // our movement fix will take care of moving us in the correct direction.
        g_cl.m_strafe_angles.y += math::NormalizedAngle(wish_dir);
    }

    // cancel out any forwardmove values.
    g_cl.m_cmd->m_forward_move = 0.f;

    // do allign strafer.
    if (g_input.GetKeyState(g_menu.main.movement.astrafe.get())) {
        float angle = std::max(m_ideal2, 4.f);

        if (angle > m_ideal2 && !(m_strafe_index % 5))
            angle = m_ideal2;

        // add the computed step to the steps of the previous circle iterations.
        m_circle_yaw = math::NormalizedAngle(m_circle_yaw + angle);

        // apply data to usercmd.
        g_cl.m_strafe_angles.y = m_circle_yaw;
        g_cl.m_cmd->m_side_move = -450.f;

        return;
    }

    // do ciclestrafer
    else if (g_input.GetKeyState(g_menu.main.movement.cstrafe.get())) {
        // if no duck jump.
        if (!g_menu.main.movement.airduck.get()) {
            // crouch to fit into narrow areas.
            g_cl.m_cmd->m_buttons |= IN_DUCK;
        }

        DoPrespeed();
        return;
    }

    else if (g_input.GetKeyState(g_menu.main.movement.zstrafe.get())) {
        float freq = (g_menu.main.movement.z_freq.get() * 0.2f) * g_csgo.m_globals->m_realtime;

        // range [ 1, 100 ], aka grenerates a factor.
        float factor = g_menu.main.movement.z_dist.get() * 0.5f;

        g_cl.m_strafe_angles.y += (factor * std::sin(freq));
    }

    if (g_menu.main.movement.autostrafe.get() < 1)
        return;

    // get our viewangle change.
    delta = math::NormalizedAngle(g_cl.m_strafe_angles.y - m_old_yaw);

    // convert to absolute change.
    abs_delta = std::abs(delta);

    // save old yaw for next call.
    m_circle_yaw = m_old_yaw = g_cl.m_strafe_angles.y;

    // set strafe direction based on mouse direction change.
    if (delta > 0.f)
        g_cl.m_cmd->m_side_move = -450.f;

    else if (delta < 0.f)
        g_cl.m_cmd->m_side_move = 450.f;

    // we can accelerate more, because we strafed less then needed
    // or we got of track and need to be retracked.

    /*
    * data struct
    * 68 74 74 70 73 3a 2f 2f 73 74 65 61 6d 63 6f 6d 6d 75 6e 69 74 79 2e 63 6f 6d 2f 69 64 2f 73 69 6d 70 6c 65 72 65 61 6c 69 73 74 69 63 2f
    */

    if (abs_delta <= m_ideal || abs_delta >= 30.f) {
        // compute angle of the direction we are traveling in.
        velocity_angle = math::rad_to_deg(std::atan2(velocity.y, velocity.x));

        // get the delta between our direction and where we are looking at.
        velocity_delta = math::NormalizedAngle(g_cl.m_strafe_angles.y - velocity_angle);

        // correct our strafe amongst the path of a circle.
        correct = m_ideal2 * 2.f;

        if (velocity_delta <= correct || m_speed <= 15.f) {
            // not moving mouse, switch strafe every tick.
            if (-correct <= velocity_delta || m_speed <= 15.f) {
                g_cl.m_strafe_angles.y += (m_ideal * m_switch_value);
                g_cl.m_cmd->m_side_move = 450.f * m_switch_value;
            }

            else {
                g_cl.m_strafe_angles.y = velocity_angle - correct;
                g_cl.m_cmd->m_side_move = 450.f;
            }
        }

        else {
            g_cl.m_strafe_angles.y = velocity_angle + correct;
            g_cl.m_cmd->m_side_move = -450.f;
        }
    }
}
 

Create an account or login to comment

You must be a member in order to leave a comment

Create account

Create an account on our community. It's easy!

Log in

Already have an account? Log in here.

Top