Tiny error on antithesis no-recoil script

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

Tiny error on antithesis no-recoil script

Postby Derivates » Sat Feb 16, 2019 12:15 am

This is my code atm , s withing from a default Vertical No-Recoil script to a new one with Horizontal too ;)
unfortunately I'm facing this issue:
Code: Select all
 
// TOGGLES
bool bAntiRecoil = TRUE;
    bool key_f2_event; // F2
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// VARIABLES & DEFINES [SETTINGS]
fix32 RECOIL_V = 4.5;                   // Adjust Vertical Anti-Recoil //
fix32 RECOIL_H = 0.0;                   // Adjust Horizontal Anti-Recoil //
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
                                                                    // Anti-Recoil
main {
  // toggle
    if(key_status(ANTI_RECOIL_KEY)) {
        if(!key_f2_event) {
            key_f2_event = TRUE;
            bAntiRecoil = !bAntiRecoil;
}
    } else key_f2_event = FALSE;
  if (bAntiRecoil && get_val(BUTTON_5)) {
    // Remove small unwanted movement as your controller sticks may not return to zero exactly after release.
    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); }
 
    AntiRecoil(STICK_1_Y,RECOIL_V); // Y Axis - vertical recoil compensation
    AntiRecoil(STICK_1_X,RECOIL_H); // X Axis - horizontal recoil compensation
  }
 
// this is the function applying the anti recoil
void AntiRecoil (uint8 axis, fix32 recoil)
{
   fix32 RY = get_actual(STICK_1_Y); // read the actual stick y value
   fix32 RX = get_actual(STICK_1_X); // read the actual sitck x value
 
   // only apply anti recoil if the actual movement of x&y is lower than the recoil to apply
   if (get_val(BUTTON_5) && (sqrt(RX*RX + RY*RY)) <= abs(recoil))
   {
     if(abs(RY) <= abs(recoil)) // only apply when y movement is lower than the recoil to apply
       {
          set_val(axis,(recoil * (100.0 - abs(get_val(axis)))) / 100.0 + get_val(axis));
       }
    }
}
}
 

Help is always appreciated. :smile0202:
User avatar
Derivates
Sergeant Major
Sergeant Major
 
Posts: 75
Joined: Sat Jan 19, 2019 6:15 pm

Re: Tiny error on antithesis no-recoil script

Postby J2Kbr » Tue Feb 19, 2019 9:55 am

I tried fix the script, however it is missing many declarations such as ANTI_RECOIL_KEY, StickNoise
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: Tiny error on antithesis no-recoil script

Postby Derivates » Tue Feb 19, 2019 2:27 pm

J2Kbr wrote:I tried fix the script, however it is missing many declarations such as ANTI_RECOIL_KEY, StickNoise

I forgot this was still up! fixed it and forgot to reply back..
Apart from missing 1 header and the defines the main issue was that I was including the void part as part of the "main" method; here's what I was looking for if anyone's interested.
Code: Select all
 
#include <keyboard.gph>
// TOGGLES
bool bAntiRecoil = TRUE;
    bool key_f2_event; // F2
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// VARIABLES & DEFINES [SETTINGS]
#define StickNoise 4.32
fix32 RECOIL_V = 4.5;                   // Adjust Vertical Anti-Recoil //
fix32 RECOIL_H = 0.0;                   // Adjust Horizontal Anti-Recoil //
#define ANTI_RECOIL_KEY    KEY_F2             // F2        "         Anti-Recoil //
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
                                                                    // Anti-Recoil
main {
  // toggle
    if(key_status(ANTI_RECOIL_KEY)) {
        if(!key_f2_event) {
            key_f2_event = TRUE;
            bAntiRecoil = !bAntiRecoil;
}
    } else key_f2_event = FALSE;
  if (bAntiRecoil && get_val(BUTTON_5)) {
    // Remove small unwanted movement as your controller sticks may not return to zero exactly after release.
    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); }
 
    AntiRecoil(STICK_1_Y,RECOIL_V); // Y Axis - vertical recoil compensation
    AntiRecoil(STICK_1_X,RECOIL_H); // X Axis - horizontal recoil compensation
  }
}
// this is the function applying the anti recoil
void AntiRecoil (uint8 axis, fix32 recoil)
{
   fix32 RY = get_actual(STICK_1_Y); // read the actual stick y value
   fix32 RX = get_actual(STICK_1_X); // read the actual sitck x value
 
   // only apply anti recoil if the actual movement of x&y is lower than the recoil to apply
   if (get_val(BUTTON_5) && (sqrt(RX*RX + RY*RY)) <= abs(recoil))
   {
     if(abs(RY) <= abs(recoil)) // only apply when y movement is lower than the recoil to apply
       {
          set_val(axis,(recoil * (100.0 - abs(get_val(axis)))) / 100.0 + get_val(axis));
       }
    }
}
 


You can also check the differences by comparing them side by side here: https://www.diffchecker.com/dD7NW76V
User avatar
Derivates
Sergeant Major
Sergeant Major
 
Posts: 75
Joined: Sat Jan 19, 2019 6:15 pm


Return to GPC2 Script Programming

Who is online

Users browsing this forum: No registered users and 133 guests