Released Simple cruise Control

Discussion in 'Utilities and programming' started by Incognito, Aug 8, 2013.

  1. Incognito

    Incognito
    Expand Collapse

    Joined:
    Aug 4, 2013
    Messages:
    246
    Instruction:
    1. Open game_folder\lua\vehicle\input.lua
    2. After:
      Code:
      local padOutRate = 2.5
      add (with a new line):
      Code:
      cruiseControl = 0
    3. After:
      Code:
      -- map the values
      add (with a new line):
      Code:
          -- simple cruise control
          local maxBrake    = 1
          local maxThrottle = 1
          local carSpeed = math.floor( obj:getVelocity():length() * 2.23694 ) -- getting car speed, in mph
          if ( carSpeed > cruiseControl and cruiseControl ~= 0 ) then -- if carSpeed > cruiseControl = disable acceleration
              --M.throttle = 0
              input.event("axisy0", 0, 2)
              if carSpeed - cruiseControl >= 5 then
                  local newBrake = ( carSpeed - cruiseControl ) / 5
                  if ( newBrake > maxBrake ) then
                      --M.brake = maxBrake
                      input.event("axisy1", maxBrake, 2)
                  else
                      --M.brake = newBrake
                      input.event("axisy1", newBrake, 2)
                  end
              end
          elseif ( carSpeed < cruiseControl and cruiseControl ~= 0 ) then -- if carSpeed < cruiseControl = enable acceleration
              local newThrottle = ( cruiseControl - carSpeed ) / 5
              if ( newThrottle > maxThrottle ) then
                  --M.throttle = maxThrottle
                  input.event("axisy0", maxThrottle, 2)
              else
                  --M.throttle = newThrottle
                  input.event("axisy0", newThrottle, 2)
              end
              --M.brake = 0
              input.event("axisy1", 0, 2)
          end
          -- simple cruise control
    4. After the "end" of the "update" function (line 128) add (with a new line):
      Code:
      -- simple cruise control
      local function setCruiseControl()
          local carSpeed = math.floor( obj:getVelocity():length() * 2.23694 ) -- getting car speed, in mph
          if ( cruiseControl == 0 ) then
              cruiseControl = carSpeed
          else
              cruiseControl = 0
          end
          print( "Cruise control set = " .. cruiseControl .. " mph"  )
      end
      -- simple cruise control
    5. After:
      Code:
      M.toggleEvent = toggleEvent
      add (with a new line):
      Code:
      M.setCruiseControl = setCruiseControl
    6. Open your inputmap file and put this somewhere, then change "key_name" to the desired key:
      Code:
      %mm.bindVLuaCmd(keyboard, "key_name", "input.setCruiseControl()", "");

    So, when you press "key_name" - enable cruise control, after second press - disable.

    Attached changed input.lua .
     

    Attached Files:

    #1 Incognito, Aug 8, 2013
    Last edited: Jul 17, 2014
  2. metalmuncher

    metalmuncher
    Expand Collapse

    Joined:
    Aug 6, 2012
    Messages:
    257
    Works quite well, except that you have to press the button to "start" the engine.
     
  3. iheartmods

    iheartmods
    Expand Collapse

    Joined:
    Aug 8, 2012
    Messages:
    1,482
    Watchyu sayin'?

    - - - Updated - - -

    Capture.JPG

    which 'end' and wheres this '(update) thing?

    (stuck on step 2 :( )

    Help me Incognito, you're my only hope ;)
     
    #3 iheartmods, Aug 8, 2013
    Last edited: Aug 8, 2013
  4. Masterjoc

    Masterjoc
    Expand Collapse

    Joined:
    Aug 4, 2013
    Messages:
    297
    will try it out tomorrow, seems amazing;)
     
  5. Incognito

    Incognito
    Expand Collapse

    Joined:
    Aug 4, 2013
    Messages:
    246
    In your screen end - its line 265. Btw, you can download changed files from first post.

    o_O Hm... My car is always appear with the running engine.
     
  6. metalmuncher

    metalmuncher
    Expand Collapse

    Joined:
    Aug 6, 2012
    Messages:
    257
    When I tested it, the vehicles engine was not started when the vehicle was loaded until the button was pressed. You can fix this by calling the setCruiseControl function right after it ends.

    EDIT: I think I found what it was. I followed your instructions and didn't use your pre done file. You omitted a line from the instructions which is in the pre done file, assigning a value of 0 to M.cruiseControl.
     
    #6 metalmuncher, Aug 8, 2013
    Last edited: Aug 8, 2013
  7. Incognito

    Incognito
    Expand Collapse

    Joined:
    Aug 4, 2013
    Messages:
    246
    Oh, lol, sorry. Fixed the first post.
     
  8. Kimmykix

    Kimmykix
    Expand Collapse

    Joined:
    Aug 4, 2013
    Messages:
    231
    Inognito... why aren't you hired to code for this game yet? xD You've done things the devs haven't even done yet xD
     
  9. Incognito

    Incognito
    Expand Collapse

    Joined:
    Aug 4, 2013
    Messages:
    246
    Update:
    Added braking when the vehicle speed is more than 5 miles than specified.
     
  10. blinkingyellow

    blinkingyellow
    Expand Collapse

    Joined:
    Mar 9, 2013
    Messages:
    276
    Good work, i wanted this to be honest, thank you.
     
  11. Incognito

    Incognito
    Expand Collapse

    Joined:
    Aug 4, 2013
    Messages:
    246
    Updated :)
     
  12. Johann2326

    Johann2326
    Expand Collapse

    Joined:
    Aug 8, 2013
    Messages:
    29
    What key to press to enable the cruise control?
    I downloaded the file in the first post
     
  13. Incognito

    Incognito
    Expand Collapse

    Joined:
    Aug 4, 2013
    Messages:
    246
    Read the step 6.
     
  14. iheartmods

    iheartmods
    Expand Collapse

    Joined:
    Aug 8, 2012
    Messages:
    1,482
    i want the toggle key to be the space bar, should i type 'spacebar' or 'space_bar' or 'space'

    - - - Updated - - -

    nevermind on above post, 'space' worked out fine;

    One thing you should try to incorporate is when the brake is applied, that should disengage cruise control
     
  15. tyman5125

    tyman5125
    Expand Collapse

    Joined:
    Sep 2, 2013
    Messages:
    1
    Can you make a version of the file that you just drag and drop in and it work, and just tell us what line to use to change the CC key
     
  16. iheartmods

    iheartmods
    Expand Collapse

    Joined:
    Aug 8, 2012
    Messages:
    1,482
    This work with the newest version? :confused:
     
  17. Incognito

    Incognito
    Expand Collapse

    Joined:
    Aug 4, 2013
    Messages:
    246
    Dont know. Need to check :)
     
  18. Incognito

    Incognito
    Expand Collapse

    Joined:
    Aug 4, 2013
    Messages:
    246
    Just checked - works fine :)
     
  19. Nivracer

    Nivracer
    Expand Collapse

    Joined:
    Jan 23, 2014
    Messages:
    370
    I have no clue how to get this to work -_-
     
  20. nick088

    nick088
    Expand Collapse

    Joined:
    Apr 1, 2014
    Messages:
    42
    Were should I add
    %mm.bindVLuaCmd(keyboard, "key_name", "input.setCruiseControl()", ""); , and Should I add the quotes Ex. "U" ? Every time i add that line the game does not work. :mad:
     
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice