I've been taking a stab at putting together a somewhat complicated scenario and have mainly been having trouble with finding documentation for how to do various things with lua. So far I've been using the wiki, the game's lua files, and other mod's lua usage to find all the info I need. Is there another place I could look for documentation that might have more complete info on things like the data given to event callbacks? At the moment the things I'm trying to solve are: Identify when a specific vehicle is inside either of a couple trigger volumes. I suspect the vehicle ID is in the data I'm getting for the beamng trigger, I just need the name. Verify that a specific vehicle is inside a trailer. Is there some way to attach a trigger to a vehicle? If not I might try using code to update the trigger's position and rotation to keep it roughly in the right spot assuming I can figure out how to insert a non-hardcoded value into the torque script expression (I'm using TorqueScript.eval to move things around with lua). Otherwise I may just need to do things the hard way and manually work out the bounding box of relative positions it can be at while inside the trailer, and test against that. Use ray casting to see if there's line of sight between vehicles. My scenario is mainly a cat and mouse type of chase so I need to be able to know when the player has successfully gotten out of sight. Looking at the usage of castRay for the external camera I think I understand how the arguments work, though I'd like to know what is returned if it does hit something. Is there a recommended limit for how often it's used? I think I'd use it ~30 times per onRaceTick in a simple implementation (I could probably cut this down to under 10 or even 5 for the majority of ticks if needed). Use lua to reset vehicles (or at least create/destroy them). In my scenario I'd like to be able to reset AIs that have crashed or gotten stuck to keep the number of chasing AIs roughly constant. It'd be fine even if they reset in the same place they crashed because I'd be moving them around to simulate another chaser arriving. Being able to remove and then add another vehicle could also potentially work assuming it somehow didn't hitch like when vehicles are spawned using the GUI. This isn't as important to me, but would be nice to have. I haven't uploaded this scenario anywhere yet as I was planning to put it up once it was finished, so let me know if you want an overview of my plans or to have a look at my work so far. Other than that I was thinking that I would write out some of the things I've worked out so far just so that they're easier for others to find out, if no one thinks that'd be inappropriate for this thread.
I can at least answer for the first question, I had made an explanation of the triggers in this post and I think you could check out a slightly different way to make it work in this mod : Cops an Robbers I'm mostly clueless about the rest of your questions though, and in my experience I've been able to reset and create new vehicles via lua, but never without a small game freeze, which completely remove the immersion in-game
Thanks a bunch! Would you mind telling me how you did the vehicle creation/resetting? That mod was pretty cool, thanks for letting me know about it.
I used TorqueScript to do most of this. I think an example is better than anything else, so feel free to take a look at this test scenario I made while figuring out what I could and couldn't do. It also seems that the focus switches to the newly spawned car now, but I haven't found (and haven't taken the time to find) a workaround.
sadly i do not recommend using TorqueScript because it will be deprecated soon (maybe next update to next year). They are some things available in lua Code: --first option be:resetVehicle(int player) --or local veh = be:getObject( 0 ) -- zero is current driven vehicle -- be:getObjectCount() --maybe useful for loops veh:spawnObjectWithPosRot(float px, float py, float pz, float rx, float ry, float rz, float rw) --or veh:requestReload(bool autoplace = false) --autoplace will reset most angles and put the vehicle at the right height above terrain or meshes (it's not aware of other vehicles) for raycast Code: float be:castRay(Point3F origin, Point3F target) --points local po = Point3F(1,2,3) (i never used it so i don't know yet how well it work)
I may hijack the thread a bit, but I now have a small issue. I happen to be using TorqueScript for a mod I'm expanding, and I was wondering if there was any other way to do it, since it'll become obsolete. Code: local function replaceForest() TorqueScript.eval([[ theForest.delete(); new Forest(theForest) { position = "0 0 0"; rotation = "1 0 0 0"; scale = "1 1 1"; canSave = "1"; canSaveDynamicFields = "1"; dataFile = "levels/jungle_rock_island/art/forest/Juggernaut_forest.forest.json"; lodReflectScalar = "1"; }; ]]) be:reloadStaticCollision(); log('I', 'Juggernaut.replaceForest', 'Forest object replaced') end return { onClientStartMission = replaceForest, } For more info, here's the mod support topic I had created which leaded me to this answer : https://beamng.com/threads/scenario-lua-deleting-a-specific-vegetation-object.30615/ Long story short, I don't need to replace the whole forest object, I just need a way to delete just specific .forest vegetation that are getting on my way.
Code: o= scenetree.findClassObjects('Forest') --TODO : check if table isn't nil or empty deleteObject(o[1]) --or you can change the filename oa = scenetree.findObject(o[1] ) print( oa:getField("dataFile","")) oa:setField("dataFile","","levels/gridmap/test.forest.json") Saddly this lua code should work but doesn't. The property field is changed but the forest doesn't change. We need to fix something in T3D to be able to change things dynamically and that T3D update them PS: i really have no idea when we will remove TS so you can still use it for now, we have to add things that isn't available in LUA to replace it
Thanks ! That's no problem, I just wanted to save future me from problems when updating the mod after the TS removal update. Hopefully I will remember this thread and get it fixed without any headache Back on topic, @The Advisor , I just remembered scenarios with a distance detector. If the box is always on the trailer, looking at something like the Heavy Delivery Pack:Utah might help you (If I recall correctly, it's a distance goal inside the .json). Else you could dig in the code of the chapter_2_4_delivery scenario in levels\Utah.zip\levels\Utah\scenarios\chapter_2, there might be something useful here