/*
	File: fn_ziptie.sqf
	Author: Tom "Nitelite" Springfield

	Description:
	Retrains the client with zipties.
*/
private["_cop","_player"];
_cop = [_this,0,Objnull,[Objnull]] call BIS_fnc_param;
_player = player;
if(isNull _cop) exitWith {};

//Monitor excessive restrainment
[] spawn
{
	private["_time"];
	while {true} do
	{
		_time = time;
		waitUntil {(time - _time) > (120 * 60)}; //(5 * 60)

		if(!(player getVariable["restrained",FALSE])) exitWith {};
		if(!(player getVariable["ziptied",FALSE])) exitWith {};
		if(!([west,getPos player,30] call life_fnc_nearUnits) || ([civilian,getPos player,30] call life_fnc_nearUnits) && (player getVariable["restrained",FALSE]) && (player getVariable["ziptied",FALSE]) && vehicle player == player) exitWith {
			player setVariable["ziptied",FALSE,TRUE];
			player setVariable["Escorting",FALSE,TRUE];
			player setVariable["transporting",false,true];
			detach player;
			titleText[localize "STR_Cop_ExcessiveRestrain","PLAIN"];
		};
	};
};

if((player getVariable["surrender",FALSE])) then
 {
 player setVariable["surrender",FALSE,TRUE];
 player switchMove "";
 };

titleText[format[localize "STR_Cop_Retrained",_cop getVariable["realname",name _cop]],"PLAIN"];
player say3D "zipties";while {player getVariable "ziptied"} do
	{
	if(vehicle player == player) then {
		player playMove "AmovPercMstpSnonWnonDnon_Ease";
	};

_state = vehicle player;
waitUntil {animationState player != "AmovPercMstpSnonWnonDnon_Ease" || !(player getvariable "ziptied") || vehicle player != _state
};

if(!alive player) exitWith	{
		player setVariable ["ziptied",false,true];
		player setVariable ["Escorting",false,true];
		player setVariable ["transporting",false,true];
		detach _player;
};

if(!alive _cop) exitWith {
		player setVariable ["Escorting",false,true];
		detach player;
};

if(vehicle player != player) then	{
		if(driver (vehicle player) == player) then
		 {player action["eject",vehicle player];
		};
	};
};

if(alive player) then
{
	player switchMove "";
	player setVariable ["Escorting",false,true];
	player setVariable ["transporting",false,true];
	detach player;
};


