-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathplayerDisconnected.sqf
61 lines (56 loc) · 1.76 KB
/
playerDisconnected.sqf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
TAG_fnc_loadClientData = {
_this params ["_loadoutStr", "_positionASL", "_dir"];
call compile _loadoutStr;
player setDir _dir;
player setPosASL _positionASL;
};
if(isServer) then {
addMissionEventHandler [
"HandleDisconnect",
{
params ["_body", "_id", "_uid", "_name"];
if(!isNull _body) then {
//Init storage var
if(isNil "TAG_disconnectedLoadouts") then {
TAG_disconnectedLoadouts = [];
};
//Save loadout as script for easy broadcast
private _loadoutStr = [player, "script", false] call BIS_fnc_exportInventory;
{
private _index = _loadoutStr find _x;
if(_index > -1) then {
private _strArray = toArray _loadoutStr;
_strArray deleteRange [_index, count _x];
_loadoutStr = toString _strArray;
};
} forEach ["// Remove existing items","// Add containers","// Add weapons", "// Add items", "// Set identity"];
//Find in storage
private _uidIndex = TAG_disconnectedLoadouts find _uid;
if(_uidIndex > -1) then {
//Found -> update
private _loadoutIndex = _uidIndex + 1;
TAG_disconnectedLoadouts set [_loadoutIndex, _loadoutStr];
} else {
//Not found -> Add new
TAG_disconnectedLoadouts pushBack _uid;
TAG_disconnectedLoadouts pushBack [_loadoutStr, getPosASL _body, getDir _body];
};
};
false
}
];
addMissionEventHandler [
"PlayerConnected",
{
params ["_id", "_uid", "_name", "_jip", "_owner"];
if(_jip) then {
private _clientData = missionNamespace getVariable ["TAG_disconnectedLoadouts", []];
private _uidIndex = _clientData find _uid;
if(_uidIndex > -1) then {
private _loadoutIndex = _uidIndex + 1;
(_clientData select _loadoutIndex) remoteExec ["TAG_fnc_loadClientData", _owner];
};
};
}
];
};