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.02
AuthorEternalDahaka
Publish DateThu, 11 Feb 2021 - 01:15
Last UpdateWed, 3 Mar 2021 - 23:21
Downloads106
RATE


0

0

Release Notes: Added options to edit the mid point to customize a 2-part piece-wise linear curve. Improved precision with small stick movements which helps with deadzone and antideadzone calculations.
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  midPointX             = 50;     //Curve control.  Edit horizontal position of X-node.
int  midPointY             = 50;     //Curve control.  Edit vertical position of X-node.
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  midPointXA            = 50;
int  midPointYA            = 50;
int  uncapValuesA          = FALSE
 
//RIGHT STICK ALTERNATE 2 SETTINGS
int  deadZoneA2             = 0;
int  antiCircleDeadZoneA2   = 0;
int  antiSquareDeadZoneA2   = 0;
int  outerDeadZoneInA2      = 100;
int  outerDeadZoneOutA2     = 100;
int  midPointXA2            = 50;
int  midPointYA2            = 50;
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  midPointXL             = 50;     //Curve control.  Edit horizontal position of X-node.
int  midPointYL             = 50;     //Curve control.  Edit vertical position of X-node.
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  midPointXLA            = 50;
int  midPointYLA            = 50;
int  uncapValuesLA          = FALSE;
 
//LEFT STICK ALTERNATE 2 SETTINGS
int  deadZoneLA2            = 0;
int  antiCircleDeadZoneLA2  = 0;
int  antiSquareDeadZoneLA2  = 0;
int  outerDeadZoneInLA2     = 100;
int  outerDeadZoneOutLA2    = 100;
int  midPointXLA2           = 50;
int  midPointYLA2           = 50;
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;
int smallValue;
 
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, midPointXA, midPointYA, uncapValuesA, 1);
        }
        else if(get_val(useAlternate2) > 0){
            applyStick(deadZoneA2, antiCircleDeadZoneA2, antiSquareDeadZoneA2, outerDeadZoneInA2, outerDeadZoneOutA2, midPointXA2, midPointYA2, uncapValuesA2, 1);
        }
 
        else{
            applyStick(deadZone, antiCircleDeadZone, antiSquareDeadZone, outerDeadZoneIn, outerDeadZoneOut, midPointX, midPointY, 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, midPointXLA, midPointYLA, uncapValuesLA, 2);
        }
        else if(get_val(useAlternateL2) > 0){
            applyStick(deadZoneLA2, antiCircleDeadZoneLA2, antiSquareDeadZoneLA2, outerDeadZoneInLA2, outerDeadZoneOutLA2, midPointXLA2, midPointYLA2, uncapValuesLA2, 2);
        }
        else{
            applyStick(deadZoneL, antiCircleDeadZoneL, antiSquareDeadZoneL, outerDeadZoneInL, outerDeadZoneOutL, midPointXL, midPointYL, uncapValuesL, 2);
        }
        prevLX = currLX;
        prevLY = currLY;
    }
 
    set_val(XB1_LX, stickLX);
    set_val(XB1_LY, stickLY);
 
}
 
function applyStick(dead, antiCDead, antiSDead, outerDeadIn, outerDeadOut, midX, midY, 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);
 
    smallValue = 0;
 
    //precision
    if(magnitude <= 10){
        smallValue = 1;
 
        x = x*10;
        y = y*10;
        magnitude = isqrt(x*x + y*y);
    }
 
 
 
    if(smallValue == 0){
 
        //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)*(100))/(outerDeadIn - dead))//Converting to 0-100 range
 
            //Piece-wise curve customization
            if(outputMagnitude < midX ){
                outputMagnitude = (outputMagnitude*midY)/midX;
            }
            else{
                outputMagnitude = (((outputMagnitude - midX)*(100 - midY))/(100 - midX)) + midY;
            }
 
            //AntiDeadzone conversion
            outputMagnitude = (((outputMagnitude)*(outerDeadZoneOut - antiCDead))/(100)) + 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;
            }
        }
    }
 
///////////////////PRECISION//////////////////////
 
    else{
 
        //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*10){
            outputMagnitude = (((magnitude - dead*10)*(100))/(outerDeadIn - dead))//Converting to 0-1000 range
 
 
 
        //Piece-wise curve customization
        if(outputMagnitude < midX*10 ){
            outputMagnitude = (outputMagnitude*midY)/midX;
        }
        else{
            outputMagnitude = (((outputMagnitude - midX*10)*(1000 - midY))/(1000 - midX*10)) + midY*10;
        }
 
 
        //AntiDeadzone conversion 0 - 1000
        outputMagnitude = (((outputMagnitude)*(outerDeadZoneOut - antiCDead))/(100)) + (antiCDead*10);
 
        if(stick == 1){
           //set_val(XB1_B, normX/10);
        }       
 
            newX = ((normX/10)*outputMagnitude)/100;
            newY = ((normY/10)*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;
            }
        }
    }
 
 
}