Unsolved Scenario End-Messages?

Discussion in 'Mod Support' started by OttoNL, Nov 6, 2017.

  1. OttoNL

    OttoNL
    Expand Collapse

    Joined:
    Apr 27, 2016
    Messages:
    125
    Hi,

    I've been making a lot of off-road and transport scenario's lately and decided to turn about 10 of the scenario's I'm working on in to a Campaign or Scenario Pack and add a bit of a storyline.

    I've figured out how to make a person loose when a towed vehicle is lost or when a car is damaged, and when you loose I can set an end-message, but I haven't managed to figure out how to set an end-message when a scenario was ended succesfully.

    I think I've seen it done before, but for the life of me I can't figure out in what scenario's, so I can't just open a .json file and copy whatever code they used.

    If anybody could point me in the right direction that would be great. Or if anybody happens to know of a scenario that uses this feature I'm happy to dig through some code.

    Thanks in advance,
    OttoNL
     
  2. Codeslasher

    Codeslasher
    Expand Collapse
    BeamNG Team

    Joined:
    Apr 12, 2016
    Messages:
    28
    Hi,
    There are 2 ways of doing this.
    The 1st is using the scenario JSON. You can add these fields to the scenario JSON file
    "failedMessage":" <A failed message string here >"
    "passedMessage":"<A success message string here >"

    The 2nd way is from custom LUA. The messages can have data inserted in them.

    For example
    At the end of the scenario in a function say onRaceResult, you can do the following
    Let's say the user's altitude is stored in a variable called userAltitude.

    for fail case
    failedMessage = { txt = "You dropped only {{altitude}}m and need at least 30m", context = {altitude = userAltitude}}
    scenario_scenarios.finish({failed = failedMessage})
    (Use this format for when you want to pass data from the scenario into the message. Can be used for success cases to, example below.)

    for success case
    PassMessage = "Well Done! You made the it across."
    scenario_scenarios.finish({msg = PassMessage})
    OR
    PassMessage = {txt = "Well done. You scored {{points}} points!", context = {points = userScore}}
    scenario_scenarios.finish({msg = PassMessage})

    Thats it.
    Please take note of the format of the messages.

    Hope this helps.

    Good luck :)
     
    • Like Like x 1
  3. OttoNL

    OttoNL
    Expand Collapse

    Joined:
    Apr 27, 2016
    Messages:
    125
    I haven't gotten it to work yet. Does it matter where I place the code?
    I'm going for the easy route, doing it all in the .json file and I put these lines at the top of the file in between the date and the difficulty, I've also tried putting it in the vehicles, scenario and goal part. (I also fixed indentation and other syntax like the comma at the end and I removed the "msg" part just in case it conflicted.)

     
    #3 OttoNL, Nov 7, 2017
    Last edited: Nov 7, 2017
  4. Codeslasher

    Codeslasher
    Expand Collapse
    BeamNG Team

    Joined:
    Apr 12, 2016
    Messages:
    28
    Hi,
    If you are going the JSON route, then add the 2 fields from option 1.
    "failedMessage":" <A failed message string here >"
    "passedMessage":"<A success message string here >"

    These should be in the main part of the scenario JSON, that is at the same level as date and difficulty
    e.g.
    Code:
    [
    {
        "name": "3/X Testing some Hopper Mods",
        "description": "",
        "previews": ["liftkittest.jpg"],
        "type": "race",
        "authors": "OttoNL",
        "difficulty": "50"
        "date": 1513857600,
        "failedMessage":" <A failed message string here >"
        "passedMessage":"<A success message string here >"
        ...
        ...
        ...
    }
    ]
    
     
  5. OttoNL

    OttoNL
    Expand Collapse

    Joined:
    Apr 27, 2016
    Messages:
    125
    Thanks for your help so far :)

    That's one of the first things I've tried, but it didn't work. Just in case I also reïnstalled the game, disabled all mods except for this one and cleared the cache.
    Below is the exact code I used.
    I also tried removing the line with "msg" just in case it conflicted and I even tried leaving out the comma's at the end of the failedmessage and passedmessage lines to be thorough.

    Code:
    [
    {
        "name": "3/X Testing some Hopper Mods",
        "description": "",
        "previews": ["liftkittest.jpg"],
        "type": "race",
        "authors": "OttoNL",
        "difficulty": "50",
        "date": 1513857600,
        "difficulty": "40",
        "failedMessage":"You damaged the car!",
        "passedMessage":"Good job!",
        
        "vehicles":
        {
            "scenario_player0":
            {
                "driver":
                {
                    "player":true,
                    "startFocus": true,
                    "required": true
                },
                "goal":
                {
                    "damage":
                    {
                        "damageLimit":100,
                        "msg":"You damaged the Demo Hopper!",
                        "purpose":"fail"
                    }
                }
            },
            "*":
            {
                "playerUsable": false
            },
        },
        
        "whiteListActions": ["default_whitelist_scenario" ],
        "blackListActions": ["default_blacklist_scenario" ],
        
        "lapConfig": ["wp1"],
        "prefabs": ["liftkittest"],
        "radiusMultiplierAI": 2
    },
    ]
     
  6. Codeslasher

    Codeslasher
    Expand Collapse
    BeamNG Team

    Joined:
    Apr 12, 2016
    Messages:
    28
    Hi,
    have examined the code, that should work.
    How are you determining when the player failed or succeeded?
    You have the damage goal which has the message for when you failed due to taking too much damage.

    But if you don't take damage, how does your scenario end?

    As a test, I'd add

    "maxTime" : 40,

    to the JSON file. This will set a time limit of 40 seconds to complete the scenario. This will set the failed or passed condition based on when the user completes the scenario.
     
  7. OttoNL

    OttoNL
    Expand Collapse

    Joined:
    Apr 27, 2016
    Messages:
    125
    Before it was a pretty simple scenario with a playercar0, some checkpoints (all but 1 removed from the .json file for quick testing).
    So you could just finish it by hitting the checkpoint or you could fail by taking damage.
    I have added the line
    "maxTime" : 40,
    To the top of the file, right under the difficulty.

    Now if I don't finish in time I get this screen:
    20171108140704_1.jpg
    Showing I won despite the time being over.

    If I do finish I get this screen, just like before.
    20171108140825_1.jpg

    Again I tried winning and loosing, then I tried removing the damage goal from the scenario and tried winning and loosing again. That also didn't change anything.

    I also tried making a timeLimit goal with the maxTime in there, just like this picture suggests:

    And that shows me the "used more then 13.5 sec" line at the end, but if I do succeed I still don't get a message.
     
    #7 OttoNL, Nov 8, 2017
    Last edited: Nov 8, 2017
  8. OttoNL

    OttoNL
    Expand Collapse

    Joined:
    Apr 27, 2016
    Messages:
    125
    Since doing it in the Json doesn't work do you have a good Lua tutorial you recommend? Can I just pick up any Lua course, or is there a lot of beamNG specific code?
     
    #8 OttoNL, Nov 9, 2017
    Last edited: Nov 9, 2017
  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