Solved Changing vehicles in scenario

Discussion in 'Mod Support' started by Darthbob555, Jul 20, 2016.

  1. Darthbob555

    Darthbob555
    Expand Collapse

    Joined:
    Feb 14, 2016
    Messages:
    290
    The title pretty much explains it. I have tried changing vehicles in scenarios and have found these commands in the lua reference:

    be:exitVehicle(number playerID)
    be:enterNextVehicle(number playerID, number step)
    be:enterVehicle(number playerID, BeamNGVehicle vehicleInstance)

    I know that the player id for the current vehicle is 0, and the other vehicle must be 1. However, I do not know what the value is for "step" and for "vehicleInstance". Any help would be appreciated.
     
  2. stenyak

    stenyak
    Expand Collapse
    Programmer & Global Moderator
    BeamNG Team

    Joined:
    Aug 6, 2012
    Messages:
    1,903
    Player ID is 0 for the first human player using the game. If multitiseat is enabled (e.g. if you are in a multiseat scenario), there can be more human players, according to the number of controllers you have plugged in your computer.

    The camera is always following the 1st player (whose playerID is 0).

    Step determines how many vehicles to cycle through. For the next vehicle, use +1. For the previous vehicle, use -1. For trying to stay in the current vehicle, use 0. This last one probably only makes sense to be used internally by the game engine, when changing from some internal states to others.

    enterVehicle can be used to hint one specific vehicle you want your human player to enter. If you want 1st player to enter a pigeon, whose vehicleInstance is foo, then use be:enterVehicle(0, foo). If that is possible, then the 1st player will end up seated in the pigeon.
     
    • Like Like x 2
  3. Darthbob555

    Darthbob555
    Expand Collapse

    Joined:
    Feb 14, 2016
    Messages:
    290
    Thank you very much for the help! One quick question, how does one get the vehicle instance? Is this the name of the vehicle when declared in the .PREFAB file (e.g scenario_player1)?
     
  4. stenyak

    stenyak
    Expand Collapse
    Programmer & Global Moderator
    BeamNG Team

    Joined:
    Aug 6, 2012
    Messages:
    1,903
    Yes, you can use the vehicle name together with: scenetree.findObject(name)
    For example: scenetree.findObject("my_vehicle_name")

    Alternatively, you can iterate through all existing vehicles with a loop, similar to what is done by getAllVehicles() function (in lua/ge/multiseat.lua).
     
  5. Darthbob555

    Darthbob555
    Expand Collapse

    Joined:
    Feb 14, 2016
    Messages:
    290
    Ok, so I have tried many different ways of calling and slotting in the name of the vehicle. However, I cannot get the correct type of data. For example, I have tried: be:enterNextVehicle(0, scenario_player1). This errors in the console saying it expected a number but got a nil value type.

    I have then tried this: be:enterNextVehicle(0, scenetree.findObject("scenario_player1")) which again errors but says it expected a number but got a table type - (scenario_player1) is the second player vehicle in the scenario that I want to switch to.

    Is there something obvious I am doing wrong?

    Quick side note: I have found that, (when pressing tab to switch vehicles), the second vehicle does not trigger waypoints. Can this be fixed?
     
  6. stenyak

    stenyak
    Expand Collapse
    Programmer & Global Moderator
    BeamNG Team

    Joined:
    Aug 6, 2012
    Messages:
    1,903
    Extracted from one of the existing scenarios: playerCar = scenetree.findObject('scenario_player0')
    That should work fine.

    As for the waypoint issue, i've forwarded it, thanks for reporting.

    Edit: ah wait, you are simply not calling the correct function. Use the function that accepts a vehicle, or switch to a number parameter (check your first post again for reference)
     
  7. Darthbob555

    Darthbob555
    Expand Collapse

    Joined:
    Feb 14, 2016
    Messages:
    290
    Done a bit more experimenting but I can't get the player to be seated in the other car. I have tried the following code:

    be:enterNextVehicle(0, scenetree.findObject('scenario_player1'))

    I have also tried this:

    playerCar = scenetree.findObject('scenario_player1')

    be:enterNextVehicle(0, playerCar)

    Both of which do not work. Am I calling it wrong?
     
  8. stenyak

    stenyak
    Expand Collapse
    Programmer & Global Moderator
    BeamNG Team

    Joined:
    Aug 6, 2012
    Messages:
    1,903
    Again, you are calling the wrong functions. Check your first post:
    be:enterNextVehicle(number playerID, number step)
    be:enterVehicle(number playerID, BeamNGVehicle vehicleInstance)

    You are using a vehicle instead of a step number.
     
  9. Darthbob555

    Darthbob555
    Expand Collapse

    Joined:
    Feb 14, 2016
    Messages:
    290
    I have changed the code to be be:enterVehicle instead but that still doesn't work.
    Next, I tried the first command: be:enterNextVehicle(0, +1) and be:enterNextVehicle(0, 1) and be:enterNextVehicle(0, -1). Have I missed something in your post earlier?
     
  10. stenyak

    stenyak
    Expand Collapse
    Programmer & Global Moderator
    BeamNG Team

    Joined:
    Aug 6, 2012
    Messages:
    1,903
    Any error messages, or does it fail silently?
     
  11. Darthbob555

    Darthbob555
    Expand Collapse

    Joined:
    Feb 14, 2016
    Messages:
    290
    Suddenly just worked! Not sure why it wasn't working earlier (must have typed something in wrong) but it works perfectly now. Thanks for your patience and help :)
     
  12. stenyak

    stenyak
    Expand Collapse
    Programmer & Global Moderator
    BeamNG Team

    Joined:
    Aug 6, 2012
    Messages:
    1,903
    No problem, glad to see it worked :)
     
  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