// adjustable RAPIDFIRE using more accurate values
define RAPIDFIRE_BUTTON = XB1_RT; // The rapidfire button
define ROF_UP = XB1_UP; // Press UP for increase
define ROF_DOWN = XB1_DOWN; // Press DOWN for decrease
define ROF_RESET = XB1_RIGHT; // Press RIGHT for reset
int check = TRUE;
int RATE_OF_FIRE_DEFAULT = 10 ; // The default rate of fire for reset
int RATE_OF_FIRE = 10 ; // The initial rate of fire. Fractions should look like this 15.5 = 155. Use 155 for 15.5
int MyRate = 0;
int MyBit;
int MyResult;
int hold_time, rest_time;
main {
set_bits(MyBit, 0, 15, 255*257);
MyResult = (MyBit - ((1500*10)+536))*-1;
hold_time = MyResult / RATE_OF_FIRE;
rest_time = hold_time - 20;
if(rest_time < 0) rest_time = 0;
MyRate = MyRate - get_rtime()*2;
if(event_press(ROF_UP)) {
RATE_OF_FIRE = RATE_OF_FIRE + 10;}
if(event_press(ROF_DOWN)) {
RATE_OF_FIRE = RATE_OF_FIRE - 10;}
if(event_press(ROF_RESET)) {
RATE_OF_FIRE = RATE_OF_FIRE_DEFAULT ;}
if(event_press(RAPIDFIRE_BUTTON)) {set_val(RAPIDFIRE_BUTTON, 100); check = TRUE; MyRate = hold_time;}
else if(get_val(RAPIDFIRE_BUTTON) && check) {set_val(RAPIDFIRE_BUTTON, 100);}
else if(!check) {set_val(RAPIDFIRE_BUTTON, 0);}
if(!get_val(RAPIDFIRE_BUTTON) && MyRate<=0 && check == FALSE) {MyRate = hold_time; check =TRUE;}
if(MyRate<=0 && check == TRUE) {MyRate = rest_time; check =FALSE;}
}