Deadzone and Antideadzone

This script will let you set deadzones and counter a game's deadzone. If a game uses a square deadzone you can counter that and use the deadZone value to set up your own circular one of preferred size. Current Options: deadZone, antiCircleDeadZone, antiSquareDeadZone, outerDeadZoneIn, outerDeadZoneOut, uncapValues, useAlternate, useAlternate2. Offers options for both sticks.
Version1.01
AuthorEternalDahaka
Publish DateThu, 11 Feb 2021 - 01:15
Last UpdateSat, 20 Feb 2021 - 04:41
Downloads57
RATE


0

0

Release Notes: Added modifier options to use alternate settings when a button is held down.
Code: Select all
/*DEADZONE AND ANTIDEADZONE*/
 
//This script will let you set a circular deadzone, counter circular and square
//deadzones, and set inner and outer deadzones.
//Note: The circular antideadzone is relative to the remaining range of the
//square antideadzone.  I.E, both at 50 will give you a 75 antideadzone, since
//25 is half of the remaining 50. 
//Use values 0 to 100.  Avoid using deadzones/antideadzones larger than the
//outerdeadzones.
 
//A simpler conversion of the TitanTwo script, using previous fixes from ME/DontAtMe.
 
//https://www.desmos.com/calculator/ofrurlpwox
//Graph demonstration on the output values(using 0-1 instead of 0 -100).
//The other values are exclusive to the TitanTwo version.
 
 
//CHANGE THESE VALUES
 
//RIGHT STICK SETTINGS
int  deadZone              = 0;      //Set the circular deadzone the player wants to use
int  antiCircleDeadZone    = 0;      //Set the value of the game's circular deadzone the player wishes to counter
int  antiSquareDeadZone    = 0;      //The value of the game's square deadzone the player wishes to counter
int  outerDeadZoneIn       = 100;    //The value that the play will input that will be considered 100% stick tilt
int  outerDeadZoneOut      = 100;    //The maximum value that will be output to the game
int  uncapValues           = FALSE//Allows diagonal values to exceed the outerDeadZoneOut distance
                                     //set to TRUE if unable to trigger maximum game movements
int  useAlternate          = 30;     //Choose to use alternate settings when a button is held down.  Use the identifier
int  useAlternate2         = 30;     //value of the button.  This can be found in Help > GPC Language Reference >
                                     //Device API > API Reference at the bottom.
 
//RIGHT STICK ALTERNATE SETTINGS
int  deadZoneA             = 0;
int  antiCircleDeadZoneA   = 0;
int  antiSquareDeadZoneA   = 0;
int  outerDeadZoneInA      = 100;
int  outerDeadZoneOutA     = 100;
int  uncapValuesA          = FALSE
 
//RIGHT STICK ALTERNATE 2 SETTINGS
int  deadZoneA2             = 0;
int  antiCircleDeadZoneA2   = 0;
int  antiSquareDeadZoneA2   = 0;
int  outerDeadZoneInA2      = 100;
int  outerDeadZoneOutA2     = 100;
int  uncapValuesA2          = FALSE;                                     
 
 
//````````````````````````````````````````````//
 
//LEFT STICK SETTINGS
int  deadZoneL              = 0;      //Set the circular deadzone the player wants to use
int  antiCircleDeadZoneL    = 0;      //Set the value of the game's circular deadzone the player wishes to counter
int  antiSquareDeadZoneL    = 0;      //The value of the game's square deadzone the player wishes to counter
int  outerDeadZoneInL       = 100;    //The value that the play will input that will be considered 100% stick tilt
int  outerDeadZoneOutL      = 100;    //The maximum value that will be output to the game
int  uncapValuesL           = FALSE//Allows diagonal values to exceed the outerDeadZoneOut distance
                                      //set to TRUE if unable to trigger maximum game movements
int  useAlternateL          = 30;     //Choose to use alternate settings when a button is held down.  Use the identifier
int  useAlternateL2         = 30;     //value of the button.  This can be found in Help > GPC Language Reference >
                                      //Device API > API Reference at the bottom.
 
//LEFT STICK ALTERNATE SETTINGS
int  deadZoneLA             = 0;
int  antiCircleDeadZoneLA   = 0;
int  antiSquareDeadZoneLA   = 0;
int  outerDeadZoneInLA      = 100;
int  outerDeadZoneOutLA     = 100;
int  uncapValuesLA          = FALSE;
 
//LEFT STICK ALTERNATE 2 SETTINGS
int  deadZoneLA2            = 0;
int  antiCircleDeadZoneLA2  = 0;
int  antiSquareDeadZoneLA2  = 0;
int  outerDeadZoneInLA2     = 100;
int  outerDeadZoneOutLA2    = 100;
int  uncapValuesLA2         = FALSE;
 
 
 
 
 
int x, y, newX, newY, outputX, outputY;
int magnitude, outputMagnitude;
int normX, normY;
 
int currRX, currRY;
int prevRX, prevRY;
int currLX, currLY;
int prevLX, prevLY;
 
int stickRX, stickRY;
int stickLX, stickLY;
 
main {
 
 
    //Apply Right Stick
    currRX = get_val(XB1_RX);
    currRY = get_val(XB1_RY);
    if(prevRX != currRX || prevRY != currRY){
 
        if(get_val(useAlternate) > 0){
            applyStick(deadZoneA, antiCircleDeadZoneA, antiSquareDeadZoneA, outerDeadZoneInA, outerDeadZoneOutA, uncapValuesA, 1);
        }
        else if(get_val(useAlternate2) > 0){
            applyStick(deadZoneA2, antiCircleDeadZoneA2, antiSquareDeadZoneA2, outerDeadZoneInA2, outerDeadZoneOutA2, uncapValuesA2, 1);
        }
 
        else{
            applyStick(deadZone, antiCircleDeadZone, antiSquareDeadZone, outerDeadZoneIn, outerDeadZoneOut, uncapValues, 1);
        }
 
        prevRX = currRX;
        prevRY = currRY;
    }
 
    set_val(XB1_RX, stickRX);
    set_val(XB1_RY, stickRY);
 
 
    //Apply Left Stick
    currLX = get_val(XB1_LX);
    currLY = get_val(XB1_LY);
    if(prevLX != currLX || prevLY != currLY){
 
        if(get_val(useAlternateL) > 0){
            applyStick(deadZoneLA, antiCircleDeadZoneLA, antiSquareDeadZoneLA, outerDeadZoneInLA, outerDeadZoneOutLA, uncapValuesLA, 2);
        }
        else if(get_val(useAlternateL2) > 0){
            applyStick(deadZoneLA2, antiCircleDeadZoneLA2, antiSquareDeadZoneLA2, outerDeadZoneInLA2, outerDeadZoneOutLA2, uncapValuesLA2, 2);
        }
        else{
            applyStick(deadZoneL, antiCircleDeadZoneL, antiSquareDeadZoneL, outerDeadZoneInL, outerDeadZoneOutL, uncapValuesL, 2);
        }
        prevLX = currLX;
        prevLY = currLY;
    }
 
    set_val(XB1_LX, stickLX);
    set_val(XB1_LY, stickLY);
 
}
 
function applyStick(dead, antiCDead, antiSDead, outerDeadIn, outerDeadOut, uncap, stick){
 
    if(stick == 1){
        x = get_val(XB1_RX);
        y = get_val(XB1_RY);
    }
    else{
        x = get_val(XB1_LX);
        y = get_val(XB1_LY);
    }
 
    magnitude = isqrt(x*x + y*y);   
 
    //Increasing antiCircleDeadZone to counter shrinkage with antiSquareDeadzone scaling below
    antiCDead = (antiCDead*((antiCDead*(100 - antiSDead))/((antiCDead*(100 - (antiSDead*100)/outerDeadOut))/100)) )/100;
 
    normX = (x*100)/magnitude;
    normY = (y*100)/magnitude;
 
    if(uncapValues == FALSE){
        if(magnitude > outerDeadIn){magnitude = outerDeadIn};
    }
 
    //DeadZone and antiCircleDeadZone scaling
    outputMagnitude = 0;
    if(magnitude > dead){
        outputMagnitude = ((magnitude - dead)*(outerDeadOut - antiCDead))/(outerDeadIn - dead) + antiCDead;
 
        newX = (normX*outputMagnitude)/100;
        newY = (normY*outputMagnitude)/100;
 
        //antiSquareDeadZone scaling
        outputX = (abs(newX)*(100 - (antiSDead*100)/outerDeadOut))/100 + antiSDead;
        if(x < 0){outputX = outputX*(-1)};
        if(x == 0){outputX = 0;}
 
        outputY = (abs(newY)*(100 -(antiSDead*100)/outerDeadOut))/100 + antiSDead;
        if(y < 0){outputY = outputY*(-1)};
        if(y == 0){outputY = 0;}
 
        if(stick == 1){
            stickRX = outputX;
            stickRY = outputY;
        }
        else{
            stickLX = outputX;
            stickLY = outputY;
        }
 
    }
    else{
        if(stick == 1){
            stickRX = 0;
            stickRY = 0;
        }
        else{
            stickLX = 0;
            stickLY = 0;
        }
    }
}