TPrince Posted April 20, 2023 Posted April 20, 2023 Hello all, Building a mission where a coalition takes over an airfield and buildings get destroyed in the process. The 2nd coalition retakes the airfield. Is there a way they can rebuild the buildings using the mission editor? Processor AMD Ryzen 9 7900X 12-Core Processor 4.70 GHz Installed RAM 32.0 GB (31.7 GB usable) Graphics Card NVIDIA GeForce RTX 4070 TI 4 K Monitor ASUS VG34V
TPrince Posted April 20, 2023 Author Posted April 20, 2023 (edited) I went to Chat GPT and this is what it wrote when asked how to achieve. If you know lua can you tell me if this is 3 separate scripts I have to create? To restore destroyed buildings on a map using a Lua script in DCS, you can use the following steps: First, create a table to store the destroyed buildings' information. You can use the following code to create an empty table: local destroyedBuildings = {} 2. Next, create a function to check if a building is destroyed. You can use the following code to check if a building is destroyed by its object name: function isBuildingDestroyed(name) local object = Object.getByName(name) if object and object:getLife() == 0 then return true else return false end end 3. In your main update loop, iterate through all the buildings on the map and check if each one is destroyed. If a building is destroyed, add its information to the destroyedBuildings table: function update() for i, buildingName in ipairs(buildings) do if isBuildingDestroyed(buildingName) then table.insert(destroyedBuildings, buildingName) end end end 4. Note that buildings is an array containing the names of all the buildings on the map. Finally, create a function to restore the destroyed buildings. This function should iterate through the destroyedBuildings table and respawn each destroyed building: function restoreDestroyedBuildings() for i, buildingName in ipairs(destroyedBuildings) do local object = Object.getByName(buildingName) if object then object:destroy() object:spawn() end end end 5. You can call the restoreDestroyedBuildings function whenever you want to restore the destroyed buildings on the map. Note that this is just a basic example, and you may need to modify the code to fit your specific use case. Additionally, restoring destroyed buildings in a multiplayer game may have implications for game balance and fairness, so you should consider the impact of this feature carefully. Edited April 20, 2023 by TPrince Processor AMD Ryzen 9 7900X 12-Core Processor 4.70 GHz Installed RAM 32.0 GB (31.7 GB usable) Graphics Card NVIDIA GeForce RTX 4070 TI 4 K Monitor ASUS VG34V
TPrince Posted April 20, 2023 Author Posted April 20, 2023 Or is this all 1 script? Processor AMD Ryzen 9 7900X 12-Core Processor 4.70 GHz Installed RAM 32.0 GB (31.7 GB usable) Graphics Card NVIDIA GeForce RTX 4070 TI 4 K Monitor ASUS VG34V
buur Posted April 20, 2023 Posted April 20, 2023 There are two types of buildings in DCS. 1. Buildings already on the map. I never heard or see that they are respawnable. 2. Buildings placed via Mission editor. Which buildings do you mean?
TPrince Posted April 20, 2023 Author Posted April 20, 2023 Buildings on the Map. Processor AMD Ryzen 9 7900X 12-Core Processor 4.70 GHz Installed RAM 32.0 GB (31.7 GB usable) Graphics Card NVIDIA GeForce RTX 4070 TI 4 K Monitor ASUS VG34V
TPrince Posted April 20, 2023 Author Posted April 20, 2023 This is a second script it created when asked about Map buildings -- List of building names to restore local buildingNames = { "Building 1", "Building 2", "Building 3" } -- Table to store destroyed building information local destroyedBuildings = {} -- Check if a building is destroyed function isBuildingDestroyed(name) local object = Object.getByName(name) if object and object:getLife() == 0 then return true else return false end end -- Check all buildings and store destroyed building names function checkBuildings() for i, name in ipairs(buildingNames) do if isBuildingDestroyed(name) then table.insert(destroyedBuildings, name) end end end -- Respawn all destroyed buildings function restoreBuildings() for i, name in ipairs(destroyedBuildings) do local object = Object.getByName(name) if object then object:destroy() object:spawn() end end end -- Main update loop function update() checkBuildings() if #destroyedBuildings > 0 then restoreBuildings() destroyedBuildings = {} end end Processor AMD Ryzen 9 7900X 12-Core Processor 4.70 GHz Installed RAM 32.0 GB (31.7 GB usable) Graphics Card NVIDIA GeForce RTX 4070 TI 4 K Monitor ASUS VG34V
buur Posted April 21, 2023 Posted April 21, 2023 I don't think that chatgpt can help you with the question. The answer of chat gpt is only helpfull if you place the buildings in the mission editor.
TPrince Posted April 21, 2023 Author Posted April 21, 2023 (edited) Ok. Understood. Thank you very much for your help. I will just add smoke and fire. Its a scenario where a Airbase is attacked by Coalition and taken over only to be lost back. After its taken back over I'm going to have 4 helos drop off personnel and go to the areas that were destroyed (Now on fire) Put out the fires then more helos will come in with cargo drops to rebuild the airbase. Then have cargo planes land to rearm and refuel the base and Fighters landing and parking.. Then the airbase becomes operational again and used in new scuffles Edited April 21, 2023 by TPrince Processor AMD Ryzen 9 7900X 12-Core Processor 4.70 GHz Installed RAM 32.0 GB (31.7 GB usable) Graphics Card NVIDIA GeForce RTX 4070 TI 4 K Monitor ASUS VG34V
TPrince Posted April 21, 2023 Author Posted April 21, 2023 (edited) @buur If you were to right click on a MAP building and choose assign, the building is provided with a name and a object ID. That information couldn't be used to restore it? Edited April 21, 2023 by TPrince Processor AMD Ryzen 9 7900X 12-Core Processor 4.70 GHz Installed RAM 32.0 GB (31.7 GB usable) Graphics Card NVIDIA GeForce RTX 4070 TI 4 K Monitor ASUS VG34V
TPrince Posted April 21, 2023 Author Posted April 21, 2023 Ok Thank you Processor AMD Ryzen 9 7900X 12-Core Processor 4.70 GHz Installed RAM 32.0 GB (31.7 GB usable) Graphics Card NVIDIA GeForce RTX 4070 TI 4 K Monitor ASUS VG34V
Recommended Posts