Jump to content
Sign in to follow this  
doomanchu

onPlayerDisconnected

Recommended Posts

I'm in need of help adding a few onPlayerDisconnected lines into my init.sqf file.

I have a few playable units with AI attached to them. When these players disconnect, I need the AI to be killed.

Basically;

onPlayerDisconnected west01; west01a setdamage 1; west01b setdamage 1; west01c setdamage 1;

onPlayerDisconnected east01; east01a setdamage 1; east01b setdamage 1; east01c setdamage 1;

Just not sure the proper structure for these.

Share this post


Link to post
Share on other sites

Got some help at Armaholic:

onPlayerDisconnected = "
if (!isPlayer west01) then { {_x setDammage 1} foreach [west01a,west01b,west01c] };
if (!isPlayer east01) then { {_x setDammage 1} foreach [east01a,east01b,east01c] }; ";

But, it's not working. Any help figuring out what's wrong would be great!

Share this post


Link to post
Share on other sites

Perhaps side is not recorded on disconnect? How are they spawned? If units are named, and groups are made depending on that named unit, you could deleteVehicle the group connected to said name in a similar manner to the 'side' method outlined.

Share this post


Link to post
Share on other sites

west01 and east01 are player names

west01a, west01b and west01c are all names given to the AI attached to the player west01

east01a, east01b and east01c are all names given to the AI attached to the player east01

Hope that helps.

Still having problems with this. Haven't gotten it to work yet and would love to find a solution.

Edited by doomanchu

Share this post


Link to post
Share on other sites

I've also tried using the following and it's not working either.

onPlayerDisconnected = "{if (!isPlayer _x) then {_x setDammage 1}} foreach units group player";

Any help would be greatly appreciated!

Share this post


Link to post
Share on other sites

onPlayerDisconnected = "{if (!isPlayer _x) then {_x setDammage 1}} foreach units group player";

Well... if the player just disconnected, how are you supposed to get his group?

Actually, I don't really know much about how onPlayerDisconnected works, and whether or not you can reference the player's unit in it (might be a reserved variable). What does the wiki say?

---------- Post added at 08:42 AM ---------- Previous post was at 08:40 AM ----------

From the comref:

Variables _id and _name are set.

So I guess not... :confused_o:

Share this post


Link to post
Share on other sites

Try to works with teams array, easier for JIP, store the groups of both side at the mission init into some array like,

westTeams = [group west01,group west02];

Groups are the easiest things to handle, they remain all along the game for playable units. Meaning you can do whatever you want trough JIP.

You can also use allGroups command, but it's a bit heavier for this purpose (depends if there's other team or not).

just pass the name in onplayerdisconnected.

Ex (we wana find which leader disconnected):

OnPlayerDisconnected "[_name] ExecVM ""Server_PlayerDisconnected.sqf""";

 
//--- Server_PlayerDisconnected.sqf

//--- Try to find the name of the player who disconnected in the teams.
_name = _this select 0;
_team = ObjNull;
{if (Name Leader _x == _name) then {_team = _x}} ForEach eastTeams;
{if (Name Leader _x == _name) then {_team = _x}} ForEach westTeams;

//--- Not found?.
if (IsNull _team) exitWith {};

_side = side _team;

//--- We get the units and kill them.
_units = Units _team;
{x setDammage 1} forEach _units;

Edited by Benny.

Share this post


Link to post
Share on other sites

When the player disconnects, all his AI - which were local to the client computer - move to the control of the server.

You can spawn a script on the server for each AI created which loops round (or waitUntils...) the right moment and then kills them.

Or maybe it's easier to check every minute or two whether you have stray AI wandering around.

if !(isPlayer (leader _unit)) then {deleteVehicle _unit};

Edited by Mr Fenix
forgot then

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  

×