My Rainbow Six Siege script for keyboard & mouse users

Documentation, usage tips and configuration guides for Titan Two scripts and bytecodes published by the community users.

My Rainbow Six Siege script for keyboard & mouse users

Postby TheBigKent » Sun Jul 01, 2018 6:42 pm

Hello, I wrote this script for myself as a keyboard and mouse player for the PS4. I started originally on a Titan One equivalent and ported it over for the Titan Two. I strictly use a mouse and keyboard to play, there is no xim4 or xim apex in-between, strictly the Titan Two. - TheBigKent

Just to note, the quick 180 turn isn't exact so just be aware it's close and tuned to use 100% sensitivity in-game. The anti-recoil isn't necessary as this is a aim for the head kind of game but it's convenient if you're playing The Division. Auto-lean will not take into account your manual lean inputs so it'll be a bit wonky if you're using both.

Code: Select all
#pragma METAINFO("TheBigKent", 1, 0, "")
#include <ps4.gph>
#include <remapper.gph>
#include <keyboard.gph>
#include <mouse.gph>
 
//////////////////////////////////////////////////////////////////////////////
//   _____ _         ______ _       _   __           _   
//  |_   _| |        | ___ (_)     | | / /          | | 
//    | | | |__   ___| |_/ /_  __ _| |/ /  ___ _ __ | |_
//    | | | '_ \ / _ \ ___ \ |/ _` |    \ / _ \ '_ \| __|
//    | | | | | |  __/ |_/ / | (_| | |\  \  __/ | | | |_
//    \_/ |_| |_|\___\____/|_|\__, \_| \_/\___|_| |_|\__|
//                             __/ |                     
//                            |___/                     
//  System:          PS4
//  Controller:      Keyboard and Mouse
//  GAME:             Rainbow Six: Siege
//  WEAPON: All
//  AUTO-LEAN = Leans left or right in scoped view
//  SLOW-WALK = Hold left shift to reduce stick movement to 40%
//  ANTI-RECOIL = 3 settings to select weight, will hold right stick down to reduce recoil
//  AUTO-RUN = Double tap 'W' to run
//////////////////////////////////////////////////////////////////////////////
// Version 0.5 - Added a combo mapped to the 'B' key to allow a ~180 quick turn
// Version 0.4 - Ported from C r o n u s MAX to Titan Two
// Version 0.3 - Ported to PS4
// Version 0.2 - Imporoved double tap code to ignore long button presses, you will now
//               have to literally double tap, no more accidental running!
//             - Added controls to allow you to adjust anti-recoil weight manually in game
//               using EXTRA8 and EXTRA9 ( I use the number pad's + and -
// Version 0.1 - increased combo delay to 300 ms.  Added a get_ptime(XB1_LT) > 100
//               delay in the lean function if statement to prevent accidental knifing.
//////////////////////////////////////////////////////////////////////////////
 
#define SLOW_WALK_KEY      KEY_LEFTSHIFT    // Left shift used to reduce left stick movent
#define AUTO_LEAN_KEY      KEY_F5            // F5 used to enable auto lean
#define ANTI_RECOIL_KEY    KEY_F6            // F6 used to enable anti recoil
#define ALL_OFF          KEY_F8            // F8 used to disable all mods except slow walk
#define QUICK_TURN_KEY    KEY_B            // Use the 'B' key
 
#define WEIGHT_ONE       KEY_PAD1        // Num pad 1
#define WEIGHT_TWO       KEY_PAD2        // Num pad 2
#define WEIGHT_THREE     KEY_PAD3        // Num pad 3
#define WEIGHT_PLUS      KEY_PADPLUS        // +
#define WEIGHT_MINUS     KEY_PADHYPHEN    // -
 
 
// Slow walk speed is 40% stick movement
#define SLOW_WALK_SPEED        40.0
// Maximum gap between tap to register double tap
#define DOUBLE_TAP_GAP        200
// Time required to consider button being held
#define DT_HOLD_TIME        800
// Maximum number of buttons on controller
#define DT_MAX_BUTTON        25
// Maximum stick input while applying anti-recoil
#define AR_MAX_STICK        25.0
// Combo button delay time
#define COMBO_DELAY_TIME    300
// Quick turn time
#define QUICK_TURN_DELAY    225           
 
// Auto lean vars
int8 AUTO_LEAN_EN;
int8 AUTO_LEAN_HOLD;
int8 LEAN_SET;
int8 WEIGHT_PLUS_HOLD;
int8 WEIGHT_MINUS_HOLD;
// Anti-recoil vars
int8 ANTI_RECOIL_EN;
int8 ANTI_RECOIL_HOLD;
fix32 ANTI_RECOIL_WEIGHT;
fix32 ANTI_RECOIL_TEMP;
// Double tap vars
int8 DT_BUTTON_STATE[DT_MAX_BUTTON];
int16 DT_BUTTON_TIMING[DT_MAX_BUTTON];
// Quick turn
int8 QUICK_TURN_HOLD;
 
init {
    // Initialize variables
    AUTO_LEAN_EN = 0;
    AUTO_LEAN_HOLD = 0;
    LEAN_SET = 0;
    WEIGHT_PLUS_HOLD = 0;
    WEIGHT_MINUS_HOLD = 0;
    ANTI_RECOIL_EN = 0;
    ANTI_RECOIL_HOLD = 0;
    ANTI_RECOIL_WEIGHT = -25.0;
    ANTI_RECOIL_TEMP = 0.0;
    QUICK_TURN_HOLD = 0;
 
    // Initialize arrays
    memset(&DT_BUTTON_STATE, 0, sizeof(DT_BUTTON_STATE));
    memset(&DT_BUTTON_TIMING, 0, sizeof(DT_BUTTON_TIMING));
 
    // Enable key passthru so that we are able to run scripts based off keyboard
    // input and also generate controller input
    key_passthru();
    mouse_passthru();
 
    // Disable rumble for us keyboard users
    port_inhibit_ffb(PORT_USB_A);
    port_inhibit_ffb(PORT_USB_B);
    port_inhibit_ffb(PORT_BT_A);
    port_inhibit_ffb(PORT_BT_B);
 
}
 
main {
 
    // Turn around aka quick 180
    if(key_status(QUICK_TURN_KEY) && QUICK_TURN_HOLD == 0) {
        // Turn
        combo_run( COMBO_QUICK_TURN );
 
        QUICK_TURN_HOLD = 1;
    } else if( !key_status(QUICK_TURN_KEY) ) {
        QUICK_TURN_HOLD = 0;
    }
 
    // Slow walk
    // - Uses shift key to limit stick input for slower walking speeds
    // - Always active
    if(key_status(SLOW_WALK_KEY)) {
 
        if(get_val(PS4_LX) <= -SLOW_WALK_SPEED) { set_val(PS4_LX, -SLOW_WALK_SPEED); }
        if(get_val(PS4_LX) >=  SLOW_WALK_SPEED) { set_val(PS4_LX,  SLOW_WALK_SPEED); }
        if(get_val(PS4_LY) <= -SLOW_WALK_SPEED) { set_val(PS4_LY, -SLOW_WALK_SPEED); }
        if(get_val(PS4_LY) >=  SLOW_WALK_SPEED) { set_val(PS4_LY,  SLOW_WALK_SPEED); }
    } //SLOW_WALK
 
    // Scoped mode
    // - Looking down the sight, we'll ignore expendables and reassign Q and E
    //   to lean
    if( get_val(PS4_L2) >= 90.0 ) {
 
        // Should we lean
        if( get_val(PS4_L1) >= 90.0 ) {
            set_val(PS4_L1, 0);
            combo_run( COMBO_LEAN_LEFT );
        } else if( get_val(PS4_R1) >= 90.0 ) {
            set_val(PS4_R1, 0);
            combo_run( COMBO_LEAN_RIGHT );
        }
    }
 
    // Check for double tap on 'W' and verify the scope is not up
    if(DOUBLE_TAP(PS4_LY) && get_val(PS4_L2) <= 90.0 ) {
        // Run lean combo
        combo_run( COMBO_LEAN_LEFT );
    }
 
    // Auto-lean enable/disable function
    if( key_status(AUTO_LEAN_KEY) && AUTO_LEAN_HOLD == 0) {
        // Toggle auto lean
        if(AUTO_LEAN_EN >= 1) { AUTO_LEAN_EN = 0; } else { AUTO_LEAN_EN = 1; }
 
        // Set flag to wait for button relase
        AUTO_LEAN_HOLD = 1;
 
        // Debug statement
        printf("AUTO_LEAN_EN = %u", AUTO_LEAN_EN);
    } else if( !key_status(AUTO_LEAN_KEY) ) {
        // Clear flag when button is released
        AUTO_LEAN_HOLD = 0;
    }
 
    if(AUTO_LEAN_EN >= 1 && get_val(PS4_L2) >= 90.0 && time_active(PS4_L2) >= COMBO_DELAY_TIME ) {
        // Lean left/right when straffing and sight is up
        // Will not lean if using slow-walk
        // Included get_ptime(XB1_LT) > 100 delay to prevent premature button press
 
        if(get_val(PS4_LX) >= 90.0 && LEAN_SET <= 0) {
            // Moving right
            combo_run(COMBO_LEAN_RIGHT);
            LEAN_SET = 1;
        } else if(get_val(PS4_LX) <= -90.0 && LEAN_SET >= 0) {
            // Moving left
            combo_run(COMBO_LEAN_LEFT);
            LEAN_SET = -1;
        }
    } else {
        // Reset our set flag
        LEAN_SET = 0;
    }
 
    // Anti-recoil enable/disable function
    if( key_status(ANTI_RECOIL_KEY) && ANTI_RECOIL_HOLD == 0) {
        // Toggle auto lean
        if(ANTI_RECOIL_EN >= 1) { ANTI_RECOIL_EN = 0; } else { ANTI_RECOIL_EN = 1; }
 
        // Set flag to wait for button relase
        ANTI_RECOIL_HOLD = 1;
 
        // Debug statement
        printf("ANTI_RECOIL_EN = %u", ANTI_RECOIL_EN);
    } else if( !key_status(ANTI_RECOIL_KEY) ) {
        // Clear flag when button is released
        ANTI_RECOIL_HOLD = 0;
    }
 
    // Anti-recoil script
    // Add recoil reduction to current right stick Y value
    if(ANTI_RECOIL_EN >= 1 && get_val(PS4_R2) >= 90.0) {
        // Grab stick input
        ANTI_RECOIL_TEMP = get_val(PS4_RY);
 
 
        // Reduce stick movement
        if(ANTI_RECOIL_TEMP >= AR_MAX_STICK) {
            ANTI_RECOIL_TEMP = AR_MAX_STICK;
        } else if(ANTI_RECOIL_TEMP <= -AR_MAX_STICK) {
            ANTI_RECOIL_TEMP = -AR_MAX_STICK;
        }
 
        // Apply anti-recoil adjust
        // I play with Y axis inverted so I subtract
        set_val(PS4_RY, ANTI_RECOIL_TEMP-ANTI_RECOIL_WEIGHT);
    }
 
    // Detect key press for default values
    if(key_status(WEIGHT_ONE)) { ANTI_RECOIL_WEIGHT = -17.0; }
    if(key_status(WEIGHT_TWO)) { ANTI_RECOIL_WEIGHT = -25.0; }
    if(key_status(WEIGHT_THREE)) { ANTI_RECOIL_WEIGHT = -35.0; }
    // Detect key presses for increase or decrease
    if(key_status(WEIGHT_PLUS) && WEIGHT_PLUS_HOLD == 0) {
        ANTI_RECOIL_WEIGHT = ANTI_RECOIL_WEIGHT - 1.0;
        WEIGHT_PLUS_HOLD = 1;
    } else if( !key_status(WEIGHT_PLUS) && WEIGHT_PLUS_HOLD == 1 ) {
        WEIGHT_PLUS_HOLD = 0;
        printf("New anti-recoil weight is: %f", ANTI_RECOIL_WEIGHT);
    }
 
    if(key_status(WEIGHT_MINUS) && WEIGHT_MINUS_HOLD == 0) {
        ANTI_RECOIL_WEIGHT = ANTI_RECOIL_WEIGHT + 1.0;
        WEIGHT_MINUS_HOLD = 1;
    } else if( !key_status(WEIGHT_MINUS) && WEIGHT_MINUS_HOLD == 1) {
        WEIGHT_MINUS_HOLD = 0;       
        printf("New anti-recoil weight is: %f", ANTI_RECOIL_WEIGHT);
    }
 
    //output_keycode();
}
 
// COMBO_LEAN_LEFT
// - A combo for leaning left, we also cancle the L1 press
combo COMBO_LEAN_LEFT {
    set_val(PS4_L1, 0);
    set_val(PS4_L3, 100);
    wait(COMBO_DELAY_TIME);
    set_val(PS4_L3, 0);
}
 
// COMBO_LEAN_RIGHT
// - A combo for leaning right, we also cancle the R1 press
combo COMBO_LEAN_RIGHT {
    set_val(PS4_R1, 0);
    set_val(PS4_R3, 100);
    wait(COMBO_DELAY_TIME);
    set_val(PS4_R3, 0);
}
 
combo COMBO_QUICK_TURN {
    set_val(STICK_1_X, 100);
    wait(QUICK_TURN_DELAY);
    set_val(STICK_1_X, 0);
}
 
void output_keycode() {
    static uint8 previous_keycode;
    uint8 keycode;
 
    keycode = key_check();
    if(keycode != previous_keycode) {
        if(keycode) {
            printf("Key Code: %02X", keycode);
        }
        previous_keycode = keycode;
    }
    return;
}
 
// DOUBLE_TAP
// uses absolute values, be careful not to trigger on quick back and forth stick input
// Thanks to tRiKy for suggesting the hold button idea
bool DOUBLE_TAP(uint8 input_button) {
    // Sanatize input
    if( input_button >= DT_MAX_BUTTON) { return FALSE; }
 
    // Grab absolute value of input button
    int32 button_value = (int32) abs(get_val(input_button));
 
    // Detect Double-Tap
    if(DT_BUTTON_STATE[input_button] == 0) {
        // Wait for initial press of button to advance state machine
        if(button_value >= 90) {
            DT_BUTTON_STATE[input_button] = 1;
            DT_BUTTON_TIMING[input_button] = 0;
        }
 
    } else if(DT_BUTTON_STATE[input_button] == 1) {
        // Update counter
        DT_BUTTON_TIMING[input_button] = DT_BUTTON_TIMING[input_button] + elapsed_time();
 
        // Wait for initial button press to be released, reset counter
        // and advance state machine
        if(button_value <= 90) {
            DT_BUTTON_TIMING[input_button] = 0;
            DT_BUTTON_STATE[input_button] = 2;
        }
 
        // Check if button is being held longer than a second
        if(DT_BUTTON_TIMING[input_button] >= DT_HOLD_TIME ) { DT_BUTTON_STATE[input_button] = 3; }
 
    } else if(DT_BUTTON_STATE[input_button] == 2) {
        // Check to see if we double tapped button
        if(button_value >= 90) {
            DT_BUTTON_STATE[input_button] = 1;
            return TRUE;
        }
 
        // Update counter
        DT_BUTTON_TIMING[input_button] = DT_BUTTON_TIMING[input_button] + elapsed_time();
 
        // Check if we've waited too long
        if(DT_BUTTON_TIMING[input_button] >= DOUBLE_TAP_GAP) { DT_BUTTON_STATE[input_button] = 0; }
 
    } else if(DT_BUTTON_STATE[input_button] == 3) {
        // Button is being held, wait for button release to reset
        if(button_value <= 90) { DT_BUTTON_STATE[input_button] = 0; }
 
    } else {
        // default case
        DT_BUTTON_STATE[input_button] = 0;
 
    }
 
    return FALSE;
}
Attachments
R6 Siege script.gpc
(10.9 KiB) Downloaded 346 times
R6 Siege input.git
(177 Bytes) Downloaded 508 times
User avatar
TheBigKent
Private First Class
Private First Class
 
Posts: 2
Joined: Sat Jun 23, 2018 12:44 pm

Re: My Rainbow Six Siege script for keyboard & mouse users

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

:joia: :joia: Thank you for sharing with us.
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: My Rainbow Six Siege script for keyboard & mouse users

Postby jaxen27 » Mon Jul 04, 2022 10:41 pm

Is this still working? I cant seem to get it working
User avatar
jaxen27
Private First Class
Private First Class
 
Posts: 2
Joined: Mon Jul 04, 2022 10:33 pm


Return to User's Script Documentation

Who is online

Users browsing this forum: No registered users and 35 guests