/* hint "Working woo!"; */
private _unit = missionNamespace getVariable ["bis_fnc_moduleRemoteControl_unit", player]; //Get player unit

if(!(local _unit))exitWith{};


_unit addEventHandler ["WeaponRested", { //Resting shows/hides link
	params ["_unitResting", "_isRested"];
 private _currentWeapon = currentWeapon _unitResting;
 private _allowedWeapon = ["braf_Minimi"];
 private _attachment = "sp_acc_gpmg_linkhide";

	if (_currentWeapon in _allowedWeapon) then{
		if(_isRested) then {
			if (isWeaponRested _unitResting) then {
				_unitResting addPrimaryWeaponItem _attachment; // Attachment hides link in model cfg
			};
	  }else{
			if (isWeaponDeployed _unitResting == false) then { //Only remove link attachment if we know user doesn't have bipod deployed
				_unitResting removePrimaryWeaponItem _attachment;
			};
	  };
	} else { //Cleanup eventhandler if different weapon is being used
		_unitResting spawn {
			 uiSleep 0.01;
			_unitResting removeEventHandler ["WeaponRested", _thisEventHandler];
		};
	};
}];


_unit addEventHandler ["WeaponDeployed", { //Deploying plays animation for holding stock
	params ["_unitDeploying", "_isDeployed"];

 	private _currentWeapon = currentWeapon _unitDeploying;
  private _allowedWeapon = ["braf_Minimi"];
 	private _anim = "sp_GestureDeployedGPMG";


	if (_currentWeapon in _allowedWeapon) then{
		if(_isDeployed) then {
			_unitDeploying playAction _anim;
	  }else{
			_unitDeploying playAction "gestureNod";
	  };
	} else { //Cleanup eventhandler if different weapon is being used
		_unitDeploying spawn {
			 uiSleep 0.01;
			_unitDeploying removeEventHandler ["WeaponDeployed", _thisEventHandler];
		};
	};
}];


_unit addEventHandler ["Take", { //When reloading, check if weapon is deployed and if so play animation for holding stock
	params ["_unitTaking"];
	private _currentWeapon = currentWeapon _unitTaking;
  private _allowedWeapon = ["braf_Minimi"];
 	private _anim = "sp_GestureDeployedGPMG";

	if (_currentWeapon in _allowedWeapon) then{
		if(isWeaponDeployed _unitTaking) then {
			_unitTaking playAction _anim;
	  };
	} else { //Cleanup eventhandler if different weapon is being used
		_unitTaking spawn {
			 uiSleep 0.01;
			_unitTaking removeEventHandler ["Take", _thisEventHandler];
		};
	};
}];
