i need help in script Rapidfire

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

Re: i need help in script Rapidfire

Postby TheOne » Tue Jun 11, 2019 1:49 pm

Thank you
Last edited by TheOne on Tue Jun 11, 2019 1:54 pm, edited 1 time in total.
User avatar
TheOne
Sergeant First Class
Sergeant First Class
 
Posts: 21
Joined: Mon Aug 13, 2018 7:43 pm

Re: i need help in script Rapidfire

Postby TheOne » Tue Jun 11, 2019 1:50 pm

Scachi wrote:So you want to en/disable the script with a key press and toggle rapid fire with a fast press of triangle ?

You may want to change one of the color-letter combination to indicate the script on/off and rapid fire on/off states differently.
Code: Select all
#pragma METAINFO("Script_Name", 1, 0, "<author_name>")
 
#include <display.gph>
#include <keyboard.gph>
#include "xkeys.gph"
 
uint8 KEYPERIOD;
bool rapidfire;
bool script;
 
init {
  KEYPERIOD=xkeys_add(KEY_PADPERIOD);
}
 
main {
    key_passthru();
 
    if(xkeys_event_release(KEYPERIOD)) { // On release
        script = !script;   
 
        if(script) { // Enabled
            led_reset();
            led_set(LED_3, -1.0, 0);
            display_overlay(_R_, 2000);           
        } 
        else { // Disabled
            led_reset();
            display_overlay(_X_, 2000);
        }
    }
 
        if (script) { // script enabled
            if(event_release(BUTTON_14) && time_active(BUTTON_14) < 300) {
                    rapidfire = !rapidfire;
 
                    if(rapidfire) { // Enabled
                            led_reset();
                            led_set(LED_3, -1.0, 0);
                            display_overlay(_R_, 2000);           
                    } 
                    else { // Disabled
                            led_reset();
                            display_overlay(_X_, 2000);
                    }
            }   
 
            if(get_val(BUTTON_5) && rapidfire) { combo_run(RapidFire); }
        }
}
 
combo RapidFire {
    set_val(BUTTON_5, 100.0);
    wait(59);
    set_val(BUTTON_5, 0.0);
    wait(37);
}



Thank you

but there is issues with it , when i press (.) in keyboard is still disable i have to press BUTTON_14 one time to work
User avatar
TheOne
Sergeant First Class
Sergeant First Class
 
Posts: 21
Joined: Mon Aug 13, 2018 7:43 pm

Re: i need help in script Rapidfire

Postby Scachi » Tue Jun 11, 2019 2:25 pm

You said:
can u make BUTTON_14 only work when i activate (.) in keyboard

( soo when i press (.) to trun in off the BUTTON_14 no more work >> when i press (.) to trun in on the BUTTON_14 work

This is how it works at the moment:
(.) to turn SCRIPT on/off
(Triangle) to turn RAPID FIRE on/off when SCRIPT is ON


How do you want it to work ?
(.) to turn RAPID FIRE on
(Triangle) to turn RAPID FIRE off

This should work then:
Code: Select all
#pragma METAINFO("Script_Name", 1, 0, "<author_name>")
 
#include <display.gph>
#include <keyboard.gph>
#include "xkeys.gph"
 
uint8 KEYPERIOD;
bool rapidfire;
 
init {
  KEYPERIOD=xkeys_add(KEY_PADPERIOD);
}
 
main {
    //key_passthru(); // <- this is required only when you want to forward keyboard inputs raw/directly to your output with T2 Output Protocol set to "USB Multi Interface HID"
 
    if(xkeys_event_release(KEYPERIOD)) { // On release
        rapidfire=TRUE;
        led_reset();
        led_set(LED_3, -1.0, 0);
    }
 
    if(event_release(BUTTON_14) && time_active(BUTTON_14) < 300 && rapidfire) {
                rapidfire = FALSE;
                led_reset();
                display_overlay(_X_, 2000);
        }
 
      if(get_val(BUTTON_5) && rapidfire) { combo_run(RapidFire); }
}
 
combo RapidFire {
    set_val(BUTTON_5, 100.0);
    wait(59);
    set_val(BUTTON_5, 0.0);
    wait(37);
}
 



Or like this:
(.) to turn SCRIPT and RAPID FIRE on and SCRIPT off
(Triangle) to toggle RAPID FIRE off/on as long SCRIPT is on

Try this then:
Code: Select all
#pragma METAINFO("Script_Name", 1, 0, "<author_name>")
 
#include <display.gph>
#include <keyboard.gph>
#include "xkeys.gph"
 
uint8 KEYPERIOD;
bool rapidfire;
bool script;
 
init {
  KEYPERIOD=xkeys_add(KEY_PADPERIOD);
}
 
main {
    //key_passthru(); // <- this is required only when you want to forward keyboard inputs raw/directly to your output with T2 Output Protocol set to "USB Multi Interface HID"
 
    if(xkeys_event_release(KEYPERIOD)) { // On release
        script = !script;   
 
        if(script) { // Enabled
            led_reset();
            led_set(LED_3, -1.0, 0);
            display_overlay(_R_, 2000);
                        rapidfire=TRUE;
        } 
        else { // Disabled
            led_reset();
            display_overlay(_X_, 2000);
        }
    }
 
        if (script) { // script enabled
            if(event_release(BUTTON_14) && time_active(BUTTON_14) < 300) {
                    rapidfire = !rapidfire;
 
                    if(rapidfire) { // Enabled
                            led_reset();
                            led_set(LED_3, -1.0, 0);
                            display_overlay(_R_, 2000);           
                    } 
                    else { // Disabled
                            led_reset();
                            display_overlay(_X_, 2000);
                    }
            }   
 
            if(get_val(BUTTON_5) && rapidfire) { combo_run(RapidFire); }
        }
}
 
combo RapidFire {
    set_val(BUTTON_5, 100.0);
    wait(59);
    set_val(BUTTON_5, 0.0);
    wait(37);
}



Or try to explain again what you want the key (.) to do and what the (Triangle) should do.
User avatar
Scachi
Brigadier General
Brigadier General
 
Posts: 3044
Joined: Wed May 11, 2016 6:25 am
Location: Germany

Re: i need help in script Rapidfire

Postby TheOne » Sun Jun 30, 2019 12:21 pm

Thanks Mad & Scachi for all your help

----

can u help me with this too

in Key No.3 i want 2 Anit-Recoil so when i press triangle it swap between them (only work when i press triangle fast , and do not work when i hold triangle)



Code: Select all
#pragma METAINFO("<author_name>", 1, 0, "")
 
 
#include <display.gph>
#include <keyboard.gph>
 
#define KEYS_TO_MONITOR_MAX 4
#define XKEYS_NOTIME
#include "xkeys.gph"
 
uint8 KEYP0, KEYP1, KEYP2, KEYP3;
 
 
 ////////////////////////////    Anit-Recoil     
 
 
 
uint32 T[]= {0,0,0}; // time in ms the button has to be pressed down for the values to be used
int8  AX[]= {0,0,0}// x anti recoil when time reached
int8  AY[]= {17,17,17}// y anti recoil when time reached
 
fix32 StickNoise = 6.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.
 
 
 
init {
  // some error checking, number of values have to match the number of times
  if (sizeof(T)/4 != sizeof(AX)) printf("number of times (%d) and x values (%d) have to match",sizeof(T)/4,sizeof(AX));
  if (sizeof(T)/4 != sizeof(AY)) printf("number of times (%d) and y values (%d) have to match",sizeof(T)/4,sizeof(AY));
 
    // prepare keys to use for xkeys_event_ functions
    KEYP0=xkeys_add(KEY_PAD0);
    KEYP1=xkeys_add(KEY_PAD1);
    KEYP2=xkeys_add(KEY_PAD2);
    KEYP3=xkeys_add(KEY_PAD3);
 
}
 
main {
    if (get_val (BUTTON_5)) // only active when ADS & firing to allow for microaim adjustments without the input being filtered
    {   
      // 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); }
 
            if (get_val(BUTTON_8)) AROverTime(); // when fire button is active use anti recoil
    }                   //0//
              if(xkeys_event_active(KEYP0)) {   ////// MUST BE NO 0
                ARSet(0,1000,1500///// Time
                  0,0,0,        /////  X L/R
                  8,5,7);             /////  Y recoil
                display_overlay(_0_,-1);
            }        //1//
              if(xkeys_event_active(KEYP1)) {   /////////// Key No.1
                ARSet(0,200,700///// Time
                  2,2,1,        /////  X L/R
                  30,22,0);             /////  Y recoil
                display_overlay(_1_,-1);
            }      //2//
              if(xkeys_event_active(KEYP2)) {   /////////// Key No.2
                ARSet(0,700,1500///// Time
                  0,0,0,        /////  X L/R
                  22,25,30);             /////  Y recoil
                display_overlay(_2_,-1);
            }    //3//
              if(xkeys_event_active(KEYP3)) {    /////////// Key No.3
               ARSet(0,850,1000,      ///// Time
                   0,0,0,           /////  X L/R
                  10,8,12);             /////  Y recoil
                display_overlay(_3_,-1);
            }
        }   
 
// time,time,time,     x,x,x,     y,y,y
void ARSet(uint32 t0,uint32 t1,uint32 t2,int8 ax0,int8 ax1,int8 ax2,int8 ay0,int8 ay1,int8 ay2) {
    T[0]= t0; T[1]= t1; T[2]= t2;
    AX[0]=ax0; AX[1]=ax1; AX[2]=ax2;
    AY[0]=ay0; AY[1]=ay1; AY[2]=ay2;
}
 
void AROverTime() {
  int8 i;
  uint32 ta = time_active(BUTTON_5);
  uint32 taADS = time_active(BUTTON_8);
 
  static int last=0; // for information in the output panel
 
  for (i=sizeof(T)/4;i>=0;i--) {
    if (ta > taADS) ta = taADS;
    if (ta >= T[i]) {
 
      if (i != last) { last=i; printf("active entry %d, time %ld, applying x: %d, y: %d",i,T[i],AX[i],AY[i]); }// for information in the output panel
 
      AntiRecoil(STICK_1_X,(fix32)AX[i]); // apply the X anti recoil value
      AntiRecoil(STICK_1_Y,(fix32)AY[i]); // apply the y anti recoil value
      return;
    }
  }
}
 
// antithesis antirecoil
void AntiRecoil (uint8 axis, fix32 recoil)
{
  fix32 RY = get_actual(STICK_1_Y);
  fix32 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));
      }
  }
}
 
 
User avatar
TheOne
Sergeant First Class
Sergeant First Class
 
Posts: 21
Joined: Mon Aug 13, 2018 7:43 pm

Re: i need help in script Rapidfire

Postby Scachi » Sun Jun 30, 2019 2:14 pm

TheOne wrote:Thanks Mad & Scachi for all your help

----

can u help me with this too

in Key No.3 i want 2 Anit-Recoil so when i press triangle it swap between them (only work when i press triangle fast , and do not work when i hold triangle)


Try this:
Code: Select all
#pragma METAINFO("script name", 1, 0, "<author_name>")
 
#include <display.gph>
#include <keyboard.gph>
 
#define KEYS_TO_MONITOR_MAX 4
#define XKEYS_NOTIME
#include "xkeys.gph"
 
uint8 KEYP0, KEYP1, KEYP2, KEYP3;
 
////////////////////////////    Anti-Recoil     
int8  DataSet=-1; // last ar data set via keypad key pressed
uint8 Triangle;        // result of monitoring fast press of triangle
#define TLimit    150 // press shorter time than set will change newteen ar values used: ARP3_A or ARP3_B
 
 
uint32 T[]= {0,0,0}; // time in ms the button has to be pressed down for the values to be used
int8  AX[]= {0,0,0}// x anti recoil when time reached
int8  AY[]= {17,17,17}// y anti recoil when time reached
 
// anti recoil data sets for the keys pressed
#define ARP0   ARSet(0,1000,1500,0,0,0, 8, 5, 7) // t1,t2,t3,x1,x2,x3,y1,y2,y3
#define ARP1   ARSet(0, 200, 700,2,2,1,30,22, 0) // t1,t2,t3,x1,x2,x3,y1,y2,y3
#define ARP2   ARSet(0, 700,1500,0,0,0,22,25,30) // t1,t2,t3,x1,x2,x3,y1,y2,y3
#define ARP3_A ARSet(0, 850,1000,0,0,0,10, 8,12) // t1,t2,t3,x1,x2,x3,y1,y2,y3 <---- default one for P3
#define ARP3_B ARSet(0, 860,1000,0,0,0,10, 8,12) // t1,t2,t3,x1,x2,x3,y1,y2,y3
 
fix32 StickNoise = 6.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.
 
 
init {
  // some error checking, number of values have to match the number of times
  if (sizeof(T)/4 != sizeof(AX)) printf("number of times (%d) and x values (%d) have to match",sizeof(T)/4,sizeof(AX));
  if (sizeof(T)/4 != sizeof(AY)) printf("number of times (%d) and y values (%d) have to match",sizeof(T)/4,sizeof(AY));
 
    // prepare keys to use for xkeys_event_ functions
    KEYP0=xkeys_add(KEY_PAD0);
    KEYP1=xkeys_add(KEY_PAD1);
    KEYP2=xkeys_add(KEY_PAD2);
    KEYP3=xkeys_add(KEY_PAD3);
 
}
 
main {
    if (get_val (BUTTON_5)) // only active when ADS & firing to allow for microaim adjustments without the input being filtered
    {   
      // 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); }
 
            if (get_val(BUTTON_8)) AROverTime(); // when fire button is active use anti recoil
    }
 
                                            //0//
              if(xkeys_event_active(KEYP0)) {   ////// MUST BE NO 0
                                DataSet=0;
                ARP0;
                display_overlay(_0_,-1);
            }        //1//
              if(xkeys_event_active(KEYP1)) {   /////////// Key No.1
                                DataSet=1;
                ARP1;
                display_overlay(_1_,-1);
            }      //2//
              if(xkeys_event_active(KEYP2)) {   /////////// Key No.2
                                DataSet=2;
                ARP2;
                display_overlay(_2_,-1);
            }    //3//
              if(xkeys_event_active(KEYP3)) {    /////////// Key No.3
                                DataSet=3; Triangle=0;
                                ARP3_A;
                display_overlay(_3_,-1);
            }
 
        if (DataSet==3) {
            if (event_release(BUTTON_14) && time_active(BUTTON_14) < TLimit) {
                Triangle=(Triangle+1)%2; // toggle between 0 or 1
                if (!Triangle) { // 0
                    ARP3_A;
                    display_overlay(_3_,-1);
                } else { // 1
                    ARP3_B;
                    display_overlay(_3_|BOTTOM_DOT,-1);
                }
            }
        }
}   
 
// time,time,time,     x,x,x,     y,y,y
void ARSet(uint32 t0,uint32 t1,uint32 t2,int8 ax0,int8 ax1,int8 ax2,int8 ay0,int8 ay1,int8 ay2) {
    T[0]= t0; T[1]= t1; T[2]= t2;
    AX[0]=ax0; AX[1]=ax1; AX[2]=ax2;
    AY[0]=ay0; AY[1]=ay1; AY[2]=ay2;
}
 
void AROverTime() {
  int8 i;
  uint32 ta = time_active(BUTTON_5);
  uint32 taADS = time_active(BUTTON_8);
 
  static int last=0; // for information in the output panel
 
  for (i=sizeof(T)/4;i>=0;i--) {
    if (ta > taADS) ta = taADS;
    if (ta >= T[i]) {
 
      if (i != last) { last=i; printf("active entry %d, time %ld, applying x: %d, y: %d",i,T[i],AX[i],AY[i]); }// for information in the output panel
 
      AntiRecoil(STICK_1_X,(fix32)AX[i]); // apply the X anti recoil value
      AntiRecoil(STICK_1_Y,(fix32)AY[i]); // apply the y anti recoil value
      return;
    }
  }
}
 
// antithesis antirecoil
void AntiRecoil (uint8 axis, fix32 recoil)
{
  fix32 RY = get_actual(STICK_1_Y);
  fix32 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));
      }
  }
}
 
 
User avatar
Scachi
Brigadier General
Brigadier General
 
Posts: 3044
Joined: Wed May 11, 2016 6:25 am
Location: Germany

Re: i need help in script Rapidfire

Postby TheOne » Sun Jun 30, 2019 3:10 pm

Scachi wrote:
TheOne wrote:Thanks Mad & Scachi for all your help

----

can u help me with this too

in Key No.3 i want 2 Anit-Recoil so when i press triangle it swap between them (only work when i press triangle fast , and do not work when i hold triangle)


Try this:
Code: Select all
#pragma METAINFO("script name", 1, 0, "<author_name>")
 
#include <display.gph>
#include <keyboard.gph>
 
#define KEYS_TO_MONITOR_MAX 4
#define XKEYS_NOTIME
#include "xkeys.gph"
 
uint8 KEYP0, KEYP1, KEYP2, KEYP3;
 
////////////////////////////    Anti-Recoil     
int8  DataSet=-1; // last ar data set via keypad key pressed
uint8 Triangle;        // result of monitoring fast press of triangle
#define TLimit    150 // press shorter time than set will change newteen ar values used: ARP3_A or ARP3_B
 
 
uint32 T[]= {0,0,0}; // time in ms the button has to be pressed down for the values to be used
int8  AX[]= {0,0,0}// x anti recoil when time reached
int8  AY[]= {17,17,17}// y anti recoil when time reached
 
// anti recoil data sets for the keys pressed
#define ARP0   ARSet(0,1000,1500,0,0,0, 8, 5, 7) // t1,t2,t3,x1,x2,x3,y1,y2,y3
#define ARP1   ARSet(0, 200, 700,2,2,1,30,22, 0) // t1,t2,t3,x1,x2,x3,y1,y2,y3
#define ARP2   ARSet(0, 700,1500,0,0,0,22,25,30) // t1,t2,t3,x1,x2,x3,y1,y2,y3
#define ARP3_A ARSet(0, 850,1000,0,0,0,10, 8,12) // t1,t2,t3,x1,x2,x3,y1,y2,y3 <---- default one for P3
#define ARP3_B ARSet(0, 860,1000,0,0,0,10, 8,12) // t1,t2,t3,x1,x2,x3,y1,y2,y3
 
fix32 StickNoise = 6.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.
 
 
init {
  // some error checking, number of values have to match the number of times
  if (sizeof(T)/4 != sizeof(AX)) printf("number of times (%d) and x values (%d) have to match",sizeof(T)/4,sizeof(AX));
  if (sizeof(T)/4 != sizeof(AY)) printf("number of times (%d) and y values (%d) have to match",sizeof(T)/4,sizeof(AY));
 
    // prepare keys to use for xkeys_event_ functions
    KEYP0=xkeys_add(KEY_PAD0);
    KEYP1=xkeys_add(KEY_PAD1);
    KEYP2=xkeys_add(KEY_PAD2);
    KEYP3=xkeys_add(KEY_PAD3);
 
}
 
main {
    if (get_val (BUTTON_5)) // only active when ADS & firing to allow for microaim adjustments without the input being filtered
    {   
      // 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); }
 
            if (get_val(BUTTON_8)) AROverTime(); // when fire button is active use anti recoil
    }
 
                                            //0//
              if(xkeys_event_active(KEYP0)) {   ////// MUST BE NO 0
                                DataSet=0;
                ARP0;
                display_overlay(_0_,-1);
            }        //1//
              if(xkeys_event_active(KEYP1)) {   /////////// Key No.1
                                DataSet=1;
                ARP1;
                display_overlay(_1_,-1);
            }      //2//
              if(xkeys_event_active(KEYP2)) {   /////////// Key No.2
                                DataSet=2;
                ARP2;
                display_overlay(_2_,-1);
            }    //3//
              if(xkeys_event_active(KEYP3)) {    /////////// Key No.3
                                DataSet=3; Triangle=0;
                                ARP3_A;
                display_overlay(_3_,-1);
            }
 
        if (DataSet==3) {
            if (event_release(BUTTON_14) && time_active(BUTTON_14) < TLimit) {
                Triangle=(Triangle+1)%2; // toggle between 0 or 1
                if (!Triangle) { // 0
                    ARP3_A;
                    display_overlay(_3_,-1);
                } else { // 1
                    ARP3_B;
                    display_overlay(_3_|BOTTOM_DOT,-1);
                }
            }
        }
}   
 
// time,time,time,     x,x,x,     y,y,y
void ARSet(uint32 t0,uint32 t1,uint32 t2,int8 ax0,int8 ax1,int8 ax2,int8 ay0,int8 ay1,int8 ay2) {
    T[0]= t0; T[1]= t1; T[2]= t2;
    AX[0]=ax0; AX[1]=ax1; AX[2]=ax2;
    AY[0]=ay0; AY[1]=ay1; AY[2]=ay2;
}
 
void AROverTime() {
  int8 i;
  uint32 ta = time_active(BUTTON_5);
  uint32 taADS = time_active(BUTTON_8);
 
  static int last=0; // for information in the output panel
 
  for (i=sizeof(T)/4;i>=0;i--) {
    if (ta > taADS) ta = taADS;
    if (ta >= T[i]) {
 
      if (i != last) { last=i; printf("active entry %d, time %ld, applying x: %d, y: %d",i,T[i],AX[i],AY[i]); }// for information in the output panel
 
      AntiRecoil(STICK_1_X,(fix32)AX[i]); // apply the X anti recoil value
      AntiRecoil(STICK_1_Y,(fix32)AY[i]); // apply the y anti recoil value
      return;
    }
  }
}
 
// antithesis antirecoil
void AntiRecoil (uint8 axis, fix32 recoil)
{
  fix32 RY = get_actual(STICK_1_Y);
  fix32 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));
      }
  }
}
 
 


there is something wrong with this , not wrok , i try change values , 0 change for recoil

Code: Select all
#define ARP0   ARSet(0,1000,1500,0,0,0, 8, 5, 7) // t1,t2,t3,x1,x2,x3,y1,y2,y3
#define ARP1   ARSet(0, 200, 700,2,2,1,30,22, 0) // t1,t2,t3,x1,x2,x3,y1,y2,y3
#define ARP2   ARSet(0, 700,1500,0,0,0,22,25,30) // t1,t2,t3,x1,x2,x3,y1,y2,y3
#define ARP3_A ARSet(0, 850,1000,0,0,0,10, 8,12) // t1,t2,t3,x1,x2,x3,y1,y2,y3 <---- default one for P3
#define ARP3_B ARSet(0, 860,1000,0,0,0,10, 8,12) // t1,t2,t3,x1,x2,x3,y1,y2,y3
User avatar
TheOne
Sergeant First Class
Sergeant First Class
 
Posts: 21
Joined: Mon Aug 13, 2018 7:43 pm

Re: i need help in script Rapidfire

Postby Scachi » Sun Jun 30, 2019 4:19 pm

TheOne wrote:there is something wrong with this , not wrok , i try change values , 0 change for recoil

oh ...yes, you are right. A failure in the for loop.
This one works:
Code: Select all
#pragma METAINFO("script name", 1, 0, "<author_name>")
 
#include <display.gph>
#include <keyboard.gph>
 
#define KEYS_TO_MONITOR_MAX 4
#define XKEYS_NOTIME
#include "xkeys.gph"
 
uint8 KEYP0, KEYP1, KEYP2, KEYP3;
 
////////////////////////////    Anti-Recoil     
int8  DataSet=-1; // last ar data set via keypad key pressed
uint8 Triangle;        // result of monitoring fast press of triangle
#define TLimit    150 // press shorter time than set will change newteen ar values used: ARP3_A or ARP3_B
 
 
uint32 T[]= {0,0,0}; // time in ms the button has to be pressed down for the values to be used
int8  AX[]= {0,0,0}// x anti recoil when time reached
int8  AY[]= {17,17,17}// y anti recoil when time reached
 
// anti recoil data sets for the keys pressed
#define ARP0   ARSet(0,1000,1500,0,0,0, 8, 5, 7) // t1,t2,t3,x1,x2,x3,y1,y2,y3
#define ARP1   ARSet(0, 200, 700,2,2,1,30,22, 0) // t1,t2,t3,x1,x2,x3,y1,y2,y3
#define ARP2   ARSet(0, 700,1500,0,0,0,22,25,30) // t1,t2,t3,x1,x2,x3,y1,y2,y3
#define ARP3_A ARSet(0, 850,1000,0,0,0,10, 8,12) // t1,t2,t3,x1,x2,x3,y1,y2,y3 <---- default one for P3
#define ARP3_B ARSet(0, 860,1000,0,0,0,10, 8,12) // t1,t2,t3,x1,x2,x3,y1,y2,y3
 
fix32 StickNoise = 6.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.
 
 
init {
  // some error checking, number of values have to match the number of times
  if (sizeof(T)/4 != sizeof(AX)) printf("number of times (%d) and x values (%d) have to match",sizeof(T)/4,sizeof(AX));
  if (sizeof(T)/4 != sizeof(AY)) printf("number of times (%d) and y values (%d) have to match",sizeof(T)/4,sizeof(AY));
 
    // prepare keys to use for xkeys_event_ functions
    KEYP0=xkeys_add(KEY_PAD0);
    KEYP1=xkeys_add(KEY_PAD1);
    KEYP2=xkeys_add(KEY_PAD2);
    KEYP3=xkeys_add(KEY_PAD3);
        //printf("T %d %d %d , X %d %d %d , Y %d %d %d",T[0],T[1],T[2],AX[0],AX[1],AX[2],AY[0],AY[1],AY[2]);
}
 
main {
    if (get_val (BUTTON_5)) // only active when ADS & firing to allow for microaim adjustments without the input being filtered
    {   
      // 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); }
 
            if (get_val(BUTTON_8)) AROverTime(); // when fire button is active use anti recoil
    }
 
                                            //0//
              if(xkeys_event_active(KEYP0)) {   ////// MUST BE NO 0
                                DataSet=0;
                ARP0;
                display_overlay(_0_,-1);
            }        //1//
              if(xkeys_event_active(KEYP1)) {   /////////// Key No.1
                                DataSet=1;
                ARP1;
                display_overlay(_1_,-1);
            }      //2//
              if(xkeys_event_active(KEYP2)) {   /////////// Key No.2
                                DataSet=2;
                ARP2;
                display_overlay(_2_,-1);
            }    //3//
              if(xkeys_event_active(KEYP3)) {    /////////// Key No.3
                                DataSet=3; Triangle=0;
                                ARP3_A;
                display_overlay(_3_,-1);
            }
 
        if (DataSet==3) {
            if (event_release(BUTTON_14) && time_active(BUTTON_14) < TLimit) {
                Triangle=(Triangle+1)%2; // toggle between 0 or 1
                if (!Triangle) { // 0
                    ARP3_A;
                    display_overlay(_3_,-1);
                } else { // 1
                    ARP3_B;
                    display_overlay(_3_|BOTTOM_DOT,-1);
                }
            }
        }
 
}   
 
// time,time,time,     x,x,x,     y,y,y
void ARSet(uint32 t0,uint32 t1,uint32 t2,int8 ax0,int8 ax1,int8 ax2,int8 ay0,int8 ay1,int8 ay2) {
    T[0]= t0; T[1]= t1; T[2]= t2;
    AX[0]=ax0; AX[1]=ax1; AX[2]=ax2;
    AY[0]=ay0; AY[1]=ay1; AY[2]=ay2;
        printf("Activating -> T:{%d,%d,%d} , X:{%d,%d,%d} , Y:{%d,%d,%d}",T[0],T[1],T[2],AX[0],AX[1],AX[2],AY[0],AY[1],AY[2]);
}
 
void AROverTime() {
  int8 i;
  uint32 ta = time_active(BUTTON_5);
  uint32 taADS = time_active(BUTTON_8);
 
  static int last=0; // for information in the output panel
 
  for (i=(sizeof(T)/4)-1;i>=0;i--) {
    if (ta > taADS) ta = taADS;
    if (ta >= T[i]) {
 
      if (i != last) { last=i; printf("active entry %d, time %ld, applying x: %d, y: %d",i,T[i],AX[i],AY[i]); }// for information in the output panel
 
      AntiRecoil(STICK_1_X,(fix32)AX[i]); // apply the X anti recoil value
      AntiRecoil(STICK_1_Y,(fix32)AY[i]); // apply the y anti recoil value
      return;
    }
  }
}
 
// antithesis antirecoil
void AntiRecoil (uint8 axis, fix32 recoil)
{
  fix32 RY = get_actual(STICK_1_Y);
  fix32 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));
      }
  }
}
 
User avatar
Scachi
Brigadier General
Brigadier General
 
Posts: 3044
Joined: Wed May 11, 2016 6:25 am
Location: Germany

Previous

Return to GPC2 Script Programming

Who is online

Users browsing this forum: No registered users and 96 guests