Jump to content
Sign in to follow this  
lockjaw-65-

Vehicle and body removal script

Recommended Posts

Hi all, as the title says I am looking for a good Vehicle and body removal script. I know the garbage collector only works for dynamicaly created objects. I need one that will remove everything that has died and been destroyed. I have seen a couple of scripts but they dont seem to remove everthing and I dont really know which is the best. Any help with this would be great :)

Share this post


Link to post
Share on other sites

I'm using a way that seems to be working quite good for a while with setVariable and kill Event Handlers. This will remove things according to your will :). Remember to use an Event Handler over the units.

1. Add a script that run in loops on the server (a FSM will do the job if needed).

a. Init, a function will be called upon the unit's death:

/* Function Called upon unit death. */
trashQueu = [];

_trashIt = {
Private ["_group","_liveUnits","_object"];
_object = _this;
if !(isNull _object) then {
	_group = [];
	if (_object isKindOf "Man") then {_group = group _object};
	sleep 300;
	trashQueu = trashQueu - [_object];
	//--- Remove a group if there's no living units in.
	if (_object isKindOf "Man") then {
		_liveUnits = [];
		{if (alive _x) then {_liveUnits = _liveUnits + [_x]}} forEach (units _group);
		if (count _liveUnits <= 0) then {deleteGroup _group};
	};
	deleteVehicle _object;
};
};

b. The loop, myLogic is a logic placed inside the editor.

while {condition} do {
_objects = myLogic getVariable "trash";
{
	if !(_x in trashQueu) then {
		_objects2 = myLogic getVariable "trash";
		trashQueu = trashQueu + [_x];
		_x Spawn _trashIT;
		_renewed = _objects2 - [_x] - [objNull];
		myLogic setVariable ["trash",_renewed,true];
	};
} forEach _objects;
sleep 1;
};

2. The Kill Event Handler Script:

myLogic setVariable ["trash",(myLogic getVariable "trash") + [_killed],true];

Hope that it's clear for you.

Share this post


Link to post
Share on other sites

Thanks Benny for your help. BTW love your warfare version, is this what you use in that?

Im not that good at scripting so there are a couple of things there that im not sure about. Im getting older and things take longer to sink in lol.

I have never used an event handler so how do you place over units?

(a FSM will do the job if needed). what is an FSM?

Sorry if I seem a bit nooby, cheers

Share this post


Link to post
Share on other sites

Lets see if I got this right...

If I want a certain number of bodies to remain on the ground I merely have to put in a

if(count trashQueu > bodyNum) then {...};

around the

_x Spawn _trashIT;
_renewed = _objects2 - [_x] - [objNull];
myLogic setVariable ["trash",_renewed,true];

correct?

Share this post


Link to post
Share on other sites
Thanks Benny for your help. BTW love your warfare version, is this what you use in that?

Im not that good at scripting so there are a couple of things there that im not sure about. Im getting older and things take longer to sink in lol.

I have never used an event handler so how do you place over units?

(a FSM will do the job if needed). what is an FSM?

Sorry if I seem a bit nooby, cheers

Yes i'm currently using this on warfare, the system is light and work disregarding of the locality :).

a FSM is like a flowchart, if you have no clues about it, then just let it aside, it's a small extra ;).

Placing an EH over a unit:

/*
 _this select 0 define the killed unit.
 _this select 1 define the killer.
 those variable are special to the EH, they shall remain as they are
*/
_unit addEventHandler ["Killed",{[_this select 0,_this select 1] ExecVM "...\myHandlerScript.sqf"}];

Lets see if I got this right...

If I want a certain number of bodies to remain on the ground I merely have to put in a

if(count trashQueu > bodyNum) then {...};

around the

_x Spawn _trashIT;
_renewed = _objects2 - [_x] - [objNull];
myLogic setVariable ["trash",_renewed,true];

correct?

If you wish to let several bodies lay on the floor, add another array, since trashQueu is quickly emptied.

depending whether it's vehicle or not, you can add a pre-check

if (_x isKindOf "Man") then {
  _bodies = _bodies + [_x];
  if (count _bofies < bodyNum) then {
      //--- Here goes the rest.
  }
}

Share this post


Link to post
Share on other sites

Ok Benny I will forget about FSM lol. Thanks for your help but just one thing about the EH, do you put that code in each units int box

Cheers

BTW im just looking on wiki about EH etc

Edited by LockJaw-65-

Share this post


Link to post
Share on other sites

Depend how you do it.

Editor:

go on the leader:

{_x addEventHandler ["Killed",{[_this select 0,_this select 1] ExecVM "...\myHandlerScript.sqf"}]} forEach (units (group this))

Share this post


Link to post
Share on other sites

You can just set it on the leader of a group, it will initialize for the rest.

You can also do something in init.sqf that will add it to every unit on start.

{_x addEventHandler ["Killed",{[_this select 0,_this select 1] ExecVM "...\myHandlerScript.sqf"}]} forEach allUnits;

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  

×