Antirecoil Script

GPC script programming for Titan Two device. Code examples, how to, questions, requests.

Moderators: The_Rabid_Taco, pablosscripts, bonefisher

Antirecoil Script

Postby Gorphius » Fri Jul 12, 2019 5:56 pm

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?
User avatar
Gorphius
Staff Sergeant
Staff Sergeant
 
Posts: 15
Joined: Tue Nov 13, 2018 7:54 pm

Re: Antirecoil Script

Postby alanmcgregor » Fri Jul 12, 2019 8:40 pm

The Antirecoil Utility has it.
Attachments
Untitled-2.jpg
Untitled-2.jpg (77.55 KiB) Viewed 145 times
User avatar
alanmcgregor
Major
Major
 
Posts: 995
Joined: Tue Mar 27, 2018 8:38 am

Re: Antirecoil Script

Postby Gorphius » Fri Jul 12, 2019 9:24 pm

Would I be able to use this in the same slot with other code?
User avatar
Gorphius
Staff Sergeant
Staff Sergeant
 
Posts: 15
Joined: Tue Nov 13, 2018 7:54 pm

Re: Antirecoil Script

Postby alanmcgregor » Fri Jul 12, 2019 10:05 pm

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:
User avatar
alanmcgregor
Major
Major
 
Posts: 995
Joined: Tue Mar 27, 2018 8:38 am

Re: Antirecoil Script

Postby Gorphius » Fri Jul 12, 2019 10:19 pm

Awesome! Man seriously thanks for all your help lately!
User avatar
Gorphius
Staff Sergeant
Staff Sergeant
 
Posts: 15
Joined: Tue Nov 13, 2018 7:54 pm

Re: Antirecoil Script

Postby alanmcgregor » Sat Jul 13, 2019 12:28 am

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)));
}
 
 
User avatar
alanmcgregor
Major
Major
 
Posts: 995
Joined: Tue Mar 27, 2018 8:38 am

Postby Gorphius » Sun Jul 14, 2019 4:59 pm

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?
User avatar
Gorphius
Staff Sergeant
Staff Sergeant
 
Posts: 15
Joined: Tue Nov 13, 2018 7:54 pm

Re: Antirecoil Script

Postby Mad » Sun Jul 14, 2019 6:24 pm

Code: Select all
//Anti Recoil toggle
bool tAntiRecoil = TRUE;


Change it to false.
ConsoleTuner Support Team || Discord
Mad
Command Sergeant Major
Command Sergeant Major
 
Posts: 151
Joined: Wed May 22, 2019 5:39 am

Re: Antirecoil Script

Postby Gorphius » Sun Jul 14, 2019 10:40 pm

Thanks Mad!
User avatar
Gorphius
Staff Sergeant
Staff Sergeant
 
Posts: 15
Joined: Tue Nov 13, 2018 7:54 pm


Return to GPC Script Programming (Titan Two)

Who is online

Users browsing this forum: Google [Bot] and 7 guests