Jump to content
Sign in to follow this  
djules

delete dead bodies on disconnected players

Recommended Posts

hello everyone,

i hope you can help me, i searched already but i didnt found a solution yet.

im pretty new to scripting and i'm looking for a simple script that deletes a body and his weapon as soon as he disconnects.

i found a way to have a routine that deletes, lets say every 5minutes all weapons and bodies on the ground, but i want it to delete them as soon as the player disconnects.

would someone kindly provide some help?

thanks a lot guys

Share this post


Link to post
Share on other sites

See this post for help. :)

Share this post


Link to post
Share on other sites

hey luki, thanks for your help but thats not what i am looking for.

i want them to get deleted when the player disconnects, not when he dies. as i said i also dont want a routine, that runs in a 5min cycle or something.

i was trying around with "onPlayerDisconnected" but i dont even know where to start.. :/

thanks a lot anyways

i was also trying to get this to work only if a player disconnects.. its a serverside FSM

    class Delete_dead_bodi
   {
     name = "Delete_dead_bodi";
     init = /*%FSM<STATEINIT""">*/"{" \n
      "	deleteVehicle _x;" \n
      "} foreach allDeadMen;"/*%FSM</STATEINIT""">*/;
     precondition = /*%FSM<STATEPRECONDITION""">*/""/*%FSM</STATEPRECONDITION""">*/;
     class Links
     {
       /*%FSM<LINK "true">*/
       class true
       {
         priority = 0.000000;
         to="Share__Work_load";
         precondition = /*%FSM<CONDPRECONDITION""">*/""/*%FSM</CONDPRECONDITION""">*/;
         condition=/*%FSM<CONDITION""">*/"true"/*%FSM</CONDITION""">*/;
         action=/*%FSM<ACTION""">*/""/*%FSM</ACTION""">*/;
       };
       /*%FSM</LINK>*/
     };
   };

this way, the corpse are getting deleted instantly, but theyre also getting deleted if a player got killed, i dont want this because i want them to keep in a revivable state

Edited by djules

Share this post


Link to post
Share on other sites

If you have disabledAI = 1; in your mission's description.ext, this should happen automatically, but obviously it's not suited for every mission.

Share this post


Link to post
Share on other sites
hey luki, thanks for your help but thats not what i am looking for.

i want them to get deleted when the player disconnects, not when he dies. as i said i also dont want a routine, that runs in a 5min cycle or something.

Try this line:

onPlayerDisconnected "deleteVehicle player;";

Share this post


Link to post
Share on other sites

Have you been able to solve this issue? I'm facing the same problem. Though I set disabledAI=1; they still remain on the ground dead after disconnect, sometimes with their gear on them and sometimes with nothing.

Share this post


Link to post
Share on other sites
Have you been able to solve this issue? I'm facing the same problem. Though I set disabledAI=1; they still remain on the ground dead after disconnect, sometimes with their gear on them and sometimes with nothing.

Bodies are now stay until either you delete them yourself or they are deleted by disposal manager. You can configure disposal manager to your liking how you want those bodies deleted:

https://community.bistudio.com/wiki/Description.ext#corpseManagerMode

Share this post


Link to post
Share on other sites

I'd use this (run at server only):

["deleteDisconnected", "onPlayerDisconnected", {
[_name,_uid] spawn {
	private ["_name","_uid","_clientId","_unit"];
	_name = _this select 0;
	_uid = _this select 1;
	_clientId = -1;
	_unit = objNull;

	while {_clientId == -1} do {
		{
			if (getPlayerUID _x == _uid) exitWith {
				_clientId = owner _x;
				_unit = _x;
				deleteVehicle _unit;
			};
		} forEach playableUnits;
		sleep .02;
	};
	deleteVehicle _unit;
};
}] call BIS_fnc_addStackedEventHandler;

Share this post


Link to post
Share on other sites

Have you actually tested that Tajin?

Not saying it does not work, but on reading it is something that makes me suspicious as its highly dependent on when the unit get disassociated from the player and his UID and would normal send me off testing. But if you have that saves some time :)

Share this post


Link to post
Share on other sites

Well, I haven't used it for deleting bodies, only for saving gear-loadouts to db on disconnect. That shouldn't make a difference, but testing is always good.

Besides, you seem to have misunderstood the loop. It doesn't wait for the unit to get disassociated. That loop is merely used to find the unit/body that belonged to the player that is disconnecting.

Share this post


Link to post
Share on other sites

No i have not misunderstood the loop. Im basically saying that if (getPlayerUID _x == _uid) exitWith { highly depends on when the unit (_x) gets disassociated from the player who has now disconnected. As in, if the unit _x no longer has any association with the disconnected player you would never get a UID to check against _uid.

Anyway does not matter as you have said you have used it with no problems.

Share this post


Link to post
Share on other sites

@Tajin, your code didn't work for me. I put it in an SQF that's executed by init.sqf. Any ideas?

@Killzone_Kid, CorpseManager would delete bodies of dead people. I only want the bodies of disconnecters gone as they can now go to lobby -> log back in -> dupe all gear.

Share this post


Link to post
Share on other sites

Try something like..

addMissionEventHandler ["HandleDisconnect", { 
_unit  = _this select 0;
_pos = getPosATL _unit;

_wholder = nearestObjects [_pos, ["weaponHolderSimulated", "weaponHolder"], 2];

{
	deleteVehicle _x;
}forEach _wholder + [_unit];

false
}];

untested.

Share this post


Link to post
Share on other sites

Had the same problem and this is how I handled it:

//Init.sqf (server):
if (isServer || isDedicated) then 
{
"playableUnitOccupier_PV" addPublicVariableEventHandler {

	private "_playableUnit";

	_playableUnit = [_this,1,objNull] call BIS_fnc_param;

	if(!isNull _playableUnit) then 
	{
		missionNamespace setVariable[getPlayerUID _playableUnit,_playableUnit];
	}; 
};

["deleteBodyOnPlayerDisccndId", "onPlayerDisconnected", {

   private "_body";

   _body = missionNamespace getVariable [_uid,objNull];

   if (!isNull _body) then 
   {
		deleteVehicle _body;
		missionNamespace setVariable[_uid,nil];
   };

}] call BIS_fnc_addStackedEventHandler;


};

//Init.sqf (client) :
if(!isDedicated) then 
{
waitUntil {Alive player};

playableUnitOccupier_PV = player; publicVariableServer "playableUnitOccupier_PV";

player addEventHandler ["Respawn", {
	playableUnitOccupier_PV = _this select 0; publicVariableServer "playableUnitOccupier_PV";
}];
};

Hope it helps

Edited by jrog

Share this post


Link to post
Share on other sites
Had the same problem and this is how I handled it:

//Init.sqf (server):
if (isServer || isDedicated) then 
{
"playableUnitOccupier_PV" addPublicVariableEventHandler {

	private "_playableUnit";

	_playableUnit = [_this,1,objNull] call BIS_fnc_param;

	if(!isNull _playableUnit) then 
	{
		missionNamespace setVariable[getPlayerUID _playableUnit,_playableUnit];
	}; 
};

["deleteBodyOnPlayerDisccndId", "onPlayerDisconnected", {

   private "_body";

   _body = missionNamespace getVariable [_uid,objNull];

   if (!isNull _body) then 
   {
		deleteVehicle _body;
		missionNamespace setVariable[_uid,nil];
   };

}] call BIS_fnc_addStackedEventHandler;


};

//Init.sqf (client) :
if(!isDedicated) then 
{
waitUntil {Alive player};

playableUnitOccupier_PV = player; publicVariableServer "playableUnitOccupier_PV";

player addEventHandler ["Respawn", {
	playableUnitOccupier_PV = _this select 0; publicVariableServer "playableUnitOccupier_PV";
}];
};

Hope it helps

Thank jrog, this script is working for me as intended. Loggers bodies disappear and killed players bodies stay. Well done.

I am, however, receiving this error in the server rpt file:

4:41:11 Error in expression <tHandler; 
missionNamespace setVariable[_uid,nil];


4:41:11   Error position: <_uid,nil];


4:41:11   Error Undefined variable in expression: _uid
4:41:11 File mpmissions\__cur_mp.Altis\server\init.sqf, line 26

Although this doesn't appear to be effecting the outcome of the script I'm worried the error could have implications down the line.

Cheers.

Share this post


Link to post
Share on other sites

@Caffeind

I don't get the error.

This is the script I use combined with @Larrow's one, to prevent from grabbing dropped, before the player disconnected, items and weapons:

if (!isServer || !isDedicated) exitWith {};

["onPlayerDiscnndId", "onPlayerDisconnected", {

  private ["_body","_weaponholders"];

  _body = missionNamespace getVariable _uid;

  if (!isNull _body) then 
  {
	_weaponholders = [];

	_weaponholders = nearestObjects [getPosATL _body, ["weaponHolderSimulated", "weaponHolder"], 20];

	{
	    deleteVehicle _x;
	}forEach _weaponholders;

	deleteVehicle _body;

       missionNamespace setVariable [_uid,nil];
  };

}] call BIS_fnc_addStackedEventHandler;

Edited by jrog

Share this post


Link to post
Share on other sites
Had the same problem and this is how I handled it:

//Init.sqf (server):
if (isServer || isDedicated) then 
{
"playableUnitOccupier_PV" addPublicVariableEventHandler {

	private "_playableUnit";

	_playableUnit = [_this,1,objNull] call BIS_fnc_param;

	if(!isNull _playableUnit) then 
	{
		missionNamespace setVariable[getPlayerUID _playableUnit,_playableUnit];
	}; 
};

["deleteBodyOnPlayerDisccndId", "onPlayerDisconnected", {

   private "_body";

   _body = missionNamespace getVariable [_uid,objNull];

   if (!isNull _body) then 
   {
		deleteVehicle _body;
		missionNamespace setVariable[_uid,nil];
   };

}] call BIS_fnc_addStackedEventHandler;


};

//Init.sqf (client) :
if(!isDedicated) then 
{
waitUntil {Alive player};

playableUnitOccupier_PV = player; publicVariableServer "playableUnitOccupier_PV";

player addEventHandler ["Respawn", {
	playableUnitOccupier_PV = _this select 0; publicVariableServer "playableUnitOccupier_PV";
}];
};

Hope it helps

Sorry for digging up old thread but, I'm only use to having one init.sqf, how do i have one for both client and server?

Share this post


Link to post
Share on other sites
Sorry for digging up old thread but, I'm only use to having one init.sqf, how do i have one for both client and server?

It is one file, not sure why he separated it to 2 separate pasties.

Share this post


Link to post
Share on other sites

A lot of the code posted above is pre- A3 1.32

Thanks to BIS Dev George we have the correct tool for the job:

https://community.bistudio.com/wiki/Arma_3:_Event_Handlers#HandleDisconnect

^ should solve all concerns re handling the body of disconnected clients.

example:

//initServer.sqf
addMissionEventHandler ['HandleDisconnect',{deleteVehicle (_this select 0);}];

If you want a delayed delete, something like this will work:

//initServer.sqf
addMissionEventHandler ['HandleDisconnect',{
[(_this select 0)] spawn {
	sleep 10;
	deleteVehicle (_this select 0);
};
}];

* Run on server only as per linked instructions

Further reading for those interested:

http://feedback.arma3.com/view.php?id=17532

  • Like 1

Share this post


Link to post
Share on other sites
5 hours ago, Samwise90 said:

but instead of the 'HandleDisconnect' it should be "HandleDisconnect"


What's the difference?

  • Like 2
  • Haha 1

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  

×