851 {
852 NVGoggles NVGAttachment;
853 NVGAttachment = NVGoggles.Cast(FindAttachmentBySlotName("NVG"));
854 bool has_nvg_slot;
855 for (int i = 0; i < GetInventory().GetAttachmentSlotsCount(); i++)
856 {
857 has_nvg_slot = GetInventory().GetAttachmentSlotId(i) == InventorySlots.GetSlotIdFromString("NVG");
858 if (has_nvg_slot)
859 break;
860 }
861
862 if ( player && has_nvg_slot )
863 {
864 if ( NVGAttachment )
865 {
866 NVGAttachment.LoweredCheck();
867
868 if ( attaching && NVGAttachment.m_Strap && NVGAttachment.m_IsLowered )
869 {
870 NVGAttachment.SetPlayer(player);
871 player.SetNVGLowered(true);
872
873 if ( player.IsControlledPlayer() )
874 {
875 if ( NVGAttachment.IsWorking() )
876 {
877 player.AddActiveNV(
NVTypes.NV_GOGGLES);
878
879 }
880 else
881 {
882
883 player.RemoveActiveNV(
NVTypes.NV_GOGGLES);
884 }
885 }
886 }
887 else
888 {
889 NVGAttachment.SetPlayer(null);
890 player.SetNVGLowered(false);
891
892 if ( player.IsControlledPlayer() )
893 {
894 player.RemoveActiveNV(
NVTypes.NV_GOGGLES);
895
896 }
897 }
898 }
899 else if ( player.IsNVGWorking() && force_disable )
900 {
901 player.SetNVGLowered(false);
902
903 if ( player.IsControlledPlayer() )
904 {
905 player.RemoveActiveNV(
NVTypes.NV_GOGGLES);
906
907 }
908 }
909 }
910 }