/*
 Respawn_player.SQF © Pumpkin
 version 2.0 - ArmA 2 seul (non OA)

 récupération des armes à l'identique au moment de la mort du joueur; sans paramètres

 exemples :
 1.) lancement direct :
     nul = execVM "lib\Respawn_player.sqf";
 2.) lancement par event handler :
     player addeventhandler ["Killed", {execVM "Respawn_player.sqf"}];

*/

_testclient = call compile preprocessFile "lib\Client_detection.sqf";
if (not _testclient) exitwith {};

_oldplyer = player;

_plyerwpns = weapons player;
_plyermags = magazines player;
_pWeap = primaryWeapon player;
_sWeap = secondaryWeapon player;

removeallweapons player;
sleep 0.2;
//_wpnreste = weapons player;

waitUntil {alive player};
sleep 0.2;
deleteVehicle _oldplyer;
removeallweapons player;
waituntil {primaryWeapon player == ""};
waituntil {secondaryWeapon player == ""};

 //_plyerwpns = _plyerwpns - _wpnreste;

for [{_i = 0},{_i < count _plyermags},{_i = _i + 1}] do { player addmagazine (_plyermags select _i) };
for [{_i = 0},{_i < count _plyerwpns},{_i = _i + 1}] do { player addweapon (_plyerwpns select _i) };

if (_pWeap != "") then {
	waitUntil {primaryweapon player != ""};
};
if (_sWeap != "") then {
	waitUntil {secondaryWeapon player != ""};
};

_weap = _pWeap;
if (_pWeap == "") then { _weap = _sWeap };


player selectweapon _weap;
_wpncfg = configFile >> "CfgWeapons" >> _weap;
_wpnname = getText (_wpncfg >> "displayName");
_wpnmuzzles = getArray (_wpncfg >> "muzzles");
player selectweapon (_wpnmuzzles select 0);

reload player;
player playmove "null";

//disableUserInput true;
sleep 0.1;
player action ["WEAPONONBACK",player];
sleep 0.1;
player action ["WEAPONINHAND",player];
sleep 0.1;
//disableUserInput false;
