Page 1 of 1

Antirecoil Script

PostPosted: Fri Jul 12, 2019 5:56 pm
by Gorphius
Anybody know if it’s possible to create a script where you have different anti recoil values one for zooming and one for hip fire?

Re: Antirecoil Script

PostPosted: Fri Jul 12, 2019 8:40 pm
by alanmcgregor
The Antirecoil Utility has it.

Re: Antirecoil Script

PostPosted: Fri Jul 12, 2019 9:24 pm
by Gorphius
Would I be able to use this in the same slot with other code?

Re: Antirecoil Script

PostPosted: Fri Jul 12, 2019 10:05 pm
by alanmcgregor
No, is a stand alone script.

If you want a code that can give you two difference antirecoils for HIP and ADS.

Try this:
Code: Select all
 
 #pragma METAINFO("AntiRecoil", 1, 0, "AryanXbonefisher")
/* Special credits goes out to AryanX and Bonefisher*/
 
// AntiRecoil Float values 0.0
#define StickNoise             6.32
#define MinARecoilPercent     20.0
#define ARecoil_H             0.0
#define ARecoil_V_ADS         20.0
#define ARecoil_V_HIP         10.0
 
// AntiRecoil Delay
#define ARecoilDelay         50
 
//Anti Recoil toggle
bool tAntiRecoil = TRUE;
 
main {
 
    if(get_actual(BUTTON_8)){ // ANTIRECOIL ON/OFF: HOLD L2/LT, PRESS Ps/XB1, RELEASE L2/LT
        set_val(BUTTON_1, 0.0);
        if(event_active(BUTTON_1)) tAntiRecoil = !tAntiRecoil;
    }
 
    if (tAntiRecoil){
        if (check_active(BUTTON_5, ARecoilDelay)){
            if (abs(get_actual(STICK_1_X)) < StickNoise) set_val(STICK_1_X, 0.0);
            if (abs(get_actual(STICK_1_Y)) < StickNoise) set_val(STICK_1_Y, 0.0);
            if (abs(get_actual(STICK_2_X)) < StickNoise) set_val(STICK_2_X, 0.0);
            if (abs(get_actual(STICK_2_Y)) < StickNoise) set_val(STICK_2_Y, 0.0);
 
            if (is_active(BUTTON_5) && (is_active(BUTTON_8))){ // ADS AntiRecoil
                AntiRecoil(STICK_1_X, ARecoil_H);
                AntiRecoil(STICK_1_Y, ARecoil_V_ADS);
            }
            else
                if (is_active(BUTTON_5) && (!is_active(BUTTON_8))){ // HIP AntiRecoil
                    AntiRecoil(STICK_1_X, ARecoil_H);
                    AntiRecoil(STICK_1_Y, ARecoil_V_HIP);
                }
        }
    }
}
 
void AntiRecoil(uint8 AxisToApply, fix32 ARecoilToApply){
    fix32 CurrentX = get_val(STICK_1_X);
    fix32 CurrentY = get_val(STICK_1_Y);
    fix32 MinARecoilFactor = MinARecoilPercent / 100.0;
    fix32 MinARecoilToApply = MinARecoilFactor * ARecoilToApply;
    //This sets the ARecoil to be dependent on both X and Y axis movement. With more emphasis on Y
    fix32 MovementARecoilToApply = (1.0 - MinARecoilFactor) * ((ARecoilToApply * (100.0 - sqrt(CurrentX*CurrentX + CurrentY*CurrentY))) / (100.0 + abs(CurrentX) + (CurrentY*CurrentY*0.5)));
    set_val(AxisToApply, clamp((MinARecoilToApply + MovementARecoilToApply + get_val(AxisToApply)), -100.00, (100.00 - MinARecoilToApply)));
}
 

:smile0517:

Re: Antirecoil Script

PostPosted: Fri Jul 12, 2019 10:19 pm
by Gorphius
Awesome! Man seriously thanks for all your help lately!

Re: Antirecoil Script

PostPosted: Sat Jul 13, 2019 12:28 am
by alanmcgregor
No problem :wink:

This is the same but also allows to set different antirecoil horizontal for both HIP and ADS fire.

Code: Select all
 
#pragma METAINFO("AntiRecoil", 1, 0, "AryanXbonefisher")
/* Special credits goes out to AryanX and Bonefisher*/
 
// AntiRecoil Float values 0.0
#define StickNoise                 6.32 //<--- Stick max rest value
#define MinARecoilPercent         20.0 //<--- Percent of AntiRecoil apply while aiming
 
// Horizontal AntiRecoil
#define ARecoil_H_ADS              0.0  //<----Change this value for horizontal ADS antirecoil
#define ARecoil_H_HIP              0.0  //<----Change this value for horizontal HIP antirecoil
 
// Vertical AntiRecoil
#define ARecoil_V_ADS             10.0 //<--- Change this Value for vertical ADS antirecoil
#define ARecoil_V_HIP             20.0 //<--- Change this Value for vertical HIP antirecoil
 
// AntiRecoil Delay
#define ARecoilDelay             50
 
//Anti Recoil toggle
bool tAntiRecoil = TRUE;
 
main {
 
    if(get_actual(BUTTON_8)){ // ANTIRECOIL ON/OFF: HOLD L2/LT, PRESS Ps/XB1, RELEASE L2/LT
        set_val(BUTTON_1, 0.0);
        if(event_active(BUTTON_1)) tAntiRecoil = !tAntiRecoil;
    }
 
    if (tAntiRecoil){
        if (check_active(BUTTON_5, ARecoilDelay)){
            if (abs(get_actual(STICK_1_X)) < StickNoise) set_val(STICK_1_X, 0.0);
            if (abs(get_actual(STICK_1_Y)) < StickNoise) set_val(STICK_1_Y, 0.0);
            if (abs(get_actual(STICK_2_X)) < StickNoise) set_val(STICK_2_X, 0.0);
            if (abs(get_actual(STICK_2_Y)) < StickNoise) set_val(STICK_2_Y, 0.0);
 
            if (is_active(BUTTON_5) && (is_active(BUTTON_8))){ // ADS AntiRecoil
                AntiRecoil(STICK_1_X, ARecoil_H_ADS);
                AntiRecoil(STICK_1_Y, ARecoil_V_ADS);
            }
            else
                if (is_active(BUTTON_5) && (!is_active(BUTTON_8))){ // HIP AntiRecoil
                    AntiRecoil(STICK_1_X, ARecoil_H_HIP);
                    AntiRecoil(STICK_1_Y, ARecoil_V_HIP);
                }
        }
    }
}
 
void AntiRecoil(uint8 AxisToApply, fix32 ARecoilToApply){
    fix32 CurrentX = get_val(STICK_1_X);
    fix32 CurrentY = get_val(STICK_1_Y);
    fix32 MinARecoilFactor = MinARecoilPercent / 100.0;
    fix32 MinARecoilToApply = MinARecoilFactor * ARecoilToApply;
    //This sets the ARecoil to be dependent on both X and Y axis movement. With more emphasis on Y
    fix32 MovementARecoilToApply = (1.0 - MinARecoilFactor) * ((ARecoilToApply * (100.0 - sqrt(CurrentX*CurrentX + CurrentY*CurrentY))) / (100.0 + abs(CurrentX) + (CurrentY*CurrentY*0.5)));
    set_val(AxisToApply, clamp((MinARecoilToApply + MovementARecoilToApply + get_val(AxisToApply)), -100.00, (100.00 - MinARecoilToApply)));
}
 
 

PostPosted: Sun Jul 14, 2019 4:59 pm
by Gorphius
Nice this will come in handy thanks! So the vertical script is initially active but the rapid fire script I use is initially off so when I activate it it turns off the anti recoil. Is there any easy tweaking to make it so the vertical recoil script is off starting out?

Re: Antirecoil Script

PostPosted: Sun Jul 14, 2019 6:24 pm
by Mad
Code: Select all
//Anti Recoil toggle
bool tAntiRecoil = TRUE;


Change it to false.

Re: Antirecoil Script

PostPosted: Sun Jul 14, 2019 10:40 pm
by Gorphius
Thanks Mad!