Solved Scenario .lua file-Help!

Discussion in 'Mod Support' started by The Gas Station, Mar 10, 2018.

  1. The Gas Station

    The Gas Station
    Expand Collapse

    Joined:
    Jul 14, 2016
    Messages:
    272
    So I've got a pretty complex scenario, I got almost everything working, except from the "win" condition.
    What I need is a .lua file that will "count" whenever you've passed through specific checkpoints (not every checkpoint- only specific ones), and after you passed through a defined number of them, it will send a "success" to the game (you win).
    Problem is, I don't know .lua at all.
    If you know a bit of .lua, and can help by explaining what functions I need to use, or by sending a link that will help me learn Beamng lua basics, or even better- if you could build a template file, I'd really appreciate that.
     
  2. Aerotactics

    Aerotactics
    Expand Collapse

    Joined:
    Dec 23, 2015
    Messages:
    57
    Check out the Tanker Delivery LUA script for reference, but I think you could do (this is abbreviated):

    local count = 0

    Onplayerentercheckpoint {
    count++;
    if(count == somenumber)
    {
    win
    }
    }
     
    • Like Like x 1
  3. The Gas Station

    The Gas Station
    Expand Collapse

    Joined:
    Jul 14, 2016
    Messages:
    272
    Here's my non-abbreviated version. It works!!!
    I'm happy now. Good night.

    HTML:
    local M = {}
    
    local helper = require('scenario/scenariohelper')
    
    local running = false
    local scenario = nil
    local count = 0
    
    local function success(reason)
      scenario_scenarios.finish({msg = reason})
    end
    
    
    
    local function onRaceWaypointReached(data)
        local playerVehicleId = be:getPlayerVehicleID(0)
        if data.vehicleId == playerVehicleId then
            if data.waypointName == 'waypoint_15' then
                    count = count + 1 ---- got to admit- I'm surprised it worked. This is Basic's syntax (The only language I ever learned was Basic), but apparently it's fine by Lua. So... Yay!
            end
            
            if data.waypointName == 'waypoint_29' then
                    count = count + 1
            end
            
                
            if(count == 2) then
                success('You made it!')
            end
        end
    end
    
    M.onRaceWaypointReached = onRaceWaypointReached
    
    return M
    
    
    
    
     
  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