Hello. I can add and delete objects and forestItems via the World Editor, but can I programmatically do this, maybe through Lua or C? I figured out how to add, delete and move vehicle/prop type objects with Lua, but now I'm trying to do the same with non-vehicle objects, and I'm not sure if it's even possible. Thank you.
In order to remove forest items you need to get the ForestData object first from which you can remove the ForestItems. Something like this would get rid of all forest items of the forest with the name "theForest": Code: local forest = scenetree.findObject("theForest") local forestData = forest:getData() for _, data in ipairs(forestData) do forestData:removeItem(data) end for some more references you can look at the following lua files: lua\ge\extensions\editor\forestEditor.lua lua\ge\extensions\core\forest.lua lua\ge\extensions\editor\api\forest.lua Those are the ones the world editor is using to add, remove, etc forest items
Ah-ha! Thank you, very much. This will help a lot. There's a very small section of Italy that I'd like to customize, but I want to leave the original map intact. Rather than copying the entire level and editing just that section (it's only a few edits), I'm attempting to create a script that removes some items, then adds others. I can then load regular Italy, run the script, and I nearly instantly have my own special version of Italy. Thanks again!
I think I have almost everything figured out. I can programmatically place objects via Lua, just like I can through the World Editor. However, I'm having an issue with collisions. When using the World Editor I can place objects, but collisions don't happen until I set the collisionType and decalType to "Visible Mesh Final", AND I close the World Editor. Then collisions work fine. When using a Lua script: Here's the block of code of interest: Code: -- Spawn TSStatic local hcar = createObject('TSStatic') if hcar == nil then log("E", "Utility_Script", "Cannot create TSStatic!") return end -- Set as helicarrier hcar:setField('shapeName', 0, "/levels/" .. mapName .. "/art/shapes/race/gerryfrod.dae") -- Set position, rotation and scale local quat = quatFromEuler(0, 0, math.pi) hcar:setPosRot(0, 0, 30, quat.x, quat.y, quat.z, quat.w) hcar.scale = vec3(7, 7, 7) -- Set collision map stuff hcar:setField('collisionType', 0, "Visible Mesh Final") hcar:setField('decalType', 0, "Visible Mesh Final") log("D", "Utility_Script", "Collision set 4") -- Register helicarrier hcar.canSave = false hcar:registerObject('') The code sets the collisionType and decalType fields as "Visible Mesh Final", and I can open the World Editor and see those fields are set like that, but collisions don't happen. While in the World Editor, if I set the fields back to "Collision Map", then set them again to "Visible Mesh Final", then close the World Editor, collisions work fine. Is the World Editor doing some extra magic to make collisions work that I'm failing to do in my script? I found the function setEditorActiveInternal() in main.lua and tried some of the stuff I found in there, such as editor.rebuildCollision(), but I still couldn't get collisions to work. Please, teach me this sorcery.
Do you know if it's possible to change rotation of a non-vehicle object in lua? It's simple to change its position thanks to setPosition() but I tried setPositionRotation() and it seems it works only for vehicles, not a static objects --- Post updated --- OK, so actually I've just tested it out and it seems setPosRot() is a different thing and it works for a non-vehicle objects aswell, pretty interesting
Yes, setPosRot is what you need. I have a script that spawns the Motorsports Playground aircraft carrier wherever I want. The script is in a zip file here: https://www.beamng.com/threads/naval-warfare.87940/page-8#post-1523113 You can examine the script to see what I did. The script spawns lights for the carrier too. One item of note: "TheForest" is a special object in World Editor. TheForest is an object on the same level as other non-vehicle objects in World Editor. However, TheForest has sub objects, like trees, shrubs, some rocks, etc. Although I haven't programmatically manipulated TheForest sub objects, they have their own manipulation functions (add, move, delete, etc).You'll probably notice the Forest Tools in the World Editor. These tools manipulate TheForest sub objects using functions that you can call too.