Auto Anti-Recoil Compensation

GPC2 script programming for Titan Two. Code examples, questions, requests.

Auto Anti-Recoil Compensation

Postby USER101 » Sun Mar 31, 2019 11:32 pm

Hello Team,
I need your help. I want my vertical anti recoil to auto adjust itself. So I am thinking that while the fire trigger is held it starts temporarily capturing the input of STICK_1_Y like maybe every 10ms (or higher if needed) into separate variables. Then after the trigger is released it sums the values captured and creates an average (either positive or negative) then applies that to the current anti recoil variable. I am just not sure how to temporarily capture and store the movement variables. Any suggestions on that?

I am hoping this will improve compensation over time regardless of the weapon. So if you switch to an SMG after sniping or something it will compensate better after your first use. I have seen the runtime manual adjustment version and much like that this would be great for battle royal gaming. Accept you would just have to turn it on and forget it. Maybe just do a quick test fire when you grab a weapon. If I can get an alpha working I will adjust for falloff, range limits, and movement gates in the future.

If you decide to help with the code just know that I will be sharing it publicly when I get things sorted out.
Any assistance will be appreciated and acknowledged.
Thanks.
User avatar
USER101
Sergeant Major
Sergeant Major
 
Posts: 100
Joined: Mon Dec 03, 2018 5:45 pm

Re: Auto Anti-Recoil Compensation

Postby bonefisher » Mon Apr 01, 2019 12:19 am

Not possible! I did have one that while firing started to bring it down to adjust faster but still didn't like it so I went back to single click adjusting. Try my Quick Adjust in online resources for adjusting in game!
bonefisher
Lieutenant General
Lieutenant General
 
Posts: 5413
Joined: Thu Jan 29, 2015 10:49 am

Re: Auto Anti-Recoil Compensation

Postby bonefisher » Mon Apr 01, 2019 12:24 am

Unless your talking about moving stick to find happy spot!
bonefisher
Lieutenant General
Lieutenant General
 
Posts: 5413
Joined: Thu Jan 29, 2015 10:49 am

Re: Auto Anti-Recoil Compensation

Postby bonefisher » Mon Apr 01, 2019 1:09 am

Code: Select all
 
#pragma METAINFO("AUto adjust recoil", 1, 0, "bonefisher")
 
/* *****************************************************************************
<cfgdesc>
[QuickAdjust]
color          = #008000
shortdesc      = <font color="green">Runtime operations for manual overrides. Use Interactive Configurations for changes don't forget to Save and Run. </font> <br /><br /> <b><u><font color="brown">Runtime Operations</font></b></u> <br /><br /><font color="green">Hold</font><font color="brown">[FIRE BUTTON] <font color="green">and press <font color="brown">[D-PAD LEFT]<font color="green"> to turn rapid fire toggle ON/OFF(red led flash will be ON and blue led OFF).<br /><br /><font color="green">Hold</font><font color="brown">[FIRE BUTTON] <font color="green">and press <font color="brown">[D-PAD RIGHT]<font color="green"> to turn anti-recoil toggle ON/OFF(red led flash will be ON and blue led OFF).<br /><br /><font color="green">Hold</font><font color="brown">[FIRE BUTTON] <font color="green">and press <font color="brown">[D-PAD UP]<font color="green"> to adjust sps setting + .5 at a time.<br /><br /><font color="green">Hold</font><font color="brown">[FIRE BUTTON] <font color="green">and press <font color="brown">[D-PAD DOWN]<font color="green"> to adjust sps setting - .5 at a time.<br /><br /><font color="green">Hold</font><font color="brown">[ADS BUTTON] <font color="green">and Hold <font color="brown">[FIRE BUTTON] <font color="green">then adjust with<font color="brown">[D-PAD DIRECTION] <font color="green">to pull compensation force where is needed for anti-recoil. Adjusts .5 per d-pad press. Shows on output panel GtunerIV.</font>
control        = info
 
[RAPID FIRE OPTION:]
color          = #008000
collapsible    = 2
shortdesc      = <font color="brown">ENABLE:<font color="green">Rapid Fire?</font>
byteoffset     = 0
bitsize        = 8
control        = radiobox
default        = 0
item           = Rapidfire OFF
item           = Rapidfire ON
 
[RAPID FIRE SETTINGS:]
group          = true
shortdesc      = <font color="brown">SHOTS PER SECOND:</font> <font color="green">   Set to desired sps setting 1~25 sps.</font>
byteoffset     = 1
bitsize        = 32
control        = spinboxf
default        = 165
minimum        = 10
maximum        = 250
step           = 05
decimals       = 1
 
[ANTI RECOIL SETTINGS:]
color          = #008000
collapsible    = 2
shortdesc      = <font color="brown">ENABLE:<font color="green"> Anti Recoil?
byteoffset     = 10
bitsize        = 1
bitoffset      = 7
control        = checkbox
default        = 1
item           = Anti Recoil ON
 
[Anti Recoil Delay]
group          = true
shortdesc      = <font color="brown">Anti Recoil Delay:<font color="green"> (In MS) after fire button is pressed.
byteoffset     = 11
bitsize        = 16
control        = slider
default        = 0
minimum        = 0
maximum        = 1000
step           = 5
 
[Min Anti Recoil Percent]
group          = true
shortdesc      = <font color="brown">Minimum Percentage:<font color="green"> Anti Recoil to apply during aim stick movement.
byteoffset     = 13
bitsize        = 32
control        = spinboxf
default        = 200
minimum        = 0
maximum        = 1000
step           = 10
decimals       = 1
 
[Stick Noise Remover]
group          = true
shortdesc      = <font color="brown">STICK NOISE:<font color="green"> Set to the resting dead zone values for your right stick.
byteoffset     = 17
bitsize        = 32
control        = spinboxf
default        = 800
minimum        = 0
maximum        = 10000
step           = 50
decimals       = 2
 
[Standing Anti Recoil Settings]
group          = true
shortdesc      = <font color="brown">Anti Recoil:<font color="green"> vertical pull force compensation.
byteoffset     = 21
bitsize        = 32
control        = spinboxf
default        = 1800
minimum        = -10000
maximum        = 10000
step           = 10
decimals       = 2
 
[Standing Anti Recoil H Settings]
group          = true
shortdesc      = <font color="brown">Anti Recoil:<font color="green"> horizontal pull force compensation.
byteoffset     = 25
bitsize        = 32
control        = spinboxf
default        = 00000
minimum        = -10000
maximum        = 10000
step           = 10
decimals       = 2
 
</cfgdesc>
***************************************************************************** */

#include <display.gph>
#define wait(a)  wait((int)a);
#define float  fix32
 
uint8 rapid_fire;
fix32 sps;
fix32 hold_time, rest_time;
uint8 bUseAntiRecoil;
float ARecoil_H;
float ARecoil_V;
uint16 ARecoilDelay;
float MinARecoilPercent;
float StickNoise;
 
init
{
    pmem_load();
    rapid_fire = pmem_read(0);
    pmem_read(1, &sps);
    printf("<center><font style='color:blue;font-size:14px;',><br>RAPID FIRE: %u", rapid_fire);
    update_rapidfire();
 
    bUseAntiRecoil = (pmem_read(10) >> 7) & 0b1;
    printf("<center><font style='color:red;font-size:14px;',><br>ANTI RECOIL: %d", bUseAntiRecoil);
    pmem_read(11, &ARecoilDelay);
    pmem_read(13, &MinARecoilPercent);
    pmem_read(17, &StickNoise);
    pmem_read(21, &ARecoil_V);
    pmem_read(25, &ARecoil_H);
    update_anti_recoil();
}
 
main {
    if(!get_actual(BUTTON_8) && get_actual(BUTTON_5))
    {
        set_val(BUTTON_4, 0.0); set_val(BUTTON_7, 0.0);
 
        if(event_active(BUTTON_10))
        {
            combo_run(positive);
 
            sps = sps + 0.5;
 
            if(sps > 25.0) sps = 25.0;
 
            pmem_write(1,sps);
 
            pmem_save();
 
            update_rapidfire();
        }
 
        if(event_active(BUTTON_11))
        {
            combo_run(negative);
 
            sps = sps - 0.5;
 
            if(sps < 1.0) sps = 1.0;
 
            pmem_write(1,sps);
 
            pmem_save();
 
            update_rapidfire();
        }
    }
    if(get_actual(BUTTON_8) && get_actual(BUTTON_5))
    {
        set_val(BUTTON_10, 0.0); set_val(BUTTON_11, 0.0);
 
        set_val(BUTTON_12, 0.0);set_val(BUTTON_13, 0.0);
 
        if(event_active(BUTTON_11))
        {
            combo_run(positive);
 
            ARecoil_V =  ARecoil_V + get_val(STICK_1_Y);
 
            if(ARecoil_V > get_val(STICK_1_Y)) ARecoil_V = get_val(STICK_1_Y);
 
            pmem_write(20,ARecoil_V);
 
            pmem_save();
 
            update_anti_recoil();
        }
 
 
        if(event_active(BUTTON_13))
        {
            combo_run(positive);
 
            ARecoil_H = ARecoil_H + 0.5;
 
            if(ARecoil_H > 100.0) ARecoil_H = 100.0;
 
            pmem_write(24,ARecoil_H);
 
            pmem_save();
 
            update_anti_recoil();
        }
 
        if(event_active(BUTTON_12))
        {
            combo_run(negative);
 
            ARecoil_H = ARecoil_H - 0.5;
 
            if(ARecoil_H < -100.0) ARecoil_H = -100.0;
 
            pmem_write(24,ARecoil_H);
 
            pmem_save();
 
            update_anti_recoil();
        }
    }
    if(!get_actual(BUTTON_8) && get_actual(BUTTON_5))
    {
        set_val(BUTTON_12, 0.0);
 
        if(event_active(BUTTON_12))
        {
            if(rapid_fire == 0)
            {
                rapid_fire = 1;
                combo_run(rapidOn);
 
            }else if(rapid_fire == 1)
            {
                rapid_fire = 0;
            }
 
            pmem_write(0,rapid_fire);
 
            pmem_save();
 
            printf("<center><font style='color:blue;font-size:14px;',><br>RAPID FIRE: %u", rapid_fire);
        }
    }
    if(!get_actual(BUTTON_8) && get_actual(BUTTON_5))
    {
        set_val(BUTTON_13, 0.0);
 
        if(event_active(BUTTON_13))
        {
            if(bUseAntiRecoil == 0)
            {
                bUseAntiRecoil = 1;
                ColorLED('R');
 
            }else if(bUseAntiRecoil == 1)
            {
                bUseAntiRecoil = 0;
                ColorLED('W');
            }
 
            pmem_write(9,bUseAntiRecoil);
 
            pmem_save();
 
            printf("<center><font style='color:red;font-size:14px;',><br>ANTI RECOIL: %d", bUseAntiRecoil);
        }
    }
 
    // - RAPIDFIRE - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    if(get_actual(BUTTON_5)) {
        set_val(BUTTON_5, 100.0);
    if(rapid_fire == 1)
        combo_run(RapidFire);
    }else combo_stop(RapidFire);
 
    if (bUseAntiRecoil)
    {
 
      if (get_actual(BUTTON_5) && time_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 (get_actual(BUTTON_8) && get_actual(BUTTON_5))
        {
          AntiRecoil(STICK_1_X, ARecoil_H);
          AntiRecoil(STICK_1_Y, ARecoil_V);
        }
        else if(is_release(BUTTON_8) && get_actual(BUTTON_5))
        {
          AntiRecoil(STICK_1_X, ARecoil_H);
          AntiRecoil(STICK_1_Y, ARecoil_V - 3.0);
        }
      }
    }
    // - SPRINT MOD - - - - - - - - - - - - - - - - - - - - - - - - - - -
    #define SPRINT_OFF     0
    #define SPRINT_ON      1
    static uint8 sprint;
    if(event_active(BUTTON_16)|| event_active(BUTTON_14)||
        event_active(BUTTON_5)|| event_active(BUTTON_9)||
        is_active(STICK_2_Y) && time_release(STICK_2_Y) < 250)
    {
        sprint = SPRINT_ON;
        goto SPRINT_LIGHTBAR;
    }
    else if(event_active(BUTTON_8)|| event_active(BUTTON_17) ||
        event_active(BUTTON_10) || event_active(BUTTON_13) ||
        event_active(BUTTON_15))
    {
        sprint = SPRINT_OFF;
        goto SPRINT_LIGHTBAR;
 
        if(sprint || !sprint)
        {
            switch(sprint)
            {
                case SPRINT_OFF: sprint = SPRINT_ON;  break;
                case SPRINT_ON:  sprint = SPRINT_OFF; break;
            }
    } else sprint = SPRINT_OFF;
        SPRINT_LIGHTBAR:
        switch(sprint)
        {
            case SPRINT_OFF: display_overlay(_W_, 500); break;
            case SPRINT_ON:  display_overlay(_R_, 500); break;
        }
    }
    if(sprint == SPRINT_ON && event_active(STICK_2_Y)){
        combo_run(easy_sprint);
    }
    if(sprint == SPRINT_OFF){
        set_val(STICK_2_X, get_val(STICK_2_X) / 1.05);
        set_val(STICK_2_Y, get_val(STICK_2_Y) / 1.05);
    }
}
 
combo easy_sprint
{
    set_val(BUTTON_9, 0.0);
    wait(100);
    set_val(BUTTON_9, 100.0);
    wait(100);
    set_val(BUTTON_9, 100.0);
}
 
combo positive
{
    ColorLED('W');
    display_overlay(_P_, 200);
    wait(200);
    ColorLED('B');
}
combo negative
{
    ColorLED('P');
    display_overlay(_N_, 200);
    wait(200);
    ColorLED('B');
}
 
combo rapidOn
{
    ColorLED('R');
    display_overlay(_P_, 200);
    wait(200);
    ColorLED('B');
}
 
combo RapidFire
{
    set_val(BUTTON_5, hold_time ? 100.0 : 0.0);
    wait(hold_time);
    set_val(BUTTON_5, rest_time ? 0.0 : 100.0);
    wait(rest_time);
    set_val(BUTTON_5, rest_time ? 0.0 : 100.0);
}
 
void update_rapidfire() {
    printf("<center><font style='color:blue;font-size:14px;',><br>SHOTS PER SECOND: %.04f", sps);
 
    hold_time = 500.0 / sps;
    rest_time = hold_time - 1.0;
    if(rest_time < 0.0) rest_time = 0.0;   
 
    return;
}
 
void update_anti_recoil(){
    printf("<center><font style='color:red;font-size:14px;',><br>VERTICAL RECOIL COMPENSATION: %.04f", ARecoil_V);
    printf("<center><font style='color:brown;font-size:14px;',><br>HORIZONTAL RECOIL COMPENSATION: %.04f", ARecoil_H);
 
    return;
}
 
void AntiRecoil(uint8 AxisToApply, float ARecoilToApply)
{
    float CurrentX = get_val(STICK_1_X);
    float CurrentY = get_val(STICK_1_Y);
    float MinARecoilFactor = MinARecoilPercent / 100.0;
    float MinARecoilToApply = MinARecoilFactor * ARecoilToApply;
    //This sets the ARecoil to be dependent on both X and Y axis movement. With more emphasis on Y
    float 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));
}
 
 
void ColorLED(char Color)
{
  static char a;
  if (Color != a)
  {
    fix32 Color1, Color2, Color3, Color4;
    if(Color == 'B') Color1 = 100f, Color2 = 0.00, Color3 = 0.00, Color4 = 0.00;
    if(Color == 'R') Color1 = 0.00, Color2 = 100f, Color3 = 0.00, Color4 = 0.00;
    if(Color == 'G') Color1 = 0.00, Color2 = 0.00, Color3 = 100f, Color4 = 0.00;
    if(Color == 'P') Color1 = 0.00, Color2 = 0.00, Color3 = 0.00, Color4 = 100f;
    if(Color == 'C') Color1 = 100f, Color2 = 0.00, Color3 = 100f, Color4 = 0.00;
    if(Color == 'A') Color1 = 0.00, Color2 = 100f, Color3 = 100f, Color4 = 0.00;
    if(Color == 'W') Color1 = 100f, Color2 = 100f, Color3 = 100f, Color4 = 100f;
    led_set(LED_1, Color1, 0), led_set(LED_2, Color2, 0);
    led_set(LED_3, Color3, 0), led_set(LED_4, Color4, 0);
    a = Color;
  }
  return;
}
 
 
 

Ok just made it with vertical compensation... Put this in slot click slot number does a quick save and run on interactive configurations. Which anti-recoil is on.... Hold ads trigger and fire holding recoil down manually with stick then when you feel level with recoil click d-pad down and release fire trigger which saves the anti recoil numbers then just fire to see if you like where it is set!
bonefisher
Lieutenant General
Lieutenant General
 
Posts: 5413
Joined: Thu Jan 29, 2015 10:49 am

Re: Auto Anti-Recoil Compensation

Postby USER101 » Mon Apr 01, 2019 4:58 am

Thank you! I will give this a shot. Since we can record macros is it possible to convert a macro to gpc on the fly?


bonefisher wrote:
Code: Select all
 
#pragma METAINFO("AUto adjust recoil", 1, 0, "bonefisher")
 
/* *****************************************************************************
<cfgdesc>
[QuickAdjust]
color          = #008000
shortdesc      = <font color="green">Runtime operations for manual overrides. Use Interactive Configurations for changes don't forget to Save and Run. </font> <br /><br /> <b><u><font color="brown">Runtime Operations</font></b></u> <br /><br /><font color="green">Hold</font><font color="brown">[FIRE BUTTON] <font color="green">and press <font color="brown">[D-PAD LEFT]<font color="green"> to turn rapid fire toggle ON/OFF(red led flash will be ON and blue led OFF).<br /><br /><font color="green">Hold</font><font color="brown">[FIRE BUTTON] <font color="green">and press <font color="brown">[D-PAD RIGHT]<font color="green"> to turn anti-recoil toggle ON/OFF(red led flash will be ON and blue led OFF).<br /><br /><font color="green">Hold</font><font color="brown">[FIRE BUTTON] <font color="green">and press <font color="brown">[D-PAD UP]<font color="green"> to adjust sps setting + .5 at a time.<br /><br /><font color="green">Hold</font><font color="brown">[FIRE BUTTON] <font color="green">and press <font color="brown">[D-PAD DOWN]<font color="green"> to adjust sps setting - .5 at a time.<br /><br /><font color="green">Hold</font><font color="brown">[ADS BUTTON] <font color="green">and Hold <font color="brown">[FIRE BUTTON] <font color="green">then adjust with<font color="brown">[D-PAD DIRECTION] <font color="green">to pull compensation force where is needed for anti-recoil. Adjusts .5 per d-pad press. Shows on output panel GtunerIV.</font>
control        = info
 
[RAPID FIRE OPTION:]
color          = #008000
collapsible    = 2
shortdesc      = <font color="brown">ENABLE:<font color="green">Rapid Fire?</font>
byteoffset     = 0
bitsize        = 8
control        = radiobox
default        = 0
item           = Rapidfire OFF
item           = Rapidfire ON
 
[RAPID FIRE SETTINGS:]
group          = true
shortdesc      = <font color="brown">SHOTS PER SECOND:</font> <font color="green">   Set to desired sps setting 1~25 sps.</font>
byteoffset     = 1
bitsize        = 32
control        = spinboxf
default        = 165
minimum        = 10
maximum        = 250
step           = 05
decimals       = 1
 
[ANTI RECOIL SETTINGS:]
color          = #008000
collapsible    = 2
shortdesc      = <font color="brown">ENABLE:<font color="green"> Anti Recoil?
byteoffset     = 10
bitsize        = 1
bitoffset      = 7
control        = checkbox
default        = 1
item           = Anti Recoil ON
 
[Anti Recoil Delay]
group          = true
shortdesc      = <font color="brown">Anti Recoil Delay:<font color="green"> (In MS) after fire button is pressed.
byteoffset     = 11
bitsize        = 16
control        = slider
default        = 0
minimum        = 0
maximum        = 1000
step           = 5
 
[Min Anti Recoil Percent]
group          = true
shortdesc      = <font color="brown">Minimum Percentage:<font color="green"> Anti Recoil to apply during aim stick movement.
byteoffset     = 13
bitsize        = 32
control        = spinboxf
default        = 200
minimum        = 0
maximum        = 1000
step           = 10
decimals       = 1
 
[Stick Noise Remover]
group          = true
shortdesc      = <font color="brown">STICK NOISE:<font color="green"> Set to the resting dead zone values for your right stick.
byteoffset     = 17
bitsize        = 32
control        = spinboxf
default        = 800
minimum        = 0
maximum        = 10000
step           = 50
decimals       = 2
 
[Standing Anti Recoil Settings]
group          = true
shortdesc      = <font color="brown">Anti Recoil:<font color="green"> vertical pull force compensation.
byteoffset     = 21
bitsize        = 32
control        = spinboxf
default        = 1800
minimum        = -10000
maximum        = 10000
step           = 10
decimals       = 2
 
[Standing Anti Recoil H Settings]
group          = true
shortdesc      = <font color="brown">Anti Recoil:<font color="green"> horizontal pull force compensation.
byteoffset     = 25
bitsize        = 32
control        = spinboxf
default        = 00000
minimum        = -10000
maximum        = 10000
step           = 10
decimals       = 2
 
</cfgdesc>
***************************************************************************** */

#include <display.gph>
#define wait(a)  wait((int)a);
#define float  fix32
 
uint8 rapid_fire;
fix32 sps;
fix32 hold_time, rest_time;
uint8 bUseAntiRecoil;
float ARecoil_H;
float ARecoil_V;
uint16 ARecoilDelay;
float MinARecoilPercent;
float StickNoise;
 
init
{
    pmem_load();
    rapid_fire = pmem_read(0);
    pmem_read(1, &sps);
    printf("<center><font style='color:blue;font-size:14px;',><br>RAPID FIRE: %u", rapid_fire);
    update_rapidfire();
 
    bUseAntiRecoil = (pmem_read(10) >> 7) & 0b1;
    printf("<center><font style='color:red;font-size:14px;',><br>ANTI RECOIL: %d", bUseAntiRecoil);
    pmem_read(11, &ARecoilDelay);
    pmem_read(13, &MinARecoilPercent);
    pmem_read(17, &StickNoise);
    pmem_read(21, &ARecoil_V);
    pmem_read(25, &ARecoil_H);
    update_anti_recoil();
}
 
main {
    if(!get_actual(BUTTON_8) && get_actual(BUTTON_5))
    {
        set_val(BUTTON_4, 0.0); set_val(BUTTON_7, 0.0);
 
        if(event_active(BUTTON_10))
        {
            combo_run(positive);
 
            sps = sps + 0.5;
 
            if(sps > 25.0) sps = 25.0;
 
            pmem_write(1,sps);
 
            pmem_save();
 
            update_rapidfire();
        }
 
        if(event_active(BUTTON_11))
        {
            combo_run(negative);
 
            sps = sps - 0.5;
 
            if(sps < 1.0) sps = 1.0;
 
            pmem_write(1,sps);
 
            pmem_save();
 
            update_rapidfire();
        }
    }
    if(get_actual(BUTTON_8) && get_actual(BUTTON_5))
    {
        set_val(BUTTON_10, 0.0); set_val(BUTTON_11, 0.0);
 
        set_val(BUTTON_12, 0.0);set_val(BUTTON_13, 0.0);
 
        if(event_active(BUTTON_11))
        {
            combo_run(positive);
 
            ARecoil_V =  ARecoil_V + get_val(STICK_1_Y);
 
            if(ARecoil_V > get_val(STICK_1_Y)) ARecoil_V = get_val(STICK_1_Y);
 
            pmem_write(20,ARecoil_V);
 
            pmem_save();
 
            update_anti_recoil();
        }
 
 
        if(event_active(BUTTON_13))
        {
            combo_run(positive);
 
            ARecoil_H = ARecoil_H + 0.5;
 
            if(ARecoil_H > 100.0) ARecoil_H = 100.0;
 
            pmem_write(24,ARecoil_H);
 
            pmem_save();
 
            update_anti_recoil();
        }
 
        if(event_active(BUTTON_12))
        {
            combo_run(negative);
 
            ARecoil_H = ARecoil_H - 0.5;
 
            if(ARecoil_H < -100.0) ARecoil_H = -100.0;
 
            pmem_write(24,ARecoil_H);
 
            pmem_save();
 
            update_anti_recoil();
        }
    }
    if(!get_actual(BUTTON_8) && get_actual(BUTTON_5))
    {
        set_val(BUTTON_12, 0.0);
 
        if(event_active(BUTTON_12))
        {
            if(rapid_fire == 0)
            {
                rapid_fire = 1;
                combo_run(rapidOn);
 
            }else if(rapid_fire == 1)
            {
                rapid_fire = 0;
            }
 
            pmem_write(0,rapid_fire);
 
            pmem_save();
 
            printf("<center><font style='color:blue;font-size:14px;',><br>RAPID FIRE: %u", rapid_fire);
        }
    }
    if(!get_actual(BUTTON_8) && get_actual(BUTTON_5))
    {
        set_val(BUTTON_13, 0.0);
 
        if(event_active(BUTTON_13))
        {
            if(bUseAntiRecoil == 0)
            {
                bUseAntiRecoil = 1;
                ColorLED('R');
 
            }else if(bUseAntiRecoil == 1)
            {
                bUseAntiRecoil = 0;
                ColorLED('W');
            }
 
            pmem_write(9,bUseAntiRecoil);
 
            pmem_save();
 
            printf("<center><font style='color:red;font-size:14px;',><br>ANTI RECOIL: %d", bUseAntiRecoil);
        }
    }
 
    // - RAPIDFIRE - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    if(get_actual(BUTTON_5)) {
        set_val(BUTTON_5, 100.0);
    if(rapid_fire == 1)
        combo_run(RapidFire);
    }else combo_stop(RapidFire);
 
    if (bUseAntiRecoil)
    {
 
      if (get_actual(BUTTON_5) && time_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 (get_actual(BUTTON_8) && get_actual(BUTTON_5))
        {
          AntiRecoil(STICK_1_X, ARecoil_H);
          AntiRecoil(STICK_1_Y, ARecoil_V);
        }
        else if(is_release(BUTTON_8) && get_actual(BUTTON_5))
        {
          AntiRecoil(STICK_1_X, ARecoil_H);
          AntiRecoil(STICK_1_Y, ARecoil_V - 3.0);
        }
      }
    }
    // - SPRINT MOD - - - - - - - - - - - - - - - - - - - - - - - - - - -
    #define SPRINT_OFF     0
    #define SPRINT_ON      1
    static uint8 sprint;
    if(event_active(BUTTON_16)|| event_active(BUTTON_14)||
        event_active(BUTTON_5)|| event_active(BUTTON_9)||
        is_active(STICK_2_Y) && time_release(STICK_2_Y) < 250)
    {
        sprint = SPRINT_ON;
        goto SPRINT_LIGHTBAR;
    }
    else if(event_active(BUTTON_8)|| event_active(BUTTON_17) ||
        event_active(BUTTON_10) || event_active(BUTTON_13) ||
        event_active(BUTTON_15))
    {
        sprint = SPRINT_OFF;
        goto SPRINT_LIGHTBAR;
 
        if(sprint || !sprint)
        {
            switch(sprint)
            {
                case SPRINT_OFF: sprint = SPRINT_ON;  break;
                case SPRINT_ON:  sprint = SPRINT_OFF; break;
            }
    } else sprint = SPRINT_OFF;
        SPRINT_LIGHTBAR:
        switch(sprint)
        {
            case SPRINT_OFF: display_overlay(_W_, 500); break;
            case SPRINT_ON:  display_overlay(_R_, 500); break;
        }
    }
    if(sprint == SPRINT_ON && event_active(STICK_2_Y)){
        combo_run(easy_sprint);
    }
    if(sprint == SPRINT_OFF){
        set_val(STICK_2_X, get_val(STICK_2_X) / 1.05);
        set_val(STICK_2_Y, get_val(STICK_2_Y) / 1.05);
    }
}
 
combo easy_sprint
{
    set_val(BUTTON_9, 0.0);
    wait(100);
    set_val(BUTTON_9, 100.0);
    wait(100);
    set_val(BUTTON_9, 100.0);
}
 
combo positive
{
    ColorLED('W');
    display_overlay(_P_, 200);
    wait(200);
    ColorLED('B');
}
combo negative
{
    ColorLED('P');
    display_overlay(_N_, 200);
    wait(200);
    ColorLED('B');
}
 
combo rapidOn
{
    ColorLED('R');
    display_overlay(_P_, 200);
    wait(200);
    ColorLED('B');
}
 
combo RapidFire
{
    set_val(BUTTON_5, hold_time ? 100.0 : 0.0);
    wait(hold_time);
    set_val(BUTTON_5, rest_time ? 0.0 : 100.0);
    wait(rest_time);
    set_val(BUTTON_5, rest_time ? 0.0 : 100.0);
}
 
void update_rapidfire() {
    printf("<center><font style='color:blue;font-size:14px;',><br>SHOTS PER SECOND: %.04f", sps);
 
    hold_time = 500.0 / sps;
    rest_time = hold_time - 1.0;
    if(rest_time < 0.0) rest_time = 0.0;   
 
    return;
}
 
void update_anti_recoil(){
    printf("<center><font style='color:red;font-size:14px;',><br>VERTICAL RECOIL COMPENSATION: %.04f", ARecoil_V);
    printf("<center><font style='color:brown;font-size:14px;',><br>HORIZONTAL RECOIL COMPENSATION: %.04f", ARecoil_H);
 
    return;
}
 
void AntiRecoil(uint8 AxisToApply, float ARecoilToApply)
{
    float CurrentX = get_val(STICK_1_X);
    float CurrentY = get_val(STICK_1_Y);
    float MinARecoilFactor = MinARecoilPercent / 100.0;
    float MinARecoilToApply = MinARecoilFactor * ARecoilToApply;
    //This sets the ARecoil to be dependent on both X and Y axis movement. With more emphasis on Y
    float 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));
}
 
 
void ColorLED(char Color)
{
  static char a;
  if (Color != a)
  {
    fix32 Color1, Color2, Color3, Color4;
    if(Color == 'B') Color1 = 100f, Color2 = 0.00, Color3 = 0.00, Color4 = 0.00;
    if(Color == 'R') Color1 = 0.00, Color2 = 100f, Color3 = 0.00, Color4 = 0.00;
    if(Color == 'G') Color1 = 0.00, Color2 = 0.00, Color3 = 100f, Color4 = 0.00;
    if(Color == 'P') Color1 = 0.00, Color2 = 0.00, Color3 = 0.00, Color4 = 100f;
    if(Color == 'C') Color1 = 100f, Color2 = 0.00, Color3 = 100f, Color4 = 0.00;
    if(Color == 'A') Color1 = 0.00, Color2 = 100f, Color3 = 100f, Color4 = 0.00;
    if(Color == 'W') Color1 = 100f, Color2 = 100f, Color3 = 100f, Color4 = 100f;
    led_set(LED_1, Color1, 0), led_set(LED_2, Color2, 0);
    led_set(LED_3, Color3, 0), led_set(LED_4, Color4, 0);
    a = Color;
  }
  return;
}
 
 
 

Ok just made it with vertical compensation... Put this in slot click slot number does a quick save and run on interactive configurations. Which anti-recoil is on.... Hold ads trigger and fire holding recoil down manually with stick then when you feel level with recoil click d-pad down and release fire trigger which saves the anti recoil numbers then just fire to see if you like where it is set!
User avatar
USER101
Sergeant Major
Sergeant Major
 
Posts: 100
Joined: Mon Dec 03, 2018 5:45 pm

Re: Auto Anti-Recoil Compensation

Postby bonefisher » Mon Apr 01, 2019 5:11 am

You can convert a macro to gpc. but on the fly no! Now you can record then do play back but you won't have control of it like this anti-recoil!
bonefisher
Lieutenant General
Lieutenant General
 
Posts: 5413
Joined: Thu Jan 29, 2015 10:49 am

Re: Auto Anti-Recoil Compensation

Postby Jalal » Tue Apr 02, 2019 8:27 am

how do i do this with mouse and keyboard on call of duty ?
:innocent_smile_1:
User avatar
Jalal
Sergeant Major
Sergeant Major
 
Posts: 73
Joined: Wed Apr 26, 2017 7:42 am

Re: Auto Anti-Recoil Compensation

Postby USER101 » Mon Apr 15, 2019 9:13 pm

I have had time to give this some more thought. Here is what I came up with I just need someone to help fill the gaps. I don't really know if I can get this to work but I feel so under the weather today that I cant think straight. This is supposed to auto correct your anti recoil after you fire your weapon for the first time (while aiming at a single point). I am thinking I can add something like this to my blackout weapon swap function in the event you have two weapons. The comments are what the methods are supposed to do. Any assistance is appreciated. Here I am just trying to get the modified variable, I am not applying it to the output yet. I guess I should add a printf in there somewhere...

Here is my untested code:

Code: Select all
//May need to float all these vars because of the STICK_1_Y input value
uint8 RecoilModifier[50];
uint8 StickValue;
uint8 Modifier;
uint8 ModifierSum;
 
uint16 timer = 0;
 
fix32 AntiRecoilVertical;
fix32 AntiRecoilVerticalOld;
init{
    pmem_load();
    pmem_read(0, &AntiRecoilVertical);
    AntiRecoilVerticalOld = AntiRecoilVertical;
}
 
main {
    if(is_active(BUTTON_5)){
 
        timer += elapsed_time(); //Add timer       
 
        if(timer == 100){ //Every 100ms increment RecoilModifier and store current STICK_1_Y value in new Modifier
            Modifier++;
            if(Modifier > 50) Modifier = 0;
            RecoilModifier[Modifier] = get_val(STICK_1_Y);
            timer = 0;
        }
    }
    if(event_release(BUTTON_5)){
        uint8 i;
        for(i=0;i<=50;i++){ //Sum all the values of the RecoilModifier array
        Modifier = Modifier + RecoilModifier[i];
        }
 
        //If ModifierSum does not exceed 30% of current AntiRecoilVertical, AntiRecoilVertical = AntiRecoilVertical + ModifierSum
        if(Modifier !> AntiRecoilVertical * .3) AntiRecoilVertical = AntiRecoilVertical + Modifier;
 
        if (AntiRecoilVerticalOld != AntiRecoilVertical) {//Save changes to AntiRecoilVertical
            set_pvar(0, AntiRecoilVertical);
            AntiRecoilVerticalOld = AntiRecoilVertical;
        }
        //reset timer and all temporary vars
        timer = 0;
        Modifier = 0;
    }
}
User avatar
USER101
Sergeant Major
Sergeant Major
 
Posts: 100
Joined: Mon Dec 03, 2018 5:45 pm

Re: Auto Anti-Recoil Compensation

Postby bonefisher » Mon Apr 15, 2019 9:33 pm

You might want to look into my new self loading anti recoil that I posted! Don't think this will work to well for you!
bonefisher
Lieutenant General
Lieutenant General
 
Posts: 5413
Joined: Thu Jan 29, 2015 10:49 am

Re: Auto Anti-Recoil Compensation

Postby USER101 » Mon Apr 15, 2019 10:10 pm

bonefisher wrote:You might want to look into my new self loading anti recoil that I posted! Don't think this will work to well for you!

I did see your code its great! This is just a concept for an alternate method that should not rely on FFB. I am hoping to get it working, for the sake of development why do you think this will not work? Do you think the concept is not possible or just that the code in its current state would not work?
User avatar
USER101
Sergeant Major
Sergeant Major
 
Posts: 100
Joined: Mon Dec 03, 2018 5:45 pm

Next

Return to GPC2 Script Programming

Who is online

Users browsing this forum: Majestic-12 [Bot] and 76 guests