Xim4 + T2 recoil issue?

Forum to discuss the scripts, configs and connection of XIM with the Titan devices.

Moderator: antithesis

Re: Xim4 + T2 recoil issue?

Postby MAC » Wed Apr 18, 2018 6:24 pm

What's the code to executie anti recoil with <L2> PS4
User avatar
MAC
Master Sergeant
Master Sergeant
 
Posts: 39
Joined: Fri Apr 13, 2018 7:13 pm

Re: Xim4 + T2 recoil issue?

Postby antithesis » Wed Apr 18, 2018 11:14 pm

It's already set to L2. Refer to previous page for updated recoil code.
Official Australian retailer for Titan One, Titan Two and XIM APEX at Mod Squad
User avatar
antithesis
Colonel
Colonel
 
Posts: 1912
Joined: Sat May 28, 2016 10:45 pm

Re: Xim4 + T2 recoil issue?

Postby mpalpha » Wed Jul 11, 2018 2:10 am

antithesis wrote:That anti-recoil code is the same, however it looks like you're plugging the T2 into the Apex rather than the other way around, hence the mouse and keyboard passthrough to get it working.

Note also that the Apex has a random resting stick position that is messing with the anti-recoil code. I've update the code in the Gtuner > Online Resources section to account for that. Here's the script for your convenience -

Code: Select all
 
#pragma METAINFO("antithesis Antirecoil", 1, 01, "antithesis")
 
fix32 RECOIL_V = 30.0;
fix32 RECOIL_H = 0.0;
fix32 RY;
fix32 RX;
 
fix32 StickNoise = 4.32;
 
main {
 
 
// DEADZONE REMOVER
    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); }
 
// ANTI-RECOIL
    if (get_val (BUTTON_5))
    {   
        AntiRecoil(STICK_1_Y,RECOIL_V);
        AntiRecoil(STICK_1_X,RECOIL_H);
    }
 
}
 
void AntiRecoil (uint8 axis, fix32 recoil)
{
 
     RY = get_actual(STICK_1_Y);
     RX = get_actual(STICK_1_X);
 
    if (get_val(BUTTON_5) && (sqrt(RX*RX + RY*RY)) <= abs(recoil))
    {
        if(abs(RY) <= abs(recoil))
        {
            set_val(axis,(recoil * (100.0 - abs(get_val(axis)))) / 100.0 + get_val(axis));
        }
    }
}
 
 



do you have a version of this script with persistent variables so you can tune the recoil h/v in game, and save the values?
User avatar
mpalpha
Staff Sergeant
Staff Sergeant
 
Posts: 11
Joined: Mon Jun 11, 2018 11:02 pm

Re: Xim4 + T2 recoil issue?

Postby mpalpha » Fri Jul 13, 2018 10:09 pm

this is where I'm at so far

in game adjustments: done :smile0517:
auto save after adjustments: done :smile0517:
interactive config: done :smile0517:
recoil Y: done :smile0517:
recoil X: done :smile0517:
toggle ads: 95% :thumbsdownsmileyanim:

trying to the boolean to work with the interactive config and pmem.

Code: Select all
#pragma METAINFO("ANTIRECOIL (V+H), adjust on the fly, interactive config", 1, 00, "ETB")
 
// Frist of all, thanks to Layman, Scachi, and Antithesis
 
// Anti Recoil
// Hold Both Triggers & Press DPAD UP, DOWN, LEFT, RIGHT to adjust.
fix32 RECOIL_V           = 30.0; // Vertical Recoil  range -100.0 to 100.0
fix32 RECOIL_H           = 0.0; // Horizontal Recoil  range -100.0 to 100.0
fix32 RY; // reserved
fix32 RX; // reserved
 
// ADS Toggle
// Hold Both Triggers & Press Right Stick
bool TOGGLE_ADS          = TRUE; // Toggle ADS Default
 
fix32 StickNoise         = 4.32; // Change this value to adjust the size of the Deadzone to ignore when using a Xim Apex.
// Go to Device Monitor in Gtuner IV, flick the right stick and take note of the largest value.
 
bool ICUpdate            = FALSE; // To update the interactive configuration window set this flag to TRUE in the main loop.
bool PMUpdate            = FALSE; // To save/write down the value to pmem set this flag to TRUE in the main loop.
 
// assign pmem locations (remember to match interactive config byteoffsets)
uint8 StickNoise_PMEM    = 0; // pmem slot
uint8 RECOIL_V_PMEM      = 4; // pmem slot
uint8 RECOIL_H_PMEM      = 8; // pmem slot
uint8 TOGGLE_ADS_PMEM    = 12; // pmem slot
 
init {
    pmem_load(); // load the ui pmem
    pmem_read(StickNoise_PMEM, &StickNoise); // read the value to change from the ui
    pmem_read(RECOIL_V_PMEM, &RECOIL_V); // read the value to change from the ui
    pmem_read(RECOIL_H_PMEM, &RECOIL_H); // read the value to change from the ui
    pmem_read(TOGGLE_ADS_PMEM, &TOGGLE_ADS); // read the value to change from the ui
    StickNoise = clamp(StickNoise,0.0,255.0); // just to make sure the value is in the correct value range
    RECOIL_V = clamp(RECOIL_V,-100.0,100.0); // just to make sure the value is in the correct value range
    RECOIL_H = clamp(RECOIL_H,-100.0,100.0); // just to make sure the value is in the correct value range
}
 
main {
    if ( event_active(BUTTON_10) && is_active(BUTTON_5) && is_active(BUTTON_8) ) { // Hold Both Triggers & Press DPAD_UP
        if ( RECOIL_V > -100.0) {
            (RECOIL_V = RECOIL_V - 1.0);
        }
        pmem_write(RECOIL_V_PMEM,(fix32) RECOIL_V); // update the pmem value
        PMUpdate=TRUE; // let the value be saved to pmem
        ICUpdate=TRUE; // show the updated value in the gui without needing to close and reopen it
    }
 
    if ( event_active(BUTTON_11) && is_active(BUTTON_5) && is_active(BUTTON_8) ) { // Hold Both Triggers & Press DPAD_DOWN
        if ( RECOIL_V < 100.0) {
            (RECOIL_V = RECOIL_V + 1.0);
        }
        pmem_write(RECOIL_V_PMEM,(fix32) RECOIL_V); // update the pmem value
        PMUpdate=TRUE; // let the value be saved to pmem
        ICUpdate=TRUE; // show the updated value in the gui without needing to close and reopen it
    }
    if ( event_active(BUTTON_12) && is_active(BUTTON_5) && is_active(BUTTON_8) ) { // Hold Both Triggers & Press DPAD_LEFT
        if ( RECOIL_H > -100.0) {
            (RECOIL_H = RECOIL_H - 1.0);
        }
        pmem_write(RECOIL_H_PMEM,(fix32) RECOIL_H); // update the pmem value
        PMUpdate=TRUE; // let the value be saved to pmem
        ICUpdate=TRUE; // show the updated value in the gui without needing to close and reopen it
    }
 
    if ( event_active(BUTTON_13) && is_active(BUTTON_5) && is_active(BUTTON_8) ) { // Hold Both Triggers & Press DPAD_RIGHT
        if ( RECOIL_H < 100.0) {
            (RECOIL_H = RECOIL_H + 1.0);
        }
        pmem_write(RECOIL_H_PMEM,(fix32) RECOIL_H); // update the pmem value
        PMUpdate=TRUE; // let the value be saved to pmem
        ICUpdate=TRUE; // show the updated value in the gui without needing to close and reopen it
    }
 
    if ( event_active(BUTTON_6) && is_active(BUTTON_5) && is_active(BUTTON_8) ) { // Hold Both Triggers & Press Right Stick
        (TOGGLE_ADS = !TOGGLE_ADS);
        pmem_write(TOGGLE_ADS_PMEM,(uint8) TOGGLE_ADS); // update the pmem value
        PMUpdate=TRUE; // let the value be saved to pmem
        ICUpdate=TRUE; // show the updated value in the gui without needing to close and reopen it
    }
 
    ICRefresh();    // This functions should be called on every iteration
        PMSave();         // This functions should be called on every iteration
 
// DEADZONE REMOVER
    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); }
 
// ANTI-RECOIL
    if (!TOGGLE_ADS || get_val (BUTTON_5))
    {
        AntiRecoil(STICK_1_Y,RECOIL_V);
        AntiRecoil(STICK_1_X,RECOIL_H);
    }
}
 
// update the UI, limit the update time to 1000ms (1 second) for safety
void ICRefresh() {
    static uint32 ICULast = 0;
    if (ICUpdate && ICULast < system_time())
    {
        printf("ic update");
        printf("GCMD:InteractiveConfiguration.Refresh");
        ICUpdate = FALSE;
        ICULast = system_time() + 1000;
    }
}
 
// Update the persistent memory, but not faster than 500ms (1/2 second)
void PMSave() {
    static uint32 PMSLast = 0;
    if (PMUpdate && PMSLast < system_time())
    {
        printf("pmem saved: StickNoise: %f",StickNoise);
        printf("pmem saved: RECOIL_V: %f",RECOIL_V);
        printf("pmem saved: RECOIL_H: %f",RECOIL_H);
        printf("pmem saved: TOGGLE_ADS: %f",TOGGLE_ADS);
        PMUpdate = FALSE;
        PMSLast = system_time() + 500;
        pmem_save();
    }
}
 
void AntiRecoil (uint8 axis, fix32 recoil)
{
     RY = get_actual(STICK_1_Y);
     RX = get_actual(STICK_1_X);
 
    if (get_val(BUTTON_5) && (sqrt(RX*RX + RY*RY)) <= abs(recoil))
    {
        if(abs(RY) <= abs(recoil))
        {
            set_val(axis,(recoil * (100.0 - abs(get_val(axis)))) / 100.0 + get_val(axis));
        }
    }
}
 
/***************
<cfgdesc>
[Example]
shortdesc       = <<<MULTILINE
UI updateexample
with automatic UI refresh
MULTILINE
control         = info
 
[Sticknoise]
shortdesc       = <<<MULTILINE
The default value 4.32 should be a good start.
If you want to tweak this, set it to the max value of your sticks resting position values.
Use the "Device Monitor" to examine them.
MULTILINE
byteoffset      = 0
bitsize         = 32
control         = spinboxf
default         = 432
minimum         = 0
maximum         = 2000
step            = 1
decimals        = 2
 
[Anti Recoil Vertical]
shortdesc       = Vertical recoil compensation
byteoffset      = 4
bitsize         = 32
control         = spinboxf
default         = 300
minimum         = -1000
maximum         = 1000
step            = 1
decimals        = 1
 
[Anti Recoil Horizontal]
shortdesc       = Horizontal recoil compensation
byteoffset      = 8
bitsize         = 32
control         = spinboxf
default         = 0
minimum         = -1000
maximum         = 1000
step            = 1
decimals        = 1
 
[Toggle ADS]
shortdesc       = Enable this if you would like Anti Recoil enabled while aiming down sight or during hip fire.
byteoffset      = 12
bitsize         = 1
bitoffset       = 1
control         = checkbox
default         = 1
item            = Enable
 
</cfgdesc>
 
***************/

 
User avatar
mpalpha
Staff Sergeant
Staff Sergeant
 
Posts: 11
Joined: Mon Jun 11, 2018 11:02 pm

Re: Xim4 + T2 recoil issue?

Postby J2Kbr » Sun Jul 15, 2018 11:13 am

Please check if the changes made below fixes the issue with the TOGGLE_ADS.

Code: Select all
#pragma METAINFO("ANTIRECOIL (V+H), adjust on the fly, interactive config", 1, 00, "ETB")
 
// Frist of all, thanks to Layman, Scachi, and Antithesis
 
// Anti Recoil
// Hold Both Triggers & Press DPAD UP, DOWN, LEFT, RIGHT to adjust.
fix32 RECOIL_V           = 30.0; // Vertical Recoil  range -100.0 to 100.0
fix32 RECOIL_H           = 0.0; // Horizontal Recoil  range -100.0 to 100.0
fix32 RY; // reserved
fix32 RX; // reserved
 
// ADS Toggle
// Hold Both Triggers & Press Right Stick
uint8 TOGGLE_ADS         = TRUE; // Toggle ADS Default
 
fix32 StickNoise         = 4.32; // Change this value to adjust the size of the Deadzone to ignore when using a Xim Apex.
// Go to Device Monitor in Gtuner IV, flick the right stick and take note of the largest value.
 
bool ICUpdate            = FALSE; // To update the interactive configuration window set this flag to TRUE in the main loop.
bool PMUpdate            = FALSE; // To save/write down the value to pmem set this flag to TRUE in the main loop.
 
// assign pmem locations (remember to match interactive config byteoffsets)
uint8 StickNoise_PMEM    = 0; // pmem slot
uint8 RECOIL_V_PMEM      = 4; // pmem slot
uint8 RECOIL_H_PMEM      = 8; // pmem slot
uint8 TOGGLE_ADS_PMEM    = 12; // pmem slot
 
init {
    pmem_load(); // load the ui pmem
    pmem_read(StickNoise_PMEM, &StickNoise); // read the value to change from the ui
    pmem_read(RECOIL_V_PMEM, &RECOIL_V); // read the value to change from the ui
    pmem_read(RECOIL_H_PMEM, &RECOIL_H); // read the value to change from the ui
    pmem_read(TOGGLE_ADS_PMEM, &TOGGLE_ADS); // read the value to change from the ui
    StickNoise = clamp(StickNoise,0.0,255.0); // just to make sure the value is in the correct value range
    RECOIL_V = clamp(RECOIL_V,-100.0,100.0); // just to make sure the value is in the correct value range
    RECOIL_H = clamp(RECOIL_H,-100.0,100.0); // just to make sure the value is in the correct value range
}
 
main {
    if ( event_active(BUTTON_10) && is_active(BUTTON_5) && is_active(BUTTON_8) ) { // Hold Both Triggers & Press DPAD_UP
        if ( RECOIL_V > -100.0) {
            (RECOIL_V = RECOIL_V - 1.0);
        }
        pmem_write(RECOIL_V_PMEM,(fix32) RECOIL_V); // update the pmem value
        PMUpdate=TRUE; // let the value be saved to pmem
        ICUpdate=TRUE; // show the updated value in the gui without needing to close and reopen it
    }
 
    if ( event_active(BUTTON_11) && is_active(BUTTON_5) && is_active(BUTTON_8) ) { // Hold Both Triggers & Press DPAD_DOWN
        if ( RECOIL_V < 100.0) {
            (RECOIL_V = RECOIL_V + 1.0);
        }
        pmem_write(RECOIL_V_PMEM,(fix32) RECOIL_V); // update the pmem value
        PMUpdate=TRUE; // let the value be saved to pmem
        ICUpdate=TRUE; // show the updated value in the gui without needing to close and reopen it
    }
    if ( event_active(BUTTON_12) && is_active(BUTTON_5) && is_active(BUTTON_8) ) { // Hold Both Triggers & Press DPAD_LEFT
        if ( RECOIL_H > -100.0) {
            (RECOIL_H = RECOIL_H - 1.0);
        }
        pmem_write(RECOIL_H_PMEM,(fix32) RECOIL_H); // update the pmem value
        PMUpdate=TRUE; // let the value be saved to pmem
        ICUpdate=TRUE; // show the updated value in the gui without needing to close and reopen it
    }
 
    if ( event_active(BUTTON_13) && is_active(BUTTON_5) && is_active(BUTTON_8) ) { // Hold Both Triggers & Press DPAD_RIGHT
        if ( RECOIL_H < 100.0) {
            (RECOIL_H = RECOIL_H + 1.0);
        }
        pmem_write(RECOIL_H_PMEM,(fix32) RECOIL_H); // update the pmem value
        PMUpdate=TRUE; // let the value be saved to pmem
        ICUpdate=TRUE; // show the updated value in the gui without needing to close and reopen it
    }
 
    if ( event_active(BUTTON_6) && is_active(BUTTON_5) && is_active(BUTTON_8) ) { // Hold Both Triggers & Press Right Stick
        (TOGGLE_ADS = !TOGGLE_ADS);
        pmem_write(TOGGLE_ADS_PMEM, TOGGLE_ADS); // update the pmem value
        PMUpdate=TRUE; // let the value be saved to pmem
        ICUpdate=TRUE; // show the updated value in the gui without needing to close and reopen it
    }
 
    ICRefresh();    // This functions should be called on every iteration
        PMSave();         // This functions should be called on every iteration
 
// DEADZONE REMOVER
    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); }
 
// ANTI-RECOIL
    if (!TOGGLE_ADS || get_val (BUTTON_5))
    {
        AntiRecoil(STICK_1_Y,RECOIL_V);
        AntiRecoil(STICK_1_X,RECOIL_H);
    }
}
 
// update the UI, limit the update time to 1000ms (1 second) for safety
void ICRefresh() {
    static uint32 ICULast = 0;
    if (ICUpdate && ICULast < system_time())
    {
        printf("ic update");
        printf("GCMD:InteractiveConfiguration.Refresh");
        ICUpdate = FALSE;
        ICULast = system_time() + 1000;
    }
}
 
// Update the persistent memory, but not faster than 500ms (1/2 second)
void PMSave() {
    static uint32 PMSLast = 0;
    if (PMUpdate && PMSLast < system_time())
    {
        printf("pmem saved: StickNoise: %f",StickNoise);
        printf("pmem saved: RECOIL_V: %f",RECOIL_V);
        printf("pmem saved: RECOIL_H: %f",RECOIL_H);
        printf("pmem saved: TOGGLE_ADS: %f",TOGGLE_ADS);
        PMUpdate = FALSE;
        PMSLast = system_time() + 500;
        pmem_save();
    }
}
 
void AntiRecoil (uint8 axis, fix32 recoil)
{
     RY = get_actual(STICK_1_Y);
     RX = get_actual(STICK_1_X);
 
    if (get_val(BUTTON_5) && (sqrt(RX*RX + RY*RY)) <= abs(recoil))
    {
        if(abs(RY) <= abs(recoil))
        {
            set_val(axis,(recoil * (100.0 - abs(get_val(axis)))) / 100.0 + get_val(axis));
        }
    }
}
 
/***************
<cfgdesc>
[Example]
shortdesc       = <<<MULTILINE
UI updateexample
with automatic UI refresh
MULTILINE
control         = info
 
[Sticknoise]
shortdesc       = <<<MULTILINE
The default value 4.32 should be a good start.
If you want to tweak this, set it to the max value of your sticks resting position values.
Use the "Device Monitor" to examine them.
MULTILINE
byteoffset      = 0
bitsize         = 32
control         = spinboxf
default         = 432
minimum         = 0
maximum         = 2000
step            = 1
decimals        = 2
 
[Anti Recoil Vertical]
shortdesc       = Vertical recoil compensation
byteoffset      = 4
bitsize         = 32
control         = spinboxf
default         = 300
minimum         = -1000
maximum         = 1000
step            = 1
decimals        = 1
 
[Anti Recoil Horizontal]
shortdesc       = Horizontal recoil compensation
byteoffset      = 8
bitsize         = 32
control         = spinboxf
default         = 0
minimum         = -1000
maximum         = 1000
step            = 1
decimals        = 1
 
[Toggle ADS]
shortdesc       = Enable this if you would like Anti Recoil enabled while aiming down sight or during hip fire.
byteoffset      = 12
bitsize         = 8
control         = checkbox
default         = 1
item            = Enable
 
</cfgdesc>
 
***************/

 
ConsoleTuner Support Team
User avatar
J2Kbr
General of the Army
General of the Army
 
Posts: 20323
Joined: Tue Mar 18, 2014 1:39 pm

Re: Xim4 + T2 recoil issue?

Postby mpalpha » Sun Jul 15, 2018 3:49 pm

the menu works now, but the value doesn't get read as a boolean, so it is not toggling the ADS requirement.
User avatar
mpalpha
Staff Sergeant
Staff Sergeant
 
Posts: 11
Joined: Mon Jun 11, 2018 11:02 pm

Re: Xim4 + T2 recoil issue?

Postby J2Kbr » Mon Jul 16, 2018 8:11 am

I believe the logic in this line is incorrect:
Code: Select all
if (!TOGGLE_ADS || get_val (BUTTON_5))
Try change to:
Code: Select all
if(get_val(BUTTON_5) && (!TOGGLE_ADS || get_val(BUTTON_8)))
Here we have two conditions to activate the anti-recoil:
(1) if TOGGLE_ADS is false the anti recoil will be activated when the fire button is pressed (HID and ADS); or
(2) if TOGGLE_ADS is true and anti recoil will only be activate when the fire button and ads button are pressed.
ConsoleTuner Support Team
User avatar
J2Kbr
General of the Army
General of the Army
 
Posts: 20323
Joined: Tue Mar 18, 2014 1:39 pm

Re: Xim4 + T2 recoil issue?

Postby mpalpha » Mon Jul 16, 2018 12:03 pm

Thanks, its working now.

Complete Fixed Script
Code: Select all
#pragma METAINFO("ANTIRECOIL, horizontal, vertical, adjust in-game, interactive config, autosave", 1, 02, "ETB")
 
// Frist of all, thanks to RedbeardCrunch, J2Kbr, Layman, Scachi, and Antithesis
 
// Anti Recoil
// Hold Both Triggers & Press DPAD UP, DOWN, LEFT, RIGHT to adjust.
fix32 RECOIL_V           = 30.0;    // Vertical Recoil  range -100.0 to 100.0
fix32 RECOIL_H           = 0.0;     // Horizontal Recoil  range -100.0 to 100.0
fix32 ADJUSTMENT_STEP    = 1.0;     // increment to adjust recoil per interation range 1.0 to 10.0
fix32 RY;                           // reserved
fix32 RX;                           // reserved
 
// ADS Toggle
// Hold Both Triggers & Press Right Stick (button)
uint8 TOGGLE_ADS         = TRUE;    // Toggle ADS Default
 
fix32 STICK_NOISE        = 4.32;    // Change this value to adjust the size of the Deadzone to ignore when using a Xim Apex.
                                    // in Gtuner IV > Device Monitor, flick the right stick and take note of the largest value.
 
bool PMUpdate            = FALSE;   // To save/write down the value to pmem set this flag to TRUE in the main loop.
 
// assign pmem locations (remember to match interactive config byteoffsets)
uint8 STICK_NOISE_PMEM   = 0;       // pmem slot
uint8 RECOIL_V_PMEM      = 4;       // pmem slot
uint8 RECOIL_H_PMEM      = 8;       // pmem slot
uint8 TOGGLE_ADS_PMEM    = 12;      // pmem slot
 
init {
    pmem_load(); // load the ui pmem
    pmem_read(STICK_NOISE_PMEM, &STICK_NOISE); // read the value to change from the ui
    pmem_read(RECOIL_V_PMEM, &RECOIL_V); // read the value to change from the ui
    pmem_read(RECOIL_H_PMEM, &RECOIL_H); // read the value to change from the ui
    pmem_read(TOGGLE_ADS_PMEM, &TOGGLE_ADS); // read the value to change from the ui
    STICK_NOISE = clamp(STICK_NOISE,0.0,255.0); // just to make sure the value is in the correct value range
    RECOIL_V = clamp(RECOIL_V,-100.0,100.0); // just to make sure the value is in the correct value range
    RECOIL_H = clamp(RECOIL_H,-100.0,100.0); // just to make sure the value is in the correct value range
    ADJUSTMENT_STEP = clamp(ADJUSTMENT_STEP,1.0,10.0); // just to make sure the value is in the correct value range
 
    printf("STICK_NOISE: %.04f", STICK_NOISE);
    printf("RECOIL_V: %.04f", RECOIL_V);
    printf("RECOIL_H: %.04f", RECOIL_H);
    printf("ADJUSTMENT_STEP: %.04f", ADJUSTMENT_STEP);
    printf("TOGGLE_ADS: %d", TOGGLE_ADS);
 
    // Light Blue led = ADS enabled, White led = ADS disabled
        set_light(TOGGLE_ADS? 'W': 'S');
}
 
main {
    // adjust anti-recoil
    if (is_active(BUTTON_5) && is_active(BUTTON_8)) { // Hold Both Triggers
        if ( event_active(BUTTON_10) ) { // ...and Press DPAD_UP
            if ( RECOIL_V > -100.0) {
                RECOIL_V = (RECOIL_V - ADJUSTMENT_STEP);
                pmem_write(RECOIL_V_PMEM,(fix32) RECOIL_V); // update the pmem value
                PMUpdate=TRUE; // pmem and gui value throttle
            }
        }
        if ( event_active(BUTTON_11) ) { // ...and Press DPAD_DOWN
            if ( RECOIL_V < 100.0) {
                RECOIL_V = (RECOIL_V + ADJUSTMENT_STEP);
                pmem_write(RECOIL_V_PMEM,(fix32) RECOIL_V); // update the pmem value
                PMUpdate=TRUE; // pmem and gui value throttle
            }
        }
        if ( event_active(BUTTON_12) ) { // ...Press DPAD_LEFT
            if ( RECOIL_H > -100.0) {
                RECOIL_H = (RECOIL_H - ADJUSTMENT_STEP);
                pmem_write(RECOIL_H_PMEM,(fix32) RECOIL_H); // update the pmem value
                PMUpdate=TRUE; // pmem and gui value throttle
            }
        }
        if ( event_active(BUTTON_13) ) { // ...and Press DPAD_RIGHT
            if ( RECOIL_H < 100.0) {
                RECOIL_H = (RECOIL_H + ADJUSTMENT_STEP);
                pmem_write(RECOIL_H_PMEM,(fix32) RECOIL_H); // update the pmem value
                PMUpdate=TRUE; // pmem and gui value throttle
            }
        }
        if ( event_active(BUTTON_6) ) { // ...and Press Right Stick
            TOGGLE_ADS = (!TOGGLE_ADS);
            pmem_write(TOGGLE_ADS_PMEM, TOGGLE_ADS); // toggle and update the pmem value
            PMUpdate=TRUE; // pmem and gui value throttle
        }
    }
    // save values when changed
    if (PMUpdate) {
        PMSave();         // This function should be called on every iteration if changes are detected.
    }
 
    // DEADZONE REMOVER
    if(abs(get_actual(STICK_1_X)) < STICK_NOISE) { set_val(STICK_1_X, 0.0); }
    if(abs(get_actual(STICK_1_Y)) < STICK_NOISE) { set_val(STICK_1_Y, 0.0); }
    if(abs(get_actual(STICK_2_X)) < STICK_NOISE) { set_val(STICK_2_X, 0.0); }
    if(abs(get_actual(STICK_2_Y)) < STICK_NOISE) { set_val(STICK_2_Y, 0.0); }
 
    // ANTI-RECOIL
    if(get_val(BUTTON_5) && (!TOGGLE_ADS || get_val(BUTTON_8)))
    {
        AntiRecoil(STICK_1_Y,RECOIL_V);
        AntiRecoil(STICK_1_X,RECOIL_H);
    }
}
 
// Update the persistent memory, but not faster than 1000ms (1 second)
void PMSave() {
    static uint32 PMSLast = 0;
    if (PMUpdate && PMSLast < system_time())
    {
        printf("STICK_NOISE: %.04f", STICK_NOISE);
        printf("RECOIL_V: %.04f", RECOIL_V);
        printf("RECOIL_H: %.04f", RECOIL_H);
        printf("ADJUSTMENT_STEP: %.04f", ADJUSTMENT_STEP);
        printf("TOGGLE_ADS: %d", TOGGLE_ADS);
        PMUpdate = FALSE;
        printf("ic update");
        printf("GCMD:InteractiveConfiguration.Refresh");
        PMSLast = system_time() + 1000;
        pmem_save();
 
        // Light Blue led = ADS enabled, White led = ADS disabled
        set_light(TOGGLE_ADS? 'W': 'S');
    }
}
 
void AntiRecoil (uint8 axis, fix32 recoil)
{
     RY = get_actual(STICK_1_Y);
     RX = get_actual(STICK_1_X);
 
    if (get_val(BUTTON_5) && (sqrt(RX*RX + RY*RY)) <= abs(recoil))
    {
        if(abs(RY) <= abs(recoil))
        {
            set_val(axis,(recoil * (100.0 - abs(get_val(axis)))) / 100.0 + get_val(axis));
        }
    }
}
 
void set_light(unsigned char new_light) {
  static unsigned char old_light;
  static uint32 timestamp;
  if(new_light != old_light && (system_time() - timestamp > 50)) {
    switch(new_light) {
      timestamp = system_time(), old_light = new_light;
      // PINK LED
      case 'P' :led_set(LED_1, 0.0, 0), led_set(LED_2, 0.0, 0), led_set(LED_3, 0.0, 0),led_set(LED_4, 5.0, 0); return;
      // BLUE LED
      case 'B': led_set(LED_1, 25.0, 0),led_set(LED_2, 0.0, 0), led_set(LED_3, 0.0, 0),led_set(LED_4, 0.0, 0); return;
      // SKY BLUE LED
      case 'S': led_set(LED_1, 50.0, 0),led_set(LED_2, 0.0, 0), led_set(LED_3, 50.0, 0),led_set(LED_4, 0.0, 0); return;
      // RED LED
      case 'R': led_set(LED_1, 0.0, 0),led_set(LED_2, 25.0, 0), led_set(LED_3, 0.0, 0),led_set(LED_4, 0.0, 0); return;
      // WHITE LED
      case 'W': led_set(LED_1, 25.0, 0), led_set(LED_2, 25.0, 0), led_set(LED_3, 25.0, 0), led_set(LED_4, 25.0, 0); return;
      // YELLOW LED
      case 'Y': led_set(LED_1, 0.0, 0),led_set(LED_2, 30.0, 0), led_set(LED_3, 10.0, 0), led_set(LED_4, 0.0, 0); return;
      // GREEN LED
      case 'G': led_set(LED_1, 0.0, 0), led_set(LED_2, 0.0, 0), led_set(LED_3, 25.0, 0), led_set(LED_4, 0.0, 0); return;
      // NO LED
      case 'N':led_set(LED_1, 0.0, 0),led_set(LED_2, 0.0, 0), led_set(LED_3, 0.0, 0), led_set(LED_4, 0.0, 0);
      }
  }
  return;
}
 
/***************
<cfgdesc>
[Universal Anti-Recoil]
shortdesc       = <<<MULTILINE
Horizontal: Hold both triggers + press left or right dpad
Vertical: Hold both triggers + press up or down dpad
Toggle ADS: Hold both triggers + press right stick button
 
Adjust in-game.
Interactive configuration.
Autosave.
MULTILINE
control         = info
 
[Sticknoise]
shortdesc       = <<<MULTILINE
The default value 4.32 should be a good start.
If you want to tweak this, set it to the max value of your sticks resting position values.
Use the "Device Monitor" to examine them.
MULTILINE
byteoffset      = 0
bitsize         = 32
control         = spinboxf
default         = 432
minimum         = 0
maximum         = 2000
step            = 1
decimals        = 2
 
[Anti Recoil Vertical]
shortdesc       = Vertical recoil compensation
byteoffset      = 4
bitsize         = 32
control         = spinboxf
default         = 300
minimum         = -1000
maximum         = 1000
step            = 1
decimals        = 1
 
[Anti Recoil Horizontal]
shortdesc       = Horizontal recoil compensation
byteoffset      = 8
bitsize         = 32
control         = spinboxf
default         = 0
minimum         = -1000
maximum         = 1000
step            = 1
decimals        = 1
 
[Toggle ADS]
shortdesc       = Enable this if you would like Anti Recoil enabled while aiming down sight or during hip fire.
byteoffset      = 12
bitsize         = 8
control         = checkbox
default         = 1
item            = Enable
 
</cfgdesc>
 
***************/

 
User avatar
mpalpha
Staff Sergeant
Staff Sergeant
 
Posts: 11
Joined: Mon Jun 11, 2018 11:02 pm

Re: Xim4 + T2 recoil issue?

Postby doiz » Mon Mar 18, 2019 8:23 pm

You could add rapid fire (off/on Triangle) ?
User avatar
doiz
Staff Sergeant
Staff Sergeant
 
Posts: 12
Joined: Sat May 05, 2018 5:21 am

Previous

Return to XIM Apex, XIM4, XIM Edge with Titan devices

Who is online

Users browsing this forum: No registered users and 34 guests