Unsolved Scenario lua questions

Discussion in 'Mod Support' started by RyvyLo, Apr 28, 2017.

  1. RyvyLo

    RyvyLo
    Expand Collapse

    Joined:
    May 15, 2014
    Messages:
    438
    I stumbled onto some problems in order to make my carBall scenarios, so here are the questions to unstuck me :

    1- How can I reset the vehicles, especially on a multiseat scenario ? ( get them at a certain position and rotation with zero speed and not broken )

    2- At the end screen of a scenario, how to show a custom bar that counts the points ?
    For example, I have a lua script that increase a counter each time the ball get through a trigger. How do I show a progress bar at the end of the scenario with the score of the counter ?

    3- Is there any function to wait a certain amount of time ?
    For example, once a trigger is enabled, I want the game to wait for, let's say, 1s before resetting all the vehicles.
    I though it could be possible to have a box prop outside the player range, that could be teleported at a certain height on trigger of the event, and when the box has dropped a certain distance, it will go through another trigger that will execute the action to do after the wait.
    For obvious reasons I would like to avoid using this solution, as it uses a lot of computer resources to simulate the box.
     
  2. torsion

    torsion
    Expand Collapse

    Joined:
    May 31, 2015
    Messages:
    1,600
    For #3 there are multiple options. I'm assuming that you need your timer to work in GE lua, not Vehicle lua - right?

    a. In GE lua you'd assign a function to onPreRender, the hook will pass the delta time since the last onPreRender(). (in Vehicle lua you'd use updateGFX() instead) - https://www.beamng.com/threads/time-lua-in-scenarios.30497/

    b. Use a timer. In GE lua you'd use hptimer() but in Vehicle lua you'd use HighPerfTimer(). I think that both of them use the same controls:

    Code:
     local myTimer = hptimer() --gelua
    local myTimer = HighPerfTimer() --vlua
    
    print(myTimer) --now
    
    myTimer:stop()
    myTimer:reset()
    myTimer:stopAndReset()
    For #1 here's what I've got:
    • https://www.beamng.com/threads/player-car-in-scenario-changing-id.29100/
    • be:resetVehicle(0) --for GE lua, just resets the vehicle and fixes damage I think, probably to the vehicle's "home" location?
    • TorqueScript.eval('getPlayerVehicle(0).setTransform("-400 -200 0.5 0 0 0");') //I'm afraid that the last 3 numbers are supposed to related to rotation, but seem to be broken currently (initial rotation is kept). Previously there was a bug with this where if you set rotation it would respawn/heal the vehicle.
    • Rather than using TS (via TorqueScript.eval()) you can use something like this in GE: be:getPlayerVehicle(0):setTransform(scenetree.findObject('thePlayer'):getTransform())
    The last example will teleport one vehicle into the space of the player's initial vehicle (in freeroam). Of course in a script you can assign stuff to variables, shuffle things around, etc.
     
    #2 torsion, May 2, 2017
    Last edited: May 3, 2017
  3. RyvyLo

    RyvyLo
    Expand Collapse

    Joined:
    May 15, 2014
    Messages:
    438
    Thank you very much for these explanations. I will try to apply them to my scenarios as soon as I've figured out why almost all of my lua triggers in these scenarios have stopped working ( I guess a dumb syntax error is hidden somewhere ), and then I'll get back to you, but it might take some time.
     
  4. torsion

    torsion
    Expand Collapse

    Joined:
    May 31, 2015
    Messages:
    1,600
    You're welcome! I apologize in advance for any sloppy code / bad advice. ;-) Just now I went back and updated the myTimer examples because I apparently didn't paste or type exactly what I wanted in there. You'd stop mytimer by using something like myTimer:stop().
     
  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