I know it's possible to delete the entire vegetation object on scenario load ( see the Suspect Pursuits Scenario Pack ), but I'd like to know if it there's a command to delete a single vegetation object, so that I can create a lua extention that automatically delete this object on scenario load. As an example, deleting the vegetation object on line 16340 in east_coast_usa.forest
Not easy to do it, lines on forest items are not persisting on file changes. Why you need this new feature? If we know the use case, maybe we can think on a different way to solve it
I'd like to have this feature in order to open holes in the vegetation walls in ECA and JRI to allow a vehicle to pass through. This way I could extend my Juggernaut scenario pack with scenarios in these maps. In the ressource discussion thread, @torsion suggested that I delete ECA's forest object ( which I know is possible), and then that I load a .forest object that I made. I think it would be the easiest way to implement this solution, and that there could even already be a way to do it with this game version. I have no idea of the command that I could use to load a .forest object though.
I suspect that with a little a little elbow-grease you might be able to do it in a similar fashion to race_marker.lua. (C:\Program Files (x86)\Steam\SteamApps\common\BeamNG.drive\lua\ge\extensions\scenario\race_marker.lua) Race_marker.lua actually executes TorqueScript which it stores as a string. For a forest object I think that the smart money is on: load the *.forest from a file into a string variable concatenate it into our TS command execute the TS command In other words something like this: Code: // assuming that we've already deleted the Forest object! fileData = readFile(filename) TSCommand = "new TSForest(myforest) " .. fileData .. ";" TorqueScript.eval(TSCommand)
Thanks ! There's a parse error somewhere though, I'm going to need to spend some more time to find it
Where's the parse error? (eg TS, Lua, etc?) FWIW I haven't attempted to use that code, I just scribbled something down.
It's a parse error occuring on the line TorqueScript.eval(TSCommand) I suspect it's because the readfile function outputs an header part with informations I don't need, and I need to erase these lines from the variable in order to get the code working. There's also the fact that the print function doesn't output all the content of the .forest file, but I guess there's a limit to the maximum number of lines printed at once to not clutter the console.
You're correct in thinking that what's shown by the print function isn't the entire contents of the variable. I'm not sure what the print() limit is, but dumpToFile(filename, variable) will give you the full contents of the variable. I think that headers shouldn't be loaded with readFile(). I tried this and the output looked OK except for some rectangles (unrecognized characters I guess?) on every hard return: Code: temp = readFile("levels/jungle_rock_island/jungle_rock_island4.forest") print(temp) Actually I get a TS parse error just running this directly on the TS console: Code: new TSForest(myforest) {"DRI_rock_a":[[-204.55,-355.585,126.183,0,0,0.7876,0.6162,1]]}; I don't think "TSForest" is correct - it's possibly supposed to be "Forest" instead. That doesn't work either. Looks like I'm out of my depth here. Maybe @tdev can point us in the right direction.
Good news @torsion ! You kinda solved the problem in the thread "What am I doing wrong? Forest files issues" I just had to run a TS Script with the last piece of code you wrote in this thread, just refering to my edited forest file instead. I'm on phone at the moment, but when i'll get access to internet on my computer tomorrow i'll edit this post to add the piece of code I've used
Oops! I am a little embarrassed that I didn't catch on to my own mistake. I'm really glad you saw the problem and got it working! Now that you've spelled it out the solution is clear. Does it require a physics reset? (I know that for your immediate purposes it doesn't matter since physics can be reset before the scenario starts.)
So, here's the code : 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/east_coast_usa/scenarios/Juggernaut_forest.forest"; lodReflectScalar = "1"; }; ]]) be:reloadStaticCollision(); log('I', 'Juggernaut.replaceForest', 'Forest object replaced') end return { onClientStartMission = replaceForest, } About the physics reset, I guess it's the function be:reloadStaticCollision() that does it. I'm not totally sure it's needed, but I had some weird collision issues ( nothing is here, or shown with the show static collision enabled, but the car crashed one time on the 4 times it got through ). Anyway, it works perfectly that way, and I even have been able to change the .forest on a checkpoint trigger without problems ( apart from a small freeze when the forest is loading ) ( not that I'm going to use it as that, but it can be useful to know what can and cannot be done )