#include "..\script_component.hpp"

if (!hasInterface) exitWith {};

[
	"respawn", 
	{
		_clientID = _thisArgs select 0;
		player setDamage 1;

		private _timeWentUnconscious = player getVariable [QGVARMAIN(lastTimeKnockedOut), -1];
		private _durationSpentUnconscious = -1;
		if (_timeWentUnconscious > - 1) then {
			_durationSpentUnconscious = diag_tickTime - _timeWentUnconscious;
		};

		// log to server RPT
		[
			LEVEL_INFO,
			QUOTE(COMPONENT),
			"CHAT COMMAND RESPAWN",
			[player, [
				["durationSpentUnconscious", _durationSpentUnconscious]
			]] call EFUNC(common,addPlayerInfoToArray)
		] remoteExec [QEFUNC(common,log), 2];

		// systemChat to all remote machines
		format["%1 claims they were glitched and respawned (%2)", name player, netID player] remoteExec["systemChat", -_clientID];
	},
	"all",
	[clientOwner]
] call CBA_fnc_registerChatCommand;

[
	LEVEL_INFO,
	QUOTE(COMPONENT),
	"respawn chat handler registered",
	[player] call EFUNC(common,addPlayerInfoToArray)
] call EFUNC(common,log);

nil;