1. Before reporting issues or bugs, please check the up-to-date Bug Reporting Thread for the current version.
    Solutions and more information may already be available.

Get player vehicle and config [SOLVED]

Discussion in 'Troubleshooting: Bugs, Questions and Support' started by jojos38, Jul 6, 2017.

  1. jojos38

    jojos38
    Expand Collapse

    Joined:
    Oct 22, 2013
    Messages:
    757
    Hi, i am the creator of Siren & Horn Mod and i would like to know if someone know how to get the player car configuration.
    I have this code:

    local vehicleNames = scenetree.findClassObjects('BeamNGVehicle')
    for _, name in ipairs(vehicleNames) do
    local veh = scenetree.findObject(name)
    print(veh.partConfig)
    end


    but it return me all vehicle on the map and i want only the vehicle the player is driving.


    I also have this:

    local vehicleName = v.vehicles.vehicleDirectory:gsub("vehicles/", ""):gsub("/", "")
    print(vehicleName)


    but it doesn't return me the config...

    If someone could help me please ? :)
     
  2. stenyak

    stenyak
    Expand Collapse
    Staff Member

    Joined:
    Aug 6, 2012
    Messages:
    1,142
    Use be:getPlayerVehicle(playerNumber)
    Where playerNumber is typically 0 (but can be 1, 2, etc if using multiseat).
     
  3. jojos38

    jojos38
    Expand Collapse

    Joined:
    Oct 22, 2013
    Messages:
    757
    Thank you, but it return me "userdata: 0x516541..." :/
     
  4. stenyak

    stenyak
    Expand Collapse
    Staff Member

    Joined:
    Aug 6, 2012
    Messages:
    1,142
    Yep, that's your vehicle.

    be:getPlayerVehicle(0):getField('partConfig', '')
    be:getPlayerVehicle(0):getField('JBeam', '')
     
  5. jojos38

    jojos38
    Expand Collapse

    Joined:
    Oct 22, 2013
    Messages:
    757
    THANK YOU !!!
     
  6. stenyak

    stenyak
    Expand Collapse
    Staff Member

    Joined:
    Aug 6, 2012
    Messages:
    1,142
    You're welcome ;)
     
  7. jojos38

    jojos38
    Expand Collapse

    Joined:
    Oct 22, 2013
    Messages:
    757
    How can i make transfer this value in vehicle lua ._. ?
    I tried obj:queueGameEngineLua("be:getPlayerVehicle(0):getField ('drivingSounds.vehicleConfig = (\"'..'partConfig', ''..'\")')") but it doesn't work :/
     
  8. stenyak

    stenyak
    Expand Collapse
    Staff Member

    Joined:
    Aug 6, 2012
    Messages:
    1,142
    What are you trying to accomplish?
    The quotes don't seem to be correctly matched.
    In addition, you are calling somethingsomething:getField('foo = bar') which makes no sense.
     
  9. jojos38

    jojos38
    Expand Collapse

    Joined:
    Oct 22, 2013
    Messages:
    757
    The code you gave me can be runned only in "GE Lua" and i need this value in "Vehicle Lua" so i want to find a way to get this value in Vehicle Lua
     
  10. stenyak

    stenyak
    Expand Collapse
    Staff Member

    Joined:
    Aug 6, 2012
    Messages:
    1,142
    Then for starters you need to queue it into vehicle lua, but you are literally queuing it into game engine lua ("queueGameEngineLua").
    You must use obj:queueLuaCommand instead.

    But still, I have no idea what you are trying to accomplish. Can you please explain in english (not in code) what you want to do?
     
  11. jojos38

    jojos38
    Expand Collapse

    Joined:
    Oct 22, 2013
    Messages:
    757
    I want to do this "be:getPlayerVehicle(0):getField('partConfig', '')" in lua vehicle
    --- Post updated ---
    obj:queueLuaCommand("drivingSounds.vehicleConfig = be:getPlayerVehicle(0):getField('partConfig', '')") --> return me "attempt to index global 'be' (a nil value)

    be:getPlayerVehicle(0):getField('partConfig', '') --> same

    obj:queueGameEngineLua("drivingSounds.vehicleConfig = be:getPlayerVehicle(0):getField('partConfig', '')") --> return me "attempt to index global 'drivingSounds' (a nil value)
     
  12. stenyak

    stenyak
    Expand Collapse
    Staff Member

    Joined:
    Aug 6, 2012
    Messages:
    1,142
    If you are in vlua already, then you can use:
    partmgmt.getConfig()
     
  13. jojos38

    jojos38
    Expand Collapse

    Joined:
    Oct 22, 2013
    Messages:
    757
    Okay but it return me "table: ..."
     
  14. stenyak

    stenyak
    Expand Collapse
    Staff Member

    Joined:
    Aug 6, 2012
    Messages:
    1,142
    If you want it in text form, you can pass it through serialize()
    serialize(partmgmt.getConfig())
     
  15. jojos38

    jojos38
    Expand Collapse

    Joined:
    Oct 22, 2013
    Messages:
    757
    Okay but it return me a long list of all vehicle parts :/
     
  16. stenyak

    stenyak
    Expand Collapse
    Staff Member

    Joined:
    Aug 6, 2012
    Messages:
    1,142
    Please describe what you are trying to accomplish. Describe your end goal, rather than the next detail that you believe is necessary to achieve the greater goal. Otherwise we'll be running in circles chasing the wrong problems.
     
  17. jojos38

    jojos38
    Expand Collapse

    Joined:
    Oct 22, 2013
    Messages:
    757
    I just want to get this : be:getPlayerVehicle(0):getField('partConfig', '') --> return the vehicle config.pc in the "BeamNG - Vehice Lua". just this
     
  18. stenyak

    stenyak
    Expand Collapse
    Staff Member

    Joined:
    Aug 6, 2012
    Messages:
    1,142
    That is exactly what you are getting, both pieces of code return the exact same string as the other. One does it from gameengine lua, the other from vehicle lua.
     
  19. jojos38

    jojos38
    Expand Collapse

    Joined:
    Oct 22, 2013
    Messages:
    757
    I don't understand
    --- Post updated ---
    Just go on the beamng chat https://www.beamng.com/pages/chat/
     
    #19 jojos38, Jul 6, 2017
    Last edited: Jul 6, 2017
  20. Codeslasher

    Codeslasher
    Expand Collapse
    Staff Member

    Joined:
    Apr 12, 2016
    Messages:
    26
    Hi,
    This is how to get the config as well as other pieces of data.

    Code:
      local vid = be:getPlayerVehicleID(0)
      local vehicle = scenetree.findObjectById(vid)
      if vehicle then
         local model = vehicle.JBeam
         local licenseText = vehicle.obj:getDynDataFieldbyName("licenseText", 0)
         local color = string.format("%0.2f %0.2f %0.2f %0.2f", vehicle.color.x, vehicle.color.y, vehicle.color.z, vehicle.color.w)
         local _, config, _ = path.split2(vehicle.partConfig)
      end
    
    config, in the 2nd to last line of code, is the vehicle config.

    Good Luck.
     
    • Agree Agree x 1
  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