demonized

DMZ Delete [script]

33 posts in this topic

DMZ Delete v 1.1

release v 1.1 - 16 July 2011

REQUIRES Arma2 OA

* Its a script wich cleans up any dead man, destroyed vehicle and empty groups (to save the 144 group limit for long missions).

* It works for men, land, air, sea vehicles and empty groups.

* it includes options to add other objects(ANY) or use custom timer/distance on any object.

* It uses no eventhandlers.

* options included: abondened vehicles, vehicles that cannot move due to damage, distance so players cannot see the "delete", timers.

* You can exclude 1 or several specific units, or even unit classnames or superclasses like all helicopters or combine with all above.

* It updates runtime so you can add and remove excluded units/vehicles on the go. v 1.1 also have a included part that can update same way.

Maybe someone find it useful.

Change log v 1.1

* NINJA CHANGE: removed all publicVariable parts, not needed as script should only run on server side.

* men now uses hideBody and sinks into ground before deleted, as requested by forum members.

* new option, DMZ_include, include ANY object with optional custom timer and distance check. can also be used to have custom timer on a special car unit etc..

v 1.0

* initial release.

MP functionality:

* acording to Forum users its now verified fully MP compatible.

Instructions:

1: Save it as DMZ_delete.sqf and place in your mission folder.

2: Place this in init.sqf or in a initline of a unit or a trigger etc:

_null = [] execVM "DMZ_delete.sqf";

DMZ_delete.sqf

if (!isServer) exitWith {};  // test for MP usage, has no impact on SP missions.
/*
DMZ Delete v 1.1
by Demonized.

This script does not use any eventhandlers, so it may delay the deleting if there are heavy scripts running.
Main purpose is to cleanup within a reasonable frame, for most missions it will be 100% accurate on timers, exept maybe for those heavy scripted ones, wich may cause some extra time until delete.

Script will delete any dead man, destroyed/abandoned vehicle and empty group after x seconds within a 10 seconds accuracy (its checking for new dead or vehicles every 10 seconds)
* abandoned vehicles if option is used, will abort their delete if anyone gets into the vehicle before timer runs out.
* abandoned vehicles wich are destroyed, will abort their current abandon timer, and will be deleted after same timer as deleting destroyed vehicles.
* _canmove may be a bad option, any vehicle witouth fuel, will be detected as it cannot move, make sure you want the option in your mission if you use it.
* mainly created for SP missions, but should be MP compatible.
* does not delete any objects, only men and vehicles (land, air, sea, static weapons).
* use DMZ_Included to include or modify timer and distance for ANY object/unit/vehicle.

execute with:
place in init.sqf or in a object init field:
_null = [] execVM "DMZ_delete.sqf";

*/

DMZ_Included = [];  				// used to include certain objects into the delete, such as for example any unit/vehicle, ieds, ammo crates, custom buildings/bases/compounds etc. any object can be used, update it same way as DMZ_Excluded runtime with info from below.
DMZ_Excluded = [];  				// used to exclude certain men or vehicles or types/classname from being deleted.

/*
* more info on DMZ_Excluded:

You can add vehicle or units to this global array and they will never be deleted.
You can either just type unitname directly here in the script, or
just do this to add unitname in your custom script or trigger or init.

	DMZ_Excluded = DMZ_Excluded + [unitname];	// unitname will now never be deleted.

examples:
	DMZ_Excluded = [car1,unit1,unit2];		// vehicle named car1 and men called unit1 and unit2 will never be deleted.
	DMZ_Excluded = [car1,"Air"];			// vehicle named car1 and any Air vehicles will never be deleted.
	DMZ_Excluded = ["Man","Helicopter"];	// any men and any helicopters will never be deleted.
	DMZ_Excluded = ["BAF_Apache_AH1_D"];	// the type BAF Apache helicopters will never be deleted.

DMZ_Excluded will be checked evey cycle for changes, and there is a failsafe before the delete in case of bad luck with timing.
go here for more cfgVehicle and types: http://community.bistudio.com/wiki/ArmA_2:_CfgVehicles

* more info on DMZ_Included:

you can add just the object/unit/vehicle, or you can add a specific timer AND distance to be used with that vehicle like shown here:
any object that can be placed in the world via editor or script can be included.
you cannot use classname or cfgVehicles atm.
included objects will not care for _canMove OR _abandoned options, they will delete no matter what after _incTimer OR custom seconds if used like below.
icluded objects will use _viewDist to check if player is to close, if not custom is used like below.

	DMZ_Included = [obj1,unit1];			// obj1 and unit1 will be deleted after x seconds(_incTimer).
	DMZ_Included = [[obj1,129],unit1];		// obj1 deletes after 129 seconds, and unit1 will be deleted after x seconds(_incTimer below).
	DMZ_Included = [[obj1,129,200]];		// obj1 deletes after 129 seconds, and only when any player unit is 200 meter or more away from it.
*/

// true/false = on/off.
_canMove = true;  	// if vehicles should be deleted when they are to damaged to move and empty, NOTE empty fuel also means it cannot move.
_abandoned = true;  	// if vehicles should be deleted after being x time un manned, if 1 unit enters in the time period, time is reset, and vehicle is processed again when empty or destroyed.
_groupDel = true;  	// if empty groups should be deleted, to avoid reaching 144 group limit in long missions.
_viewDist = 0;  		// min distance in meter from a player unit to allow delete, if you dont care if player sees the delete, set it to 0.
_manTimer = 10;  		// x seconds until delete of dead man units.
_vehTimer = 10;  		// x seconds until delete of dead vehicles, for destroyed and heavy damaged vehicles.
_abaTimer = 10;  		// x seconds a vehicle must be unmanned to be deleted, for _abandoned option.
_incTimer = 10;		// x seconds any object put inside the DMZ_Included will be deleted no matter condition.

// DO NOT EDIT PAST THIS LINE //

// delete function.
_delete = {
_del = _this select 0;
_dis = _this select 1;
_tim = _this select 2;
_aba = _this select 3;
_abt = _this select 4;
_cnm = _this select 5;
//if (isPlayer _del OR !(local _del)) exitWith {};

_abort = true;
if ("veh" in _this AND (_aba OR _cnm)) then {
	_sec = _abt;
	while {_sec != 0} do {
		sleep 1;
		if (_aba AND (getDammage _del) < 1 AND ({alive _x} count (crew _del)) == 0) then {_sec = _sec - 1};
		if (_aba AND _sec == 0) then {_abort = false};
		if (((_cnm AND canMove _del) OR _aba) AND ({alive _x} count (crew _del)) != 0) then {
			_sec = 0; _abort = true;
			_del setVariable ["DMZ_delete_readd", true, true];
		};
		if ((getDammage _del) >= 1) then {
			_sec = 0; _abort = false;
			sleep _tim;
		};
		if (isNull _del) then {_sec = 0; _abort = true};
	};
} else {
	_abort = false;
	sleep _tim;
};
// fail safe for excluded and included.
if (isNull _del OR _abort OR _del in DMZ_Excluded) exitWith {};
{
	_arr = _x; _obj = ""; _timer = _tim; _dist = _dis;
	if ((typeName _arr) == "ARRAY") then {
		_obj = _arr select 0; _timer = _arr select 1;
		if ((count _arr) == 3) then {_dist = _arr select 2} else {_dist = _viewDist};
	} else {
		_obj = _arr; _timer = _tim; _dist = _dis;
	};
	if (_del == _obj) then {
		_del = _obj;
		_dis = _dist;
		if ((_timer - _tim) > 0) then {sleep (_timer - _tim)};
		// clean up the DMZ_Included array of deleted objects.
		DMZ_Included = DMZ_Included - [_x];
	};
} foreach DMZ_Included;

if (!isNull _del) then {
	_arr = [];
	waitUntil {sleep 1; ({isPlayer _x AND (_del distance (vehicle _x)) < _dis} count playableUnits) == 0};
	waitUntil {sleep 1; ({isPlayer _x AND (_del distance (vehicle _x)) < _dis} count switchableUnits) == 0};
	if ("veh" in _this OR "incVeh" in _this) then {{_arr = _arr + [_x]; _x setPos (getPos _del); deleteVehicle _x} foreach crew _del} else {
		if (_del isKindOf "man") then {hideBody _del; sleep 10};
	};
	_arr = _arr + [_del];
	deleteVehicle _del;
	//{_x = objNull; waitUntil {sleep 1; isNull _x}; _x = nil} foreach _arr;

	{if (_x in DMZ_delete_respawned) then {_arr = _arr - [_x]}} foreach _arr;
	DMZ_delete_respawned = DMZ_delete_respawned + _arr;
};
};

_processed = []; _todo = []; _types = []; _included = []; DMZ_delete_respawned = [];
while {true} do {
// check DMZ_Excluded array for changes.
{if ((typeName _x) == "STRING" AND !(_x in _types)) then {_types = _types + [_x]}} foreach DMZ_Excluded;
// update types/classnames if changed.
{if (!(_x in DMZ_Excluded)) then {_types = _types - [_x]}} foreach _types;
// clean the processed list of all objects that have been deleted.
{if (isNull _x) then {_processed = _processed - [_x]}} foreach _processed;
// clean the included list of all objects that have been deleted.
{if (isNull _x) then {_included = _included - [_x]}} foreach _included;

// process DMZ_Included array.
{
	_arr = _x; _obj = ""; _timer = 0; _dist = 0;
	if ((typeName _arr) == "ARRAY") then {
		_obj = _arr select 0; _timer = _arr select 1;
		if ((count _arr) == 3) then {_dist = _arr select 2} else {_dist = _viewDist};
	} else {
		_obj = _arr; _timer = _incTimer; _dist = _viewDist;
	};
	if (_x in _included) exitWith {};
	_included = _included + [_obj];
	if (_obj isKindOf "AllVehicles" AND !(_obj isKindOf "Man")) then {
		_null = [_obj,_dist,_timer,false,0,false,"incVeh"] spawn _delete;
	} else {
		_null = [_obj,_dist,_timer,false,0,false,"inc"] spawn _delete;
	};
} foreach DMZ_Included;

// gather all dead.
_allD = allDead;
{if (_x in DMZ_delete_respawned AND _x in _processed) then {_processed = _processed - [_x]}} foreach _allD;
{
	_unit = _x;
	if (_x in _included) exitWith {};
	if ((vehicle _x) == _x AND !(_x in _processed) AND ({_unit isKindOf _x} count _types) == 0 AND !(_x in DMZ_Excluded)) then {
		if (!(_x in _todo)) then {_todo = _todo + [_x]};
	};
} foreach _allD;

// gather all vehicles and process depending on options used.
_allV = vehicles;
{if (_x in DMZ_delete_respawned AND _x in _processed) then {_processed = _processed - [_x]}} foreach _allV;
{
	_veh = _x;
	if (_x in _included) exitWith {};
	if (_x getVariable ["DMZ_delete_readd", false]) then {
		_processed = _processed - [_x];
		_x setVariable ["DMZ_delete_readd", false, true];
	};
	if (!(_x in _processed) AND ({_veh isKindOf _x} count _types) == 0 AND !(_x in DMZ_Excluded)) then {
		if ((getDammage _x) >= 1 OR (_canMove AND !canMove _x AND ({alive _x} count (crew _x)) == 0) OR (_abandoned AND ({alive _x} count (crew _x)) == 0)) then {
			if (!(_x in _todo)) then {_todo = _todo + [_x]};
		};
	};
} foreach _allV;

// run the delete script for todo list.
{
	if (!(_x in _processed)) then {
		if (_x isKindOf "Man") then {
			_null = [_x,_viewDist,_manTimer,_abandoned,_abaTimer,_canMove] spawn _delete;
		} else {
			_null = [_x,_viewDist,_vehTimer,_abandoned,_abaTimer,_canMove,"veh"] spawn _delete;
		};
		_todo = _todo - [_x]; _processed = _processed + [_x];
	};
} foreach _todo;

// delete empty groups.
if (_groupDel) then {{if ((count (units _x)) == 0) then {deleteGroup _x; _x = grpNull; _x = nil}} foreach allGroups};

// sleep 10 seconds, then check if there are any changes to dead or vehicles that are not processed.
sleep 10;
};

direct download: Dirty Demo 4Shared:

hosted by ArmaHolic, cheers to Foxhound.

Edited by Demonized
added armaholic link

Share this post


Link to post
Share on other sites

Great script love it!

Just a quick suggestion it would be cool if the bodies went into the ground instead of being deleted instantly.

Like when you go to a dead body an in the action menu you have the option to "Hide Body".

Either way this script is fantastic thanks for the release!

-Bigshot

P.S. You should update your signature with your new scripts!

Edited by bigshotking

Share this post


Link to post
Share on other sites

Another very useful script, thanks!

& +1 for the hide body option

Share this post


Link to post
Share on other sites

Just add a:

hideBody _del;
sleep 5;

above the deleteVehicle _del; line.

Share this post


Link to post
Share on other sites

Thanks Kylania for the piece of code!

Unfortunately it seems this script does not work in MP. I tested it on a non-dedicated server hosted on my pc. (I already know that it states that it was made for SP).

-Bigshot

Share this post


Link to post
Share on other sites

updated to v 1.1

Change log:

* men now uses hideBody and sinks into ground before deleted, as requested by forum members.

* new option, DMZ_include, include ANY object with optional custom timer and distance check. can also be used to have custom timer on a special car unit etc..

will look into MP compatibility of this, maybe all thats needed is a if (isServer) check at the top.

for those testing, try placing this at the very top of the script:

edit: have added the MP test option to the Demo mission file and posted file, has no impact on SP usage.

that should maybe make it work on dedis and hosted server.

it will not include units in player groups and vehicles driven by players afaik.

unless vehicles not used by players will revert to server side again after player is no longer in command of vehicle.

also im not sure on the locality of the allDead array wich is used to check for dead men.

im hoping it is a global array that includes any dead man unit no matter client.

Edited by Demonized
added info and updated post.

Share this post


Link to post
Share on other sites

:D awsome picture.

will keep looking into this, im doing tests on my own MP hosted on LAN to see whats wrong, will update on progress.

---------- Post added at 03:39 AM ---------- Previous post was at 03:28 AM ----------

@bigshotking

I have updated the demo mission, there was an error in the init.sqf used.

i forgot to comment out the tests i did with the DMZ_include option, thos objects was not in the mission, and then caused error so nothing was deleted.

all got deleted now on my own locally hosted server, MP internet and lan and in SP.

PS: i changed script again:

no noticable changes, i removed publicvariable lines as they are not needed since script only runs on server side.

publicvariable increases lag on MP games afaik, maybe just a teeny tiny bit, but they are out anyway now.

1st post updated.

Edited by Demonized

Share this post


Link to post
Share on other sites

It works! Thanks for the awesome script man!

Oh and here is another screen shot (Fixed Version):

http://i409.photobucket.com/albums/pp177/bigshotking/ArmA2OA2011-07-1519-39-00-55.png

In the screen shot you will see fire burning in thin air, that is where the vehicles used to be, but when they are deleted they leave the fire behind.

Personally I could care less about it, but I know that someone will ask you about it in the future. Just pointing it out now!

-Bigshot

Share this post


Link to post
Share on other sites

the fire is just particle effects from the burning wreck, they should disappear after a short while.

Share this post


Link to post
Share on other sites

Yes it does, I was just pointing it out so that you know and that if someone needs perfection and doesn't want to see the fire when there is no vehicle there. :D

-Bigshot

Share this post


Link to post
Share on other sites

Hey Demonized,

Loving this script. However, it only works on all dead objects that are spawned at the start of the mission. Is there a way to add checks in for objects spawned AFTER the mission has started. I'm talking about missions like VTS, where you can spawn objects on the fly.

I CAN get it to work if I manually restart the script again, but it's a little clunky having to call it when EVERY object is spawned.

Here is a thing - IF I have one copy of the script running, and I run another, does it override the original (and restart the counter) ?

Share this post


Link to post
Share on other sites
Hey Demonized,

Loving this script. However, it only works on all dead objects that are spawned at the start of the mission. Is there a way to add checks in for objects spawned AFTER the mission has started. I'm talking about missions like VTS, where you can spawn objects on the fly.

I CAN get it to work if I manually restart the script again, but it's a little clunky having to call it when EVERY object is spawned.

Here is a thing - IF I have one copy of the script running, and I run another, does it override the original (and restart the counter) ?

thats strange, i had asumed that the VTS would work same way as any other spawned units.

in the demo mission you have a radio trigger where you can spawn a stryker group as many times you like, and they get deleted just as well as others.

Is this an MP issue?

the script rechecks the complete list of dead and every vehicles every 10 seconds.

if you run a paralell script of this, the 1st script will take precedence, and the second timer will simply exit since the object is null.

i dont think it will create any special lag running multiples of this as its small in CPU usage, but if you would run it after any spawns, that would be ridiculus and for sure screw things up with the excluded included parts.

Share this post


Link to post
Share on other sites

Hmmm will have a look again tonight. So in your mind a single call at the start of a mission will apply to every unit spawned after?

Share this post


Link to post
Share on other sites

in my mind :D yes.

the script is not collecting all units at start, it checks the ingame arrays of all vehicles and all dead and if they are meeting the condition and have not been already processed by the script, the script processes them.

then sleeps 10 seconds, and rechecks and so on and so forth..

it also readds respawned units with same name as the dead ones to the check list so they will again get deleted upon meeting the condition.

---------- Post added at 08:43 PM ---------- Previous post was at 08:34 PM ----------

you can verify that its collecting the spawned units by placing this in init.sqf and run your VTS mission and see if numbers change to what you expect.

make sure you have function module placed in editor.

if (isServer) then {
_null = [] spawn {
	waitUntil {!isNil ("BIS_MPF_InitDone")};
	while {true} do {
		_hint = format["all dead units is %1 \n all vehicles is %2",(count allDead),(count vehicles)];
		[nil,nil,rHINT,_hint] call RE;
		sleep 1;
	};
};
};

Share this post


Link to post
Share on other sites

Cheers mate .. will try this tonight !

EDIT: Retested again this evening, and it seems that it is working perfectly. I THINK I must have been too close to the dead enemy (I had set it to 300m!) and therefore the script didnt trigger!

Edited by Kremator

Share this post


Link to post
Share on other sites

EDIT: Retested again this evening, and it seems that it is working perfectly. I THINK I must have been too close to the dead enemy (I had set it to 300m!) and therefore the script didnt trigger!

Just to clarify, the timer runs no matter the distance, but the delete waits for the distance check to be true.

i thought of resetting timer if player was to close, but figured the current would be the best way.

Release frontpaged on the Armaholic homepage.

cheers Foxhound.

Share this post


Link to post
Share on other sites

Now here is a challenge for you ..... DMZ_repair ..... looks for engineers in team, looks for vehicles nearby, engineer asks periodically should he repair ... you yes/no it

Then DMZ_autoDefuse ... looks for engineer in team, look for IED close (Reezo's IEDs are good) then asks you if he should defuse :)

Then .... then .... then....

Seriously great work Demonized! Thanks

Share this post


Link to post
Share on other sites

i was actually thinking of making a engineer version for tires and vehicles, and the ieds are a good idea for them too. but ill start with repairs and tire fixes.

the auto medic seemed like a sucess so ill start working on Auto Engineer. :D

Share this post


Link to post
Share on other sites

Cool mate. Perhaps not JUST fixing things but perhaps looking at placing mines, emplacements, foxholes, traps etc?

Share this post


Link to post
Share on other sites
Sir, there's 10 meters of road! Should I place a mine?

No.

Should I place an emplacement?

No.

Should I place a foxhole?

No.

Should I place a trap?

No.

Sir, there's 10 more meters of road! Should I place a mine?

...

Might get a bit crazy! heh

Share this post


Link to post
Share on other sites

I know what you mean but I'm sure Demonized can come up with something cool :)

Certianly the repair function is something could happen automatically (even in battle - I'm thinking tank repair :) )

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now