Koni 1 Posted September 9, 2011 (edited) For my current mission, I have a number of tasks\side missions that the player needs to complete as they play through the whole mission. Quite a few of the tasks need the scene setting with sometimes a large amount of objects and units being spawned in the area that the side mission\task takes place in. Once the side mission\task is completed, there's either a cutscene, or the player will be travelling away from the task area, while a trigger will activate a simple script to tidy up the place by deleting dead units\groups and objects that are no longer needed. This is the part that I could do with some pointers\help on. Deleting dead units\groups and objects is simple enough, but when there's sometimes quite a lot to delete I would like to know if there is a more economical way of deleting everything. Like groups. Say there's 20 groups of units that have either some dead, all alive or all dead in them, I am currently using {deleteVehicle _x} forEach units civgroup1; deleteGroup civgroup1;{deleteVehicle _x} forEach units civgroup2; deleteGroup civgroup2; deletevehicle objectname; deletevehicle objectname; deletevehicle objectname; and so on, and on etc. Now I find sometimes the "deleteGroup" can take effect before the "{deleteVehicle _x} forEach units groupname" has finished deleting all the units to start with, so I can end up having a couple of units left on the map after they should have been deleted, even that it is ran afterwards, so I end up making large lists with groups and objects that need deleting, but putting sleeps inbetween most things to slow the process down a bit, so things don't get missed out. Is there a better way of doing this, like having a trigger large enough to cover the whole area needed, and have it delete everything like units, alive or dead, including the groups and editor placed objects with a small amount of code, etc ? Edited September 9, 2011 by Koni Share this post Link to post Share on other sites
loyalguard 9 Posted September 9, 2011 (edited) Instead of sleeping how about this: {deleteVehicle _x} forEach units civgroup1; waitUntil {(count units civgroup1) < 1}; deleteGroup civgroup1; ... EDIT: Here is a more effecient code block. It uses nested forEach statements, so you have to be carefull you don't cause lag...but with a short sleep between the iterations you should be fine. This is untested should excuse any typos. Just create an array of what you want to delete (in this example groups) and the nested forEach blocks does the rest without having to re-write deleteVehicle, deleteGroup, etc. every time. BTW, you may not want/need the waitUntil in a nested forEach. Experiment to make sure the waitUntil does not cause lag or if it is even necessary. // Create an array of all of the groups you want to delete. _groupsToDelete = [civgroup1, civgroup2]; //Begin a nested forEach block to delete all units in a group (inner) and then delete the group (outer). { { // Inner Loop // Delete a unit. deleteVehicle _x; } forEach units _x; // Outer Loop // Wait until all units are deleted then delete the group. waitUntil {(count units _x) < 1}; deleteGroup _x; sleep .01; } forEach _groupsToDelete; Edited September 9, 2011 by Loyalguard More effecient example. Share this post Link to post Share on other sites
Koni 1 Posted September 9, 2011 That makes far more sense than what I'm doing, thanks, I'll keep watching to see if you come up with something else :) I ended up adding a bit more to the end of my original post too, lol Share this post Link to post Share on other sites
neokika 61 Posted September 9, 2011 Hi Koni, You can have a thread open just for this, like deleting all dead objects and groups without units in it within a while loop for example: while { true } do { { private ["_unit"]; _unit = _x; if ({ _unit distance _x < 250 } count playableUnits < 1) then //Make sure no players are near { deleteVehicle _x; }; } forEach allDead; { if ({ alive _x } count units _x < 1) then //Make sure only empty groups are deleted { deleteGroup _x; }; } forEach allGroups; sleep 60; }; _neo_ Share this post Link to post Share on other sites
Koni 1 Posted September 9, 2011 Thanks, both of you, I'll have a propper look at these examples later Share this post Link to post Share on other sites