FBMrider86's Forza/G27 MaxAimDI Script (w/ Fully Operational Clutch)

This code changes some of the typically seen settings for the G27 and Forza games to include as many functions native to the game(s) as possible. - YOU MUST USE Controller Layout 10 for this script to function properly, DO NOT USE Layout 4/6!!! - Script has been fully tested utilizing Forza 4 (XB360) and Forza 5 (XB1). Features Include: -Adjustable steering deadzone ( controllable via 'wheelSlop' variable ) -Fully managed Brake and Accelerator pedals -FULLY FUNCTIONAL Clutch Pedal (no longer an 'on/off' button, it is now mapped to an appropriate axis, allowing for a more realistic take off and proper clutch 'slipping'. -Fully working six speed H-pattern shifter (utilizing J2Kbr's shifter code) -Fully working Emergency Brake (mapped to Button 4) - Now complete with J-turns! -EXTRA: "Line Lock" function - Allows for a certain amount of brake to be applied at the press of a single button (mimics the usage of an actual line-lock in drag racing, which locks the front brakes but allows the rear wheels to spin up and burnout). This is also fully adjustable, from 0 to 100% of braking applied during its activation. To find the appropriate layout please visit the ConsoleTuner forums and look for my thread in the 'Steering Wheel Setups' sub-forum. Enjoy!
Version2.01
Authorfbmrider86
Publish DateThu, 26 Feb 2015 - 04:19
Last UpdateSun, 1 Mar 2015 - 20:42
Downloads5614
RATE


4

1

Release Notes: Minor change to line lock function/flow. Screen will no longer switch between the standard and "detailed" HUD when pressing Up or Down while holding the line lock button.
Code: Select all
/* 
   *****************************************************************************
   *****************************************************************************
   ******        Forza 4/5/Horizon/Horizon 2 - G27 MaxAimDI Script        ******
   ******                  Code written by:  FBMrider86                   ******
   ******    Contains code sourced from: J2Kbr (H pattern shifter code)   ******
   ******  Contains code sourced from: KittyDawn (steering deadzone code) ******
   *****************************************************************************
   *****************************************************************************
 
   *****************************************************************************
   ********************************  IMPORTANT  ********************************
   *****************************************************************************
   *****************************************************************************
   ***                                                                       ***
   **  You must utilize Controller Layout 10 for this code to work properly!  **
   ***                                                                       ***
   *****************************************************************************
   *****************************************************************************
   *****************************************************************************
   *****************************************************************************
 
   - This code changes some of the typically seen settings for the G27 and Forza games
     to include as many functions native to the game(s) as possible.
   - YOU MUST USE Controller Layout 10 for this script to function properly, DO NOT USE Layout 4/6!!!
   - Script has been fully tested utilizing Forza 4 (XB360) and Forza 5 (XB1). 
   - Features Include:
 
   *****************************************************************************************************
   *  * Adjustable steering deadzone ( controllable via 'wheelSlop' variable )                           *
   *  * Fully managed Brake and Accelerator pedals                                                       *
   *  * FULLY FUNCTIONAL Clutch Pedal (no longer an 'on/off' button, it is now mapped to                *
   *    an appropriate axis, allowing for a more realistic take off and proper                           *
   *    clutch 'slipping'.                                                                               *               
   *  * Fully working six speed H-pattern shifter (utilizing J2Kbr's shifter code)                       *
   *  * Fully working Emergency Brake (mapped to Button 4) - Now complete with J-turns!                   *
   *  * EXTRA: "Line Lock" function - Allows for a certain amount of brake to be applied               *
   *    at the press of a single button (mimics the usage of an actual line-lock in drag racing,       *
   *    which locks the front brakes but allows the rear wheels to spin up and burnout).               *
   *    This is also fully adjustable, from 0 to 100% of braking applied during its activation.        *
   *****************************************************************************************************
*/

 
int prev_gear, loop_gear;  // utilized by J2Kbr's shifter code
int wheelSlop = 8// accounts for slop in steering wheel (deadzone) : 0 would be NO dead zone (very twitchy)
int eBrake = 0;
int lineLockActivation = 0;
int brakePerc = 20// default is 20 ; utilized by Line Lock function
 
main
{
    // Steering Dead Zone Adjustment
    if(get_val(XB360_LX) < inv(wheelSlop) )
        set_val(XB360_LX, ((get_val(XB360_LX) * 7) / 9) - 23);
 
    else if( get_val( XB360_LX ) > wheelSlop )
        set_val( XB360_LX , (( get_val( XB360_LX ) * 7) / 9) + 23);
 
    else
        set_val( XB360_LX, get_val (XB360_LX ) );
 
    // END: Steering Dead Zone Adjustment
 
    // Pedal Manager:  Contains code to maintain Clutch, Accelerator and Brake Pedals
    pedalManager();
 
    // Line Lock - Button-activated braking; useful for burnouts - Mapped to Button 3
    lineLock();
 
    deactivateBtns();
 
    // Shifter Manager:  Contains code to manage 6-speed shifter
    shifterManager();
}
 
combo gearDOWN // Written by: J2Kbr
{
    set_val(XB360_LB, 100);
    wait(50);
    set_val(XB360_LB, 0);
    wait(40);
    set_val(XB360_LB, 0);
}
 
combo gearUP // Written by: J2Kbr
{
    set_val(XB360_RB, 100);
    wait(50);
    set_val(XB360_RB, 0);
    wait(40);
    set_val(XB360_RB, 0);
}
 
 
function deactivateBtns()  // Essentially 'deactivates' these inputs by not allowing the controller to change their value as we're utilizing their inputs elsewhere in the script.
{
    set_val(XB360_LS,0);
    set_val(XB360_RS,0);
    set_val(XB360_LY,0);
    set_val(XB360_RX,0);   
 
    // added 3/1/2015: when line lock is active, disable the usage of up and down buttons in the game itself (avoids the constant switching between standard and detailed info. display)
    if( lineLockActivation == 1 )
    {
            set_val( XB360_UP, 0);
            set_val( XB360_DOWN, 0);
    }
}
 
function pedalManager() // Properly addresses Accelerator, Brake, and Clutch (and Emergency Brake)
{   
    // Accelerator Pedal
    set_val(XB360_RT, inv((get_val(XB360_RX))/2) + 50);
 
    // Brake Pedal
    set_val(XB360_LT, inv((get_val(XB360_LY))/2) + 50);
 
    // Emergency Brake - Map using CEMU_EXTRA9
    if( event_press( CEMU_EXTRA9) )  // EBrake and Clutch are on same Axis, must check for button press first
    {
        eBrake = 1;
    }
    if (event_release (CEMU_EXTRA9) )
        eBrake = 0;
 
    // Clutch Pedal - Check to see if E Brake has been activated first
    if( eBrake == 0 )
    {
        // Clutch and E Brake share the right analog stick's Y axis
        if(get_val(XB360_RY) < 0)
            set_val(XB360_RY, (get_val(XB360_RY)/2)-50);
        else if(get_val(XB360_RY) >= 0)
            set_val(XB360_RY, (get_val(XB360_RY)-100)/2);
    }
    // Activate Emergency Brake
    else
        set_val(XB360_RY, 100);
}
 
function lineLock() // Burnouts!
{
    // Line Lock - Applies braking force to vehicle (default is 20%) ; mapped to Button 3 on shifter
    //               Braking force is adjustable while Line Lock button is activated/pressed.
    //             Pressing Up on D-Pad while activated increases braking effectiveness.
    //               Pressing Down on D-Pad while activated decreases braking effectiveness.
    //             Pressing Button 1 while activated will reset the line lock to default of 20%
    //             Default: 20 ; Minimum: 0 ; Maximum : 100
 
    if( event_press( XB360_RS) )
        lineLockActivation = 1;
    if( event_release( XB360_RS) )
        lineLockActivation = 0;
 
    if( lineLockActivation == 1 )
    {
        if( event_press( XB360_UP) && brakePerc < 100 )
            brakePerc = brakePerc + 1;
        if( event_press( XB360_DOWN) && brakePerc > 0 )
            brakePerc = brakePerc - 1;
        if( event_press( XB360_LS) )
            brakePerc = 20;
 
        set_val(XB360_LT, brakePerc);
 
    }
 
}
 
function shifterManager() // Written by: J2Kbr
{
    // Reverse
    if( event_press(CEMU_EXTRA1) )
        loop_gear = loop_gear + 1 - prev_gear;
    else if( event_release(CEMU_EXTRA1 ))
        prev_gear = 1;
 
    // 1st Gear
    if( event_press(CEMU_EXTRA2) )
        loop_gear = loop_gear + 2 - prev_gear;
    else if( event_release(CEMU_EXTRA2) )
        prev_gear = 2;
 
    // 2nd Gear
    if( event_press(CEMU_EXTRA3) )
        loop_gear = loop_gear + 3 - prev_gear;
    else if( event_release(CEMU_EXTRA3) )
        prev_gear = 3;
 
    // 3rd Gear
    if( event_press(CEMU_EXTRA4) )
        loop_gear = loop_gear + 4 - prev_gear;
    else if( event_release(CEMU_EXTRA4) )
        prev_gear = 4;
 
    // 4th Gear
    if( event_press(CEMU_EXTRA5) )
        loop_gear = loop_gear + 5 - prev_gear;
    else if( event_release(CEMU_EXTRA5) )
        prev_gear = 5;
 
    // 5th Gear
    if( event_press(CEMU_EXTRA6) )
        loop_gear = loop_gear + 6 - prev_gear;
    else if( event_release(CEMU_EXTRA6) )
        prev_gear = 6;
 
    // 6th Gear
    if( event_press(CEMU_EXTRA7) )
        loop_gear = loop_gear + 7 - prev_gear;
    else if( event_release(CEMU_EXTRA7) )
        prev_gear = 7;
 
    // Press the LB or RB button to change the gear based on H-Shifter
    if(!combo_running(gearUP) && !combo_running(gearDOWN))
    {
        if(loop_gear > 0)
        {
            loop_gear = loop_gear - 1;
            combo_run(gearUP);
        }
        else if(loop_gear < 0)
        {
            loop_gear = loop_gear + 1;
            combo_run(gearDOWN);
        }
    }
}