Jump to content
Sign in to follow this  
Killy_McMurder

Script to delete units

Recommended Posts

I'm in the process of learning the basics of scripting and i seem to spend more time here, luckily you guys are a whoooooole lot cleverer than me!

Basically my mission starts with a cutscene, in which i have two pilots that get into a fighter on a carrier, the fighter takes off and then flies away out of shot (with a nice/cliche fade-to-black). After which the game fades back in and the player is controling a different unit to the one that execs the cutscene. This is working fine now, thanks to you awesome people.

What i need is to add a code to the end of my scene.sqs that will delete both pilots and the aircraft once i'm finished with them as i don't want them buzzing around for the remainder of my mission.

Scouring the forums it looks like i have to do something along the lines of define them all as a group (all i can find is deleteGroup, no deleteUnit...) and delete that, i have no idea how to do this though.

Can this event even be called from the scene.sqs?

If so what would the code look like?

If not were would it be called from?

If it is something to do with having to define a group or whatever first pleeeeeease explain how i do that, i've spent hours staring at forums and wikis and examples.... I just can't get my head around this...

Any help would be hugely appreciated

-Killy

Share this post


Link to post
Share on other sites

deletevehicle is used for units as well as vehicles, run that to each of them

Share this post


Link to post
Share on other sites

Got a follow on question so thought I'd join it to this thread.

Is there a way to delete all units bar one within a trigger field apart from one unit if it's within the delete area ?

Share this post


Link to post
Share on other sites

Your asking about like a cleanup script that would clean the battlefield once anything is dead?

If this is what your asking then there is a script I use to cleanup the battlefield, its very good for big missions,

as it keeps the lag at a min, and if anything eliminate lag altogether.

create a SQF script name it: cleanup

put this code in the script:

private ["_delcode", "_currentworld", "_oldworld", "_newworld", "_notalive"];
_delcode = {
private ["_crew"];
sleep 60;
{
	if (not isNull _x) then {
		if (_x isKindOf "Ship" or _x isKindOf "Air" or _x isKindOf "LandVehicle") then {
			_crew = nearestObjects [_x, ["Man"], 20];
			_crew = _crew + crew _x;
			deleteVehicle _x;
			{
				if (not alive _x) then {deleteVehicle _x};
			} forEach _crew;
		} else {
			deleteVehicle _x;
		};
	};
} forEach _this;
};
_currentworld = [];
while {true} do {
sleep 3;
_oldworld = _currentworld;
_currentworld = + list wholeworld;
_newworld = _oldworld - _currentworld;
_notalive = [];
{
	if (not alive _x) then {_notalive = _notalive + [_x]};
} forEach _newworld;
if (count _notalive > 0) then {_notalive spawn _delcode};
};

then you will need a init script also a SQF, name this script: init

put this code in the script:

if (isServer) then {
[] execVM "cleanup.sqf";
};

then in the game create an area trigger that will cover the area that units and what not will be in.

Activation: anybody present

under name on the middle left hand side of the trigger

name it: wholeworld

I use it for Mp missions, should work in sp as well.

any questions let me know.

Edited by Gnter Severloh

Share this post


Link to post
Share on other sites

Not 100% on topic, but still related to basic cleanup. This is what I use in persistent missions to clean up user dropped ammo, weapons, and rucks. Just implemented it, so no guarantees :D

From Domination:

XPlayersNumber = {(playersNumber east + playersNumber west + playersNumber resistance + playersNumber civilian)};

Servers onPlayerDisconnected script:

[] spawn {
if (call XPlayersNumber == 1) then {
	diag_log "####---x_serverOPD.sqf---#### Last player left, preparing to clean up abandoned stuff after 5 minutes.";
	sleep 300;
	if (call XPlayersNumber > 1) exitWith {diag_log "####---x_serverOPD.sqf---#### Somebody joined within 5 minutes. Skipping cleanup."};
	diag_log "####---x_serverOPD.sqf---#### 5 minutes have passed. Startint to clean up.";
	_tt = time;
	_no = nearestObjects [d_island_center,["weaponholder","Bag_Base_EP1"],10000];
	for "_i" from 0 to count _no - 1 do {
		deleteVehicle (_no select _i);
		sleep 0.056;
	};
	diag_log format ["####---x_serverOPD.sqf---#### Cleanup of abandoned stuff complete in %1 seconds.",time - _tt];
} else {
	diag_log "####---x_serverOPD.sqf---#### Still players here, will do nothing";
};
};

You'll have to define d_island_center somewhere for at least the server. Domination uses this, note the workaround for Takistan, don't blindly trust the automatic method:

#ifndef __OA__
d_island_center = getArray (configFile >> "CfgWorlds" >> worldName >> "centerPosition");
#else
// workaround for Takistan, the island center of Takistan is located at the airfield in the south ^^
d_island_center = [6481.51,6506.95,300];
#endif

Uhm, I see I still use 10000. Was supposed to be a placeholder while testing, lol. You should probably use something like

_radius = ((d_island_center select 0) max (d_island_center select 1)) * 1.414214;

instead. Not sure what happens outside the radius of a circle, outside the bounding box of an island, so probably best to keep it somewhat safe.

Share this post


Link to post
Share on other sites

Tried this in a trigger without sleep, and only weapons I actually dropped on the ground, and with 1000m radius it was pretty isntant, with 100,000m radius the game froze for ~1sec before deleting. So it seems pretty quick.

Now I wonder what I should add in order to also delete placed mines and ACE mines/claymores/IEDs to make this perfect.

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
Sign in to follow this  

×