Advertisement
Guest User

Untitled

a guest
Mar 21st, 2018
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.28 KB | None | 0 0
  1. --Deadzone Adjust
  2. local _PPH = _Tune.Peripherals
  3. for i,v in pairs(_PPH) do
  4. local a = Instance.new("IntValue",Controls)
  5. a.Name = i
  6. a.Value = v
  7. a.Changed:connect(function()
  8. a.Value=math.min(100,math.max(0,a.Value))
  9. _PPH[i] = a.Value
  10. end)
  11. end
  12.  
  13. --Input Handler
  14. function DealWithInput(input,IsRobloxFunction)
  15. if (UserInputService:GetFocusedTextBox()==nil) and not _InControls then --Ignore when UI Focus
  16. --Shift Down [Manual Transmission]
  17. if _IsOn and (input.KeyCode ==_CTRL["ContlrShiftDown"] or (_MSteer and input.KeyCode==_CTRL["MouseShiftDown"]) or ((not _MSteer) and input.KeyCode==_CTRL["ShiftDown"])) and (_TMode=="Semi" or (_TMode=="Manual" and (not _ClutchOn))) and input.UserInputState == Enum.UserInputState.Begin then
  18. if _CGear == 0 and (_TMode=="Auto" or not _ClPressing) then _ClutchOn = true end
  19. _CGear = math.max(_CGear-1,-1)
  20.  
  21. --Shift Up [Manual Transmission]
  22. elseif _IsOn and (input.KeyCode ==_CTRL["ContlrShiftUp"] or (_MSteer and input.KeyCode==_CTRL["MouseShiftUp"]) or ((not _MSteer) and input.KeyCode==_CTRL["ShiftUp"])) and (_TMode=="Semi" or (_TMode=="Manual" and (not _ClutchOn))) and input.UserInputState == Enum.UserInputState.Begin then
  23. if _CGear == 0 and (_TMode=="Auto" or not _ClPressing) then _ClutchOn = true end
  24. _CGear = math.min(_CGear+1,#_Tune.Ratios-2)
  25.  
  26. --Toggle Clutch
  27. elseif _IsOn and (input.KeyCode ==_CTRL["ContlrClutch"] or (_MSteer and input.KeyCode==_CTRL["MouseClutch"]) or ((not _MSteer) and input.KeyCode==_CTRL["Clutch"])) and _TMode=="Manual" then
  28. if input.UserInputState == Enum.UserInputState.Begin then
  29. _ClutchOn = false
  30. _ClPressing = true
  31. elseif input.UserInputState == Enum.UserInputState.End then
  32. _ClutchOn = true
  33. _ClPressing = false
  34. end
  35.  
  36. --Toggle PBrake
  37. elseif _IsOn and input.KeyCode ==_CTRL["ContlrPBrake"] or (_MSteer and input.KeyCode==_CTRL["MousePBrake"]) or ((not _MSteer) and input.KeyCode==_CTRL["PBrake"]) then
  38. if input.UserInputState == Enum.UserInputState.Begin then
  39. _PBrake = not _PBrake
  40. elseif input.UserInputState == Enum.UserInputState.End then
  41. if car.DriveSeat.Velocity.Magnitude>5 then
  42. _PBrake = false
  43. end
  44. end
  45.  
  46. --Toggle Transmission Mode
  47. elseif (input.KeyCode == _CTRL["ContlrToggleTMode"] or input.KeyCode==_CTRL["ToggleTransMode"]) and input.UserInputState == Enum.UserInputState.Begin then
  48. local n=1
  49. for i,v in pairs(_Tune.TransModes) do
  50. if v==_TMode then n=i break end
  51. end
  52. n=n+1
  53. if n>#_Tune.TransModes then n=1 end
  54. _TMode = _Tune.TransModes[n]
  55.  
  56. --Throttle
  57. elseif _IsOn and ((not _MSteer) and (input.KeyCode==_CTRL["Throttle"] or input.KeyCode == _CTRL["Throttle2"])) or ((((_CTRL["MouseThrottle"]==Enum.UserInputType.MouseButton1 or _CTRL["MouseThrottle"]==Enum.UserInputType.MouseButton2) and input.UserInputType == _CTRL["MouseThrottle"]) or input.KeyCode == _CTRL["MouseThrottle"])and _MSteer) then
  58. if input.UserInputState == Enum.UserInputState.Begin then
  59. _GThrot = 1
  60. else
  61. _GThrot = _Tune.IdleThrottle/100
  62. end
  63.  
  64. --Brake
  65. elseif ((not _MSteer) and (input.KeyCode==_CTRL["Brake"] or input.KeyCode == _CTRL["Brake2"])) or ((((_CTRL["MouseBrake"]==Enum.UserInputType.MouseButton1 or _CTRL["MouseBrake"]==Enum.UserInputType.MouseButton2) and input.UserInputType == _CTRL["MouseBrake"]) or input.KeyCode == _CTRL["MouseBrake"])and _MSteer) then
  66. if input.UserInputState == Enum.UserInputState.Begin then
  67. _GBrake = 1
  68. else
  69. _GBrake = 0
  70. end
  71.  
  72. --Steer Left
  73. elseif (not _MSteer) and (input.KeyCode==_CTRL["SteerLeft"] or input.KeyCode == _CTRL["SteerLeft2"]) then
  74. if input.UserInputState == Enum.UserInputState.Begin then
  75. _GSteerT = -1
  76. _SteerL = true
  77. else
  78. if _SteerR then
  79. _GSteerT = 1
  80. else
  81. _GSteerT = 0
  82. end
  83. _SteerL = false
  84. end
  85.  
  86. --Steer Right
  87. elseif (not _MSteer) and (input.KeyCode==_CTRL["SteerRight"] or input.KeyCode == _CTRL["SteerRight2"]) then
  88. if input.UserInputState == Enum.UserInputState.Begin then
  89. _GSteerT = 1
  90. _SteerR = true
  91. else
  92. if _SteerL then
  93. _GSteerT = -1
  94. else
  95. _GSteerT = 0
  96. end
  97. _SteerR = false
  98. end
  99.  
  100. --Toggle Mouse Controls
  101. elseif input.KeyCode ==_CTRL["ToggleMouseDrive"] then
  102. if input.UserInputState == Enum.UserInputState.End then
  103. _MSteer = not _MSteer
  104. _GThrot = _Tune.IdleThrottle/100
  105. _GBrake = 0
  106. _GSteerT = 0
  107. _ClutchOn = true
  108. end
  109.  
  110. --Toggle TCS
  111. elseif _Tune.TCSEnabled and _IsOn and input.KeyCode == _CTRL["ToggleTCS"] or input.KeyCode == _CTRL["ContlrToggleTCS"] then
  112. if input.UserInputState == Enum.UserInputState.End then
  113. _TCS = not _TCS
  114. end
  115.  
  116. --Toggle ABS
  117. elseif _Tune. ABSEnabled and _IsOn and input.KeyCode == _CTRL["ToggleABS"] or input.KeyCode == _CTRL["ContlrToggleABS"] then
  118. if input.UserInputState == Enum.UserInputState.End then
  119. _ABS = not _ABS
  120. end
  121. end
  122.  
  123. --Variable Controls
  124. if input.UserInputType.Name:find("Gamepad") then
  125. --Gamepad Steering
  126. if input.KeyCode == _CTRL["ContlrSteer"] then
  127. if input.Position.X>= 0 then
  128. local cDZone = math.min(.99,_Tune.Peripherals.ControlRDZone/100)
  129. if math.abs(input.Position.X)>cDZone then
  130. _GSteerT = (input.Position.X-cDZone)/(1-cDZone)
  131. else
  132. _GSteerT = 0
  133. end
  134. else
  135. local cDZone = math.min(.99,_Tune.Peripherals.ControlLDZone/100)
  136. if math.abs(input.Position.X)>cDZone then
  137. _GSteerT = (input.Position.X+cDZone)/(1-cDZone)
  138. else
  139. _GSteerT = 0
  140. end
  141. end
  142.  
  143. --Gamepad Throttle
  144. elseif _IsOn and input.KeyCode == _CTRL["ContlrThrottle"] then
  145. _GThrot = math.max(_Tune.IdleThrottle/100,input.Position.Z)
  146.  
  147. --Gamepad Brake
  148. elseif input.KeyCode == _CTRL["ContlrBrake"] then
  149. _GBrake = input.Position.Z
  150. end
  151. end
  152. else
  153. _GThrot = _Tune.IdleThrottle/100
  154. _GSteerT = 0
  155. _GBrake = 0
  156. if _CGear~=0 then _ClutchOn = true end
  157. end
  158. end
  159. UserInputService.InputBegan:connect(DealWithInput)
  160. UserInputService.InputChanged:connect(DealWithInput)
  161. UserInputService.InputEnded:connect(DealWithInput)
  162.  
  163.  
  164.  
  165. --[[Drivetrain Initialize]]
  166.  
  167. local Drive={}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement