Released Auto disable turn signals

Discussion in 'Programming' started by Incognito, Aug 12, 2013.

  1. Incognito

    Incognito
    Expand Collapse

    Joined:
    Aug 4, 2013
    Messages:
    246
    This is a simple mod, which automatically shuts off the turn signals.
    1. Open game_folder\lua\vehicle\electrics.lua
    2. After:
      Code:
      local blinkTimer = 0
      add (with a new line):
      Code:
      local steering_old = 0
    3. After:
      Code:
      updateValue("lowhighbeam")
      add (with a new line):
      Code:
          -- auto disable blinker
          if ( math.abs( M.values["steering"] ) < math.abs( steering_old ) and math.abs( M.values["steering"] ) < 0.3 and math.abs( steering_old ) > 0.3 ) then
              electrics.disableBlinkerSignals( M.values["steering"] )
          end    
          steering_old = M.values["steering"]
          -- auto disable blinker
    4. After "end" of "setLightsState" function (line 311) add (with a new line):
      Code:
      -- auto disable blinker
      local function disableBlinkerSignals( v )
          if ( not signalWarnState ) then
              if ( v < 0 ) then
                  signalRightState = false        
              else
                  signalLeftState  = false
              end
              signalModeChanged()
          end
      end
      -- auto disable blinker
    5. After:
      Code:
      M.init                = reset
      add (with a new line):
      Code:
      -- auto disable blinker
      M.disableBlinkerSignals = disableBlinkerSignals
      -- auto disable blinker
    Demonstration:
     

    Attached Files:

    #1 Incognito, Aug 12, 2013
    Last edited by a moderator: Oct 21, 2015
  2. Incognito

    Incognito
    Expand Collapse

    Joined:
    Aug 4, 2013
    Messages:
    246
    Update. It should now work correctly on keyboards.
    How to update for those who have used the previous version:

    1. Open game_folder\lua\vehicle\input.lua and delete:
      Code:
          -- auto disable blinker
          if ( math.abs( M.axisX ) < math.abs( M.axisX_old ) and math.abs( M.axisX ) < 0.3 and math.abs( M.axisX_old ) > 0.3 ) then
              electrics.disableBlinkerSignals()
          end    
          M.axisX_old = M.axisX
          -- auto disable blinker
      and:
      Code:
      M.axisX_old = 0
    2. Make the third and fourth steps which are specified in the first post.
     
  3. Masterjoc

    Masterjoc
    Expand Collapse

    Joined:
    Aug 4, 2013
    Messages:
    297
    When i hit the update, the changes will be resetted or?
    Else backup edited files.
     
  4. Incognito

    Incognito
    Expand Collapse

    Joined:
    Aug 4, 2013
    Messages:
    246
    What you mean? To reset the changes delete the code that you added earlier or use backup.
     
  5. TheAdmiester

    TheAdmiester
    Expand Collapse

    Joined:
    Aug 7, 2012
    Messages:
    577
    Updating replaces any modified (but not added) files, so yes, it'll revert any changes.
     
  6. bits&bytes

    bits&bytes
    Expand Collapse

    Joined:
    Jun 13, 2013
    Messages:
    40
    Ok, I have just made my first modification to the game.
    I wanted to do the automatic shut-off of the turn signal when the steering wheel returns towards center, because it seemed an easy mod to start with, but I did not noticed that incognito has done it already :D.

    So anyway, here is my version of it:

    Code in blue must be copied into the corresponding lua script.
    The values (-)45 and (-)10 are the angles that the steering wheel must reach to shut of the turn signal. So steering must first exceed 45 degree and then return to 10 degree before shutting of the turn signal.

    game_folder\lua\vehicle\electrics.lua
    Code:
     -- internal functions
    local function signalModeChanged()
          updateValue("signal_right_input", 0)
          updateValue("signal_left_input", 0)
    end
     
    [COLOR=#0000ff]-- function to turn off indicators automatic: -- Mod by bits&bytes on 03-Sep-2013[/COLOR][COLOR=#0000ff]
    function IndicatorAutoOff()[/COLOR][COLOR=#0000ff]
          --Turn off left indicator:[/COLOR][COLOR=#0000ff]
          if M.values["steering"] > 45 and Steered_Left ~= true then[/COLOR][COLOR=#0000ff]
                Steered_Left = true[/COLOR][COLOR=#0000ff]
          end[/COLOR][COLOR=#0000ff]
          if M.values["steering"] < 10 and Steered_Left == true then  [/COLOR][COLOR=#0000ff]
                Steered_Left = false[/COLOR][COLOR=#0000ff]
                if not signalWarnState then   [/COLOR][COLOR=#0000ff]
                      signalLeftState = false[/COLOR][COLOR=#0000ff]
                      signalModeChanged()[/COLOR][COLOR=#0000ff]
                end[/COLOR][COLOR=#0000ff]
          end[/COLOR][COLOR=#0000ff]
         
          --Turn off right indicator:[/COLOR][COLOR=#0000ff]
          if M.values["steering"] < -45 and Steered_Right ~= true then[/COLOR][COLOR=#0000ff]
                Steered_Right = true[/COLOR][COLOR=#0000ff]
          end[/COLOR][COLOR=#0000ff]
          if M.values["steering"] > -10 and Steered_Right == true then      [/COLOR][COLOR=#0000ff]
                Steered_Right = false[/COLOR][COLOR=#0000ff]
                if not signalWarnState then[/COLOR][COLOR=#0000ff]
                      signalRightState = false[/COLOR][COLOR=#0000ff]
                      signalModeChanged()[/COLOR][COLOR=#0000ff]
                end[/COLOR][COLOR=#0000ff]
          end[/COLOR][COLOR=#0000ff]
    end[/COLOR][COLOR=#0000ff]
    [/COLOR]
     
    -- user input functions
    local function toggle_left_signal()
          if not signalWarnState then
                signalLeftState = not signalLeftState
          else
                signalLeftState = true
          end
          if signalLeftState then
                signalRightState = false
                signalWarnState = false
          end
          signalModeChanged()
    end
      
    game_folder\lua\vehicle\hydros.lua
    Code:
     local function update(dts)
          -- state: the state of the hydro from -1 to 1
          -- cmd the input value
          -- note: state is scaled to the ratio as the last step
          for i,h in pairs(M.hydros) do
                -- slowly approach the desired value
                if h.cmd < h.state then
                      h.state = math.max(h.state - dts * h._inrate, h.cmd)
                else
                      h.state = math.min(h.state + dts * h._outrate, h.cmd)
                end
     
                --if inputSource ~= "steering" then
                --    print("state: "..h.state .. " - inlimit: " .. h.inLimit.. " - state: "..h.state .. " cmd:"..h.cmd .. " val = "..val)
                --end
                obj:setBeamLengthRefRatio(h.beam.cid, h.state)
          end
         
          [COLOR=#0000ff]IndicatorAutoOff() -- Mod by bits&bytes on 03-sep-2013[/COLOR][COLOR=#0000ff]
    [/COLOR]end
     
    -- nop'ed functions
    M.updateGFX = updateGFX
    M.update = update
     
    Or you can replace both scripts with the ones in the .zip file.
    If you do it that way, keep in mind that earlier mods in those files, will be overwritten.


    Next modification will be an alternative way of steering for keyboard users (like me):
    I will try to reduce the steering speed so it looks more realistic (return speed is good like it is now).
    If possible I make the steering speed lower as airspeed increases.
    I will try to make some sort of incremental steering, so pressing left key will turn the steering wheel to the left. When releasing the key, the wheel will stay in its position. Right key will move the wheel to the right. Another button will release the steering wheel so it returns back to its center position.
    But I will make another topic for that.
     

    Attached Files:

    #6 bits&bytes, Sep 4, 2013
    Last edited: Sep 6, 2013
  7. Incognito

    Incognito
    Expand Collapse

    Joined:
    Aug 4, 2013
    Messages:
    246
    For some reason I forgot about this mod :D
    Updated :)
     
  8. Incognito

    Incognito
    Expand Collapse

    Joined:
    Aug 4, 2013
    Messages:
    246
    Added the installation file for automatic installation with Lua-mod-installer .
    Unpack the "InstallScript" archive, in BeamNG Lua-mod Installer select adts_script.bls and press "Install" button.
     
  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