Advertisement
FartNebuleuse

Gmod_Tank_Ecu_E2

Nov 25th, 2022
558
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.50 KB | None | 0 0
  1. @name Tank ECU by AstalNeker<3
  2. @inputs Engine:array Wheel:array Differential:array Baseplate:entity Brake W S A D
  3. @outputs Gear
  4.  
  5. @persist MaxBrakeForce Speed RearGear FrontGear
  6.  
  7. if(first()) {
  8.     #------------Settings
  9.     MaxBrakeForce = 700
  10.     RearGear = 6
  11.     FrontGear = 1
  12. }
  13.  
  14. interval(100)
  15.  
  16.  
  17. #----Control gear
  18. foreach(J, E:entity = Engine) {
  19.     E:acfThrottle((W+S+A+D) * 100)
  20.    
  21.     if(W || A || D) {
  22.         foreach(I, E:entity = Differential) {
  23.             Gear = FrontGear
  24.         }
  25.     }
  26.     if(S) {
  27.         foreach(I, E:entity = Differential) {
  28.             Gear = RearGear
  29.         }
  30.     }
  31. }
  32.  
  33. #----Control braking/ABS
  34. Speed = round(toUnit("km/h",Baseplate:vel():length()),1)
  35. if(Brake) {
  36.     foreach(I, E:entity = Differential) {
  37.         for(X=1, Wheel:count()) {
  38.             E:acfClutch(1)
  39.             if(abs(Wheel[X,entity]:angVel():pitch()/6) <= 40) {
  40.                 E:acfBrake(0)
  41.             }
  42.             else{
  43.                 E:acfBrake(Brake*MaxBrakeForce)
  44.             }
  45.            
  46.             if(Speed < 10) {
  47.                 E:acfBrake((Brake*MaxBrakeForce) * 0.7)
  48.             }
  49.         }
  50.     }
  51. }
  52. else{
  53.     #Reset the braking and Turn controller
  54.     foreach(I, E:entity = Differential) {
  55.         E:acfBrake(0)
  56.         E:acfClutch(0)
  57.  
  58.         if(D) {
  59.             E:acfClutchLeft(1)
  60.             E:acfBrakeLeft(1*MaxBrakeForce)
  61.         }
  62.         if(A) {
  63.             E:acfClutchRight(1)
  64.             E:acfBrakeRight(1*MaxBrakeForce)
  65.         }
  66.     }
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement