Jump to content
Sign in to follow this  
Sexacutioner

Deleting Group when all are dead

Recommended Posts

Hello. I have a script that allows players to spawn units and I read you need to make sure and remove created groups to keep below the 144 limit. I've been trying to find a way to check if everyone in the group is dead however it's not working. For instance in a "Killed" event listener if I put the following:

sleep 10;
		_cnt = count units _victimGroup;
		player globalchat format["count %1",_cnt];

It never gives me a zero group count. I killed 7 guys in a group one by one and on the last guy it returned "2" instead of "0". Does this mean the group is auto-removed and it's messing up or does it just get it wrong because there is no one in the group to take a census?

I'd like to use deleteGroup if the count is at zero, but first I need a way to find out when that is.

Share this post


Link to post
Share on other sites

hey look at DMZ Delete script v 1.1 by Demonized. It does that very well and is a great script to use in your mission.

Share this post


Link to post
Share on other sites

Thanks for the script. Looking through it I found this line:

{if ((count (units _x)) == 0) then {deleteGroup _x; _x = grpNull; _x = nil}} foreach allGroups;

Which if I check the "count (units _x)" part it's still inaccurate for a period of time after an entire group is wiped out, so the bummer part is it will need to be checked in a loop, but I suppose it will work if a bit less efficient than I'd hoped.

Share this post


Link to post
Share on other sites

Okay somewhere I read that all groups without anyone in them will be deleted by the server automatically after some time, but that could be a rumor so don't mind me :D

I guess you didn't look into your error-log because you'd have noticed a generic error indicating that you can't use the command "sleep" in the event handler :D

Furthermore you can't delete a group unless it's empty - and I mean empty!. Just made a quick test myself, unless you delete the dead units, you can't delete the group they were in.

So something like this could help you out nevertheless:

killedEHandler = {

_this spawn {

		sleep 10;

		_group = group (_this select 0);
		deleteVehicle (_this select 0);	
		if (count units _group == 0) then
		{
			deleteGroup _group;
		};

}
};

yourSoldier addEventHandler ["killed", killedEHandler];

Share this post


Link to post
Share on other sites

For the sleep I have the event call another thread with execVM, which I think works? This is how the event is called:

_unit addMPEventHandler ["MPKilled", {[_this,null,null,[7]] execVM "callScript.sqf"}];

I tried the count units group, but haven't been able to get it to return zero. Instead I decided to go with counting all groups in the event. Some will slip by but hopefully will get caught the next time an AI dies. It's either that or have a loop constantly counting the groups which I'd rather not do. I'm making a multiplayer game that allows teams to call in ai support pretty often so the spawned AI is always coming and going :).

Share this post


Link to post
Share on other sites

interesting, I do it a completely different way.. I let someone else do all the hard work and then I steal it lol

this is taken from Demonized SP Respawn script so I take no credit where credit is due

but this should work.

_grpDel = false; // default false, delete dead units after x time when all in units group is dead.

if ("_groupdelete" in _this) then {_grpDel = true};

   // delete the dead unit if selected.
   if (_delete != 0 OR _grpDel) then {
       _null = [_dead,_delete,_grpDel,_grp] spawn {
           if ((_this select 2)) then {
               waitUntil {({alive _x} count units (_this select 3)) == 0};
           };
           sleep (_this select 1);
           deleteVehicle (_this select 0);
       };
    };

{
	if ((typeName _x) == "ARRAY") then {_init = _x};
	if ((typeName _x) == "STRING" AND !(_x in ["_groupdelete"])) then {_mark = _mark + [_x]};
} foreach _this;
_lead = false;
if ((leader (group _unit)) == _unit) then {_lead = true};

_null = [this,"_groupdelete"] execVM "yourscriptname.sqf";

I hope that's right but there may be tons of other mixed arrays in there *shrug*

Edited by MadM0nkey
left some stuff out

Share this post


Link to post
Share on other sites

Probably you've already had a look at this and the comments http://community.bistudio.com/wiki/deleteGroup

About the delayed unit count, from my OFPR experience it's just like the "Oh no, 5 is dead!" ai reporting system of your player group. All units are reported dead sooner or later and count does reach zero. It happens earlier when the death is reported for the system by another unit, and probably takes the longest time if only its own timeout runs out.

BTW this counting should detect dead units at once:

({alive _x} count (units _x))

Share this post


Link to post
Share on other sites

Oh duh, why didn't I think of using alive in conjunction with group. Yea just count those alive in the group and if it's zero remove the group. Thanks.

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  

×