
@name ACF ECU
@inputs Pod:wirelink RPM1 RPM2 RPM3 RPM4 RPM5 RPM6 RPM7 RPM8
@outputs Active Throttle Clutch Brake Gear
@outputs KMH MPH RightClutch LeftClutch RightBrake LeftBrake
@persist GearWait GearIn
@trigger
interval(100)
 
###Hello and welcome to my E2! please take a moment to read all the comments within setup lines 16-61.
###Make sure you set this e2 up properly for the vehicle you are going to be using it for.
###Any questions, concerns, requests or feedback please do not hesitate to ask.
###If you need to find me I play mostly only GGG servers (mostly Toshkent)
###LeftClutch, RightClutch and LeftBreak, RightBreak are for tanks only... wire only normal Clutch and Break if it is a car.
#______________________________________________________________________________________________________________________________________#
 
###Vehicle Max Speed (KPH), this is really the only part you will need to tweak a bit to get right simply use the wire debugger tool and debug-
#your gearbox, if you notice your gearbox going through the gears to fast make your MaxSpeed higher (NOTE: ONLY NEEDED FOR AUTO TRANSMISSION!)
#Speed is in KM/h (im a kiwi xD)
MaxSpeed=130
###EngineAmount is the number of ACF engines each individual chip is in control of.
###Be sure to wire all the RPM inputs of the chip to each individual engine!
EngineAmount=6
###ACF Engine RPM Values (look in ACF Engine Spawner menu for details on your motor!)
###Also if you are using multiple motors add up the totals for these values (if you are using two 1.8 i4 P with idle of 900 then Idle=1800)
Idle=900*EngineAmount
IdealMin=5400*EngineAmount
IdealMax=7000*EngineAmount
Redline=8000*EngineAmount
###Clutch Settings. Use a low value for smaller petrol engines (default 0.0025 I find is good for the 1.8L I4 Petrol.
###A much higher value for larger or diesel motors (a solid 1 will probably work fine for most large diesels.)
###This is the speed the clutch eases off after you dissengage it.
ClutchSensitivity=1
###Clutch Type "0" for Automatic Friction Hold Clutch Great for heavy vehicles or climbing (not reccomended for use with deisel!)
###Type "1" for Manual Clutch (Mouse2)
###Type "2" for Automatic stationary Take-off only clutch (The name says it all)
ClutchType=0
###Transmission Type "0" for Automatic, "1" for Sequential Manual.
###There is a third transmission type though I am still working on it read lines 213 and 214 for details and use only is regular auto
###is giving you trouble. Type "2" in the field below to use this unstable setup.
TransType=0
###TankSteer is a feature for steering tanks using dual clutch and brake setup
###Obviously it will only work for dual clutch gearboxes...
TankSteer=1
###ThrottleInc and ThrottleDec is the increase/Decrease amount per tick similar to ClutchSensitivity but for Throttle..
ThrottleInc=10
ThrottleDec=10
###BrakeInc and BrakeDec.. same scenario as throttleInc/Dec
BrakeInc=1
BrakeDec=1
###Maximum values pretty straigh forward.. if ThrottleMax is 80 the most the throttle will go to is 80... although there is no real need
###To reduce it below 100. Breaks spazz if they are over 20 so stay below 20!
###GearMax should be the number of gears you have... 6 Speed transmission = 6. EASY xD
BrakeMax=8
GearMax=6
ThrottleMax=100
###ThrottleMin is the opposite of throttle max, only use if you want to keep your vehicle constantly revving a little bit otherwise keep 0
ThrottleMin=0
###RPM, for multiple motors add a input RPM3, RPM4 etc for each motor and add "+RPM3" to the equation in the line below.
###Notice E2 is already set for 2 motors
RPM=RPM1+RPM2+RPM3+RPM4+RPM5+RPM6+RPM7+RPM8
###NO NEED TO TOUCH ANYTHING BEYOND THIS LINE, YOU ARE READY TO BURN SOME RUBBER!
###Speedometer.
Vel = entity():vel():length()
KMH = toUnit("km/h",Vel)
MPH = toUnit("mph",Vel)
###
GearChange = Pod["PrevWeapon",number] + Pod["NextWeapon",number]
###    
if(first()|dupefinished())
{
    Throttle=0
    GearIn=0
    Clutch=0
    Brake=0
    Active=0
}
 
if(Pod["Active",number])
{
    Active=1
 
###Throttle Control#
if(Pod["W",number]&Throttle<ThrottleMax){Throttle+=ThrottleInc}
elseif(!Pod["W",number]){Throttle-=ThrottleDec}
    if(Throttle>ThrottleMax){Throttle-=ThrottleInc}
    elseif(Throttle<ThrottleMin){Throttle+=ThrottleDec}
   
###Brake Control#
if(Pod["Space",number]&Brake<BrakeMax){Brake+=BrakeInc}
elseif(!Pod["Space",number]){Brake-=BrakeDec}
    if(Brake>BrakeMax){Brake-=BrakeInc}
    elseif(Brake<0){Brake+=BrakeDec}
 
###Manual Clutch Control#
if(ClutchType==1){
    interval(100)  
    if(Pod["Mouse2",number] & Clutch < 1){Clutch = 1}
    elseif(!Pod["Mouse2",number] & Clutch > 0){Clutch-=ClutchSensitivity}
}
 
###Automatic Friction Holding Clutch (Reccomended For Heavy Vehicles or Climbing.)
###Think of this feature as a Smashbox or "Dogbox" if you are into rally
elseif(ClutchType==0){
if(Gear<=2&KMH<10&inrange(RPM,Idle,IdealMin)){Clutch=1}
elseif(inrange(RPM,IdealMin,Redline)){Clutch-=ClutchSensitivity}
if(Clutch<0){Clutch+=ClutchSensitivity*10}
}
 
###Take-off only clutch
elseif(ClutchType==2){
    if(inrange(RPM,Idle,IdealMin*1.125)&inrange(KMH,0,10)){Clutch=1}
    elseif(Clutch>0){Clutch-=ClutchSensitivity}    
}
 
#                                                           ||
########Thanks Kickasskyle for ideas for this segment Below \/ (Manual Shifting for Manual Transmission)
 
if(TransType==1){
 
    if(!GearChange & GearWait){
        GearWait = 0
    }
   
   
   
    if(GearChange){
     
       #Neutral Shifting
        if(GearIn == 0 & !GearWait){
            if(Pod["PrevWeapon",number]){
                GearIn = 1
                GearWait = 1
         }
  }
            #GearIn 1 Shifting
        if(GearIn == 1 & !GearWait){
            if(Pod["PrevWeapon",number]){
                GearIn = 2
                GearWait = 1
          }
            if(Pod["NextWeapon",number]){
                GearIn = 0
                GearWait = 1
       }
        }
                #GearIn 2 Shifting
        if(GearIn == 2 & !GearWait){
            if(Pod["PrevWeapon",number]){
                GearIn = 3
                GearWait = 1
            }
            if(Pod["NextWeapon",number]){
                GearIn = 1
                GearWait = 1
            }
        }
   
            #GearIn 3 Shifting
        if(GearIn == 3 & !GearWait){
            if(Pod["PrevWeapon",number]){
                GearIn = 4
                GearWait = 1
            }
            if(Pod["NextWeapon",number]){
                GearIn = 2
                GearWait = 1
            }
        }
                    #GearIn 4 Shifting
        if(GearIn == 4 & !GearWait){
            if(Pod["PrevWeapon",number]){
                GearIn = 5
                GearWait = 1
            }
            if(Pod["NextWeapon",number]){
                GearIn = 3
                GearWait = 1
            }
        }
                    #GearIn 5 Shifting
        if(GearIn == 5 & !GearWait){
            if(Pod["PrevWeapon",number]){
                GearIn = 6
                GearWait = 1
            }
            if(Pod["NextWeapon",number]){
                GearIn = 4
                GearWait = 1
            }
        }
            #GearIn 6 Shifting
        if(GearIn == 6 & !GearWait){
            if(Pod["NextWeapon",number]){
                GearIn = 5
                GearWait = 1
            }
        }
    }
    if(GearIn == 0){
         Gear = 0
        }
    if(GearIn == 1){
         Gear = 1
        }
    if(GearIn == 2){
         Gear = 2
        }
    if(GearIn == 3){
         Gear = 3
        }
    if(GearIn == 4){
         Gear = 4
        }
    if(GearIn == 5){
         Gear = 5
        }
    if(GearIn == 6){
         Gear = 6
        }
}
########Thanks Kickasskyle for ideas for that segment ^^^^^  xD
 
###Auto Transmission Below.
elseif(TransType==0)
{
   
if(Clutch==1&Pod["W",number]){Gear = 1}
 
if(Gear==1&RPM>IdealMax&inrange(KMH,MaxSpeed*0.15,MaxSpeed*0.25)){Gear = 2}
if(Gear==2&RPM>IdealMax&inrange(KMH,MaxSpeed*0.25,MaxSpeed*0.40)){Gear = 3}elseif(RPM<IdealMin&Gear==3){Gear=2}
if(Gear==3&RPM>IdealMax&inrange(KMH,MaxSpeed*0.40,MaxSpeed*0.60)){Gear = 4}elseif(RPM<IdealMin&Gear==4){Gear=3}
if(Gear==4&RPM>IdealMax&inrange(KMH,MaxSpeed*0.60,MaxSpeed*0.80)){Gear = 5}elseif(RPM<IdealMin&Gear==5){Gear=4}
if(Gear==5&RPM>IdealMax&inrange(KMH,MaxSpeed*0.80,MaxSpeed*2)){Gear = 6}elseif(RPM<IdealMin&Gear==6){Gear=5}
 
    }
###This part though it is still partly an idea it is working to a small degree ;) but I reccomend for use only with higher revving settups
###Most typicaly small petrol motors, which is the reason I made this segment. I wouldnt use it unless you are having trouble with regular auto.
elseif(TransType==2)
{
   
if((Clutch==1)&Pod["W",number]){
    Gear = 1
}
if(inrange(RPM,IdealMin*1.2,Redline)&inrange(KMH,MaxSpeed*0.15,MaxSpeed*0.25)){
    Gear = 2
}elseif(inrange(RPM,Idle,Idle*3)&Gear==2){Gear=1}
if(inrange(RPM,IdealMin*1.2,Redline)&inrange(KMH,MaxSpeed*0.25,MaxSpeed*0.40)){
    Gear = 3
}elseif(inrange(RPM,Idle,Idle*3)&Gear==3){Gear=2}
if(inrange(RPM,IdealMin*1.2,Redline)&inrange(KMH,MaxSpeed*0.40,MaxSpeed*0.60)){
    Gear = 4
}elseif(inrange(RPM,Idle,Idle*3)&Gear==4){Gear=3}
if(inrange(RPM,IdealMin*1.2,Redline)&inrange(KMH,MaxSpeed*0.60,MaxSpeed*0.80)){
    Gear = 5
}elseif(inrange(RPM,Idle,Idle*3)&Gear==5){Gear=4}
if(inrange(RPM,IdealMin*1.2,Redline)&inrange(KMH,MaxSpeed*0.80,MaxSpeed*2)){
    Gear = 6
}elseif(inrange(RPM,Idle,Idle*3)&Gear==6){Gear=5}
       }
###Dual Clutch steering system for mainly tanks
if(TankSteer==1){
 if(Pod["D",number]){LeftBrake=BrakeMax, LeftClutch=1, Throttle=100}  
    elseif(!Pod["D",number]){LeftClutch-=ClutchSensitivity*1.5, LeftBrake=0}
   
     if(Pod["A",number]){RightBrake=BrakeMax, RightClutch=1, Throttle=100}  
    elseif(!Pod["A",number]){RightClutch-=ClutchSensitivity*1.5, RightBrake=0}
 
 
}
###
}
###This little part just tells the motor and gearbox to pretty much turn off if you are not sitting in your pod.
else{
Active=0
Throttle=0
Brake=10
Gear=0
Clutch=0
}
 
 
###This segment is just to keep throttle, clutch break etc within its desired parameters
if(Throttle>ThrottleMax){Throttle-=ThrottleInc}
elseif(Throttle<ThrottleMin){Throttle-=ThrottleDec}
if(LeftBrake>BrakeMax){LeftBrake-=BrakeInc}
elseif(LeftBrake<0){LeftBrake+=BrakeDec}
if(RightBrake>BrakeMax){RightBrake-=BrakeInc}
elseif(RightBrake<0){RightBrake+=BrakeDec}
if(LeftClutch>1){LeftClutch-=ClutchSensitivity}
elseif(LeftClutch<0){LeftClutch+=ClutchSensitivity}
if(RightClutch>1){RightClutch-=ClutchSensitivity}
elseif(RightClutch<0){RightClutch+=ClutchSensitivity}
