[ LUA ] Does anyone know how to get the name of the vehicle being used ?

Discussion in 'Utilities and programming' started by mike22, Apr 7, 2014.

  1. mike22

    mike22
    Expand Collapse

    Joined:
    Feb 21, 2014
    Messages:
    338
    The title sums it up.
     
  2. tdev

    tdev
    Expand Collapse
    Developer
    BeamNG Team

    Joined:
    Aug 3, 2012
    Messages:
    3,031
    hm, it should be in v.data somewhere ^^

    try to dump that variable :)
     
  3. mike22

    mike22
    Expand Collapse

    Joined:
    Feb 21, 2014
    Messages:
    338
    How would I dump that variable ?

    You don't have to explain it in detail. Honestly, if you don't wanna explain it at all, that's cool too, LOL.. I guess I would have to dump it from the beamng.lua file in the lua\vehicle directory.

    After thinking about it for a few minutes, is v.data a temporary file while playing the game ?

    Alright, this correctly puts the air speed in the variable called vName, but for the last line of code, what would put the current vehicle name in it ?

    Code:
            local function getPlayerCarID()
        for objID = 0, BeamEngine:getSlotCount(), 1 do
            local slot    = BeamEngine:getSlot( objID )
            if slot ~= nil and slot.activationMode == 1 then
                return objID
            end
        end
        return 0
        end
    
    
        local carID    = getPlayerCarID()
        if carID == nil then
            return 0, 0
        end
        
        local VName2 = BeamEngine:getSlot( carID )
        local vName    = VName2:getVelocity():length()
    
    - - - Updated - - -

    I'm just bumping this once because I don't know if the last update was seen.
     
    #3 mike22, Apr 8, 2014
    Last edited: Apr 7, 2014
  4. ThreeDTech21

    ThreeDTech21
    Expand Collapse

    Joined:
    Sep 27, 2013
    Messages:
    1,616
    this may work: "printCurrentCarId()" type that into the console without the ""

    press "~" for console
     
  5. mike22

    mike22
    Expand Collapse

    Joined:
    Feb 21, 2014
    Messages:
    338
    Thanks for the reply.

    It returns "unable to find function
    printCurrentCarId".

    I find it crazy that I can get the air speed around the vehicle but not the name of it..



    - - - Updated - - -

    OK, if I go into the console, select BNGV, then enter "print (v.vehicleDirectory)", I get the vehicle directory path, which I could work with, but.. v.vehicleDirectory doesn't seem usable from a .lua file.. I mean, it probably is able to be used from a .lua file, but I'm missing something.
     
    • Like Like x 1
  6. ThreeDTech21

    ThreeDTech21
    Expand Collapse

    Joined:
    Sep 27, 2013
    Messages:
    1,616
    Do you need the name the computer assigns to it or the name of it in BeamNG? in the vehicles folder there is a "name" .cs file, the computer may uses that as an official Identifier.

    The computer assigned name, using the printcarID handle it shows the player car as "0" the player car is always "0" other cars in the scene simply go up "1" "2" "3" etc. and when you switch to another car it changes its name to "0", the player id's (names) seem to be variable not static. Other than that I don't know what else to look for.
     
  7. mike22

    mike22
    Expand Collapse

    Joined:
    Feb 21, 2014
    Messages:
    338
    I'd like to have the name of the car being driven from it's name.cs file into a Lua file. My track timer is considered a system Lua, so I'm having trouble accessing metatables that were created in a vehicle Lua.
     
  8. Incognito

    Incognito
    Expand Collapse

    Joined:
    Aug 4, 2013
    Messages:
    246
    This function defined in waypoints mod. So, if the op didnt installed this mod he must define this function.
    P.S. The cars ids changing after reset (CTRL+R).

    Perhaps, op trying to know how to get this name:
    2014-04-08 17-34-17 BeamNG.drive.png
    I didn't find this name in v.data dump
    View attachment v.data_dump.zip
     
  9. mike22

    mike22
    Expand Collapse

    Joined:
    Feb 21, 2014
    Messages:
    338
    I appreciate the dump file, but is it possible for me to access any of the data in those tables from a system Lua file ?
     
  10. logoster

    logoster
    Expand Collapse

    Joined:
    Sep 5, 2012
    Messages:
    2,082

    that's not part of default beamng, that's from the waypoints mod by incognito


    EDIT: Ninja'd by incognito, lol
     
  11. Incognito

    Incognito
    Expand Collapse

    Joined:
    Aug 4, 2013
    Messages:
    246
    Most likely, no. Only in vehicle lua.

    It will be possiblee when devs will add data exchange between system lua and vehicle lua.
     
  12. mike22

    mike22
    Expand Collapse

    Joined:
    Feb 21, 2014
    Messages:
    338
    I put a couple requires ( default.lua and beamng.lua from the lua vehicle directory ) into my track timer and I was able to access the v.table but it wasn't complete. It was just basic.

    - - - Updated - - -

    I guess there's no possible way to bridge Torque ( vehicle chooser ) with Lua ? It seems like it is in a way..

    Code:
    function VehicleChooser::apply(%this){
       %cval = %this.getSelectedVehicle();
       %config = %this.getSelectedVehicleConfig();
       
       %obj = %this.getCurrentObject();
       if( %obj != 0 )
       {
          %obj.JBeam = %cval;
          %obj.partConfig = %config;
          %obj.requestReload();
          if(%config !$= "")
          {
            [COLOR=#006400][B] %obj.lua("partmgmt.load('" @ %config @ "')");[/B][/COLOR]
          }
       }
     
       Canvas.popDialog(VehicleChooser);
    }
    - - - Updated - - -

    HA, even after figuring out how to dump the v table to a file, the vehicle name that's contained in the name.cs file is not even in it.. It's crazy..

    The only thing I can do is get the active vehicle directory name and trim it..

    - - - Updated - - -

    Holy shit, I did it.. completely automated.. dumps v.vehicles to a file on vehicle spawn, which my system Lua file reads from.. It isn't just to echo on the screen. I'll log the vehicle used with lap times. I'll include this with all my tracks eventually.

    Now I have it so the lap timer display depends on which vehicle is being driven, so.. the best time displayed will be the best time for the vehicle being driven. It was a joy to learn Lua tables.......
     

    Attached Files:

    • BeamNG.drive.x86_2014_04_09_02_41_17_146.jpg
    #12 mike22, Apr 9, 2014
    Last edited: Apr 9, 2014
  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