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
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
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.)
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 >" ... ... ... } ]
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 }, ]
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.
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: Showing I won despite the time being over. If I do finish I get this screen, just like before. 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.
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?