------Emitters-------------------
AddParticleToObject(60,"Highlight_cup");
MoveEmiter("Highlight_cup",512,523);

AddParticleToObject(57,"Highlight_door");
MoveEmiter("Highlight_door",205,450);

AddParticleToObject(201,"fakel1");
MoveEmiter("fakel1",242,150);
StartEmiter("fakel1");

AddParticleToObject(202,"fakel2");
MoveEmiter("fakel2",785,150);
StartEmiter("fakel2");

AddParticleToObject(203,"fakel3");
MoveEmiter("fakel3",510,525);
StartEmiter("fakel3");

AddParticleToObject(204,"fakel4");
MoveEmiter("fakel4",685,305);
StartEmiter("fakel4");

AddParticleToObject(205,"fakel5");
MoveEmiter("fakel5",567,322);
StartEmiter("fakel5");

AddParticleToObject(206,"fakel6");
MoveEmiter("fakel6",465,322);
StartEmiter("fakel6");

AddParticleToObject(207,"fakel7");
MoveEmiter("fakel7",285,395);
StartEmiter("fakel7");
------End Emitters------------
-- CreateConsole()
local speed = 1;
nice_27_level = true;
pointer = false;
flag = false;

WaitRender();

Set_Cursor(60,4);

function comicsNV()
if not flags.comics4 then return;end;
	flags.comics4 = false;
	flag = true;
	CreatePlashechka(79,"107","goodgirl")	
	SwitchToSheet("gr")
return;end;

function gameinput( sender,obj_id,attachedID )
	if SLevel==1.0 then return; end;
	 if (sender == 1  or sender==5) and not isTimes  and imagetex~=-1 then
			set_visible_object(obj.plashechka.id,false)
			set_visible_object(obj[imagetex].id,false)
			del_object_from_game(5654547)		
			gameinput(26,imageid)		
del_object_from_game(5654547)
				del_object_from_game(5654547)
				del_object_from_game(5654547)
				del_object_from_game(5654547)
				del_object_from_game(5654547)
				del_object_from_game(5654547)				
	end
	if sender == 6 then
		if flags.first_time_load then
			flags.first_time_load = false;		
		end;
		if not flags.comics1 and not flags.light and not flags.n_vision then
			CreatePlashechka(4,"201","goodgirl")
		end
		if flags.light and not flags.nv_done then
			CreatePlashechka(4,"202","goodgirl")
		end
		if rentgen_is_usable and not flags.xray then
			CreatePlashechka(4,"203","goodgirl")
		end
		if flags.xray then
			CreatePlashechka(4,"205","goodgirl")
		return;end;
	end;	
	
	if sender == 33 then	
		if flags.finish then
			ShowMenu(false);
		else
			ShowMenu(true);
			SwitchToSheet("re");
			if flags.all_items27 then
			SwitchToSheet("gr")
			end
		end;
	return;end;
	
	if sender == 2 then
		RemoveFromMouse(object);
		MessageProc(sender,obj_id);
	return;end;	
	if sender == 41 then	
	if obj_id == obj.bat_27.id then
		StartTimer(555,20);
	end
		RotateHandler(obj_id);	
		
	if obj_id ==obj.dragonfly.id then	
		StartAnimation( 5555555555,1,5 );
	return;end;	
	
	return;end;	
--обработка рентгена	
	if sender == 100001 then
		speciale_action(4,61);
		speciale_action(2,61,true);
		flags.xray = true;
		Set_Cursor(57,2);
	end;
--обработка ПНВ когда уезжает уже	, засвет
	if sender == 1000022 and flags.light then
				flags.n_vision = false;
				flags.nv_done = true;
				speciale_action(2,56);				
				flags.nvg_block=true;	
				canmenu=false
				flags.lvl27flag=false
				canusegadjets=false
	end
--обработка ПНВ	
	if sender == 100002 then
		if not flags.nv_done then
			if not flags.light then
				
				StartTimer(2323232,1,"canmenu1")
				
				function canmenu1()
					canusegadjets=true
				end
				flags.lvl27flag=true;
				set_visible_object(-100022, false);
				flags.n_vision = not flags.n_vision;				
				--flags.nv = true;
				speciale_action(2,55);
				speciale_action(2,60);
				SwitchToSheet("gr")			
				declineGadjet=false
				-- Fourth Comics --
				if flags.comics4 and flags.n_vision then					
					StartTimer(8888, 0.5);
					
				end;
				-- End Fourth Comics --	
			else
				flags.n_vision = false;
				flags.nv_done = true;
				speciale_action(2,56);
			end;
		else
			CreatePlashechka(4,"301","goodgirl")
		end;
		if flags.n_vision then
			StartEmiter("Highlight_cup");
		else
			StopEmiter("Highlight_cup");
		end;
	return;end;
	
	if sender==777 then
	--старт локации	
			if  flags.comics1 then			
				
				StartTimer(43342,0.5,"conv27")
			function conv27()
				CreatePlashechka(79,"101","goodgirl")	
			end		
				ShowMenu(true)
				SwitchToSheet("re")
				flags.comics1=false;
			return;end
--старт мини	
		if flags.dver then	
			leafobj={2234}
			GetRenderTarget(2234,"rendertar");	
			mininame="mini";
			mininum1=27;
			mininum2=10;
			mininame2="dark_cave";	
	return;end
	if top_plush_id then		
		ShowMenu(true)
		end	
	end

	
	
	if sender == 100 then

	if  not flags.kluch  then
			flags.kluch= true;
			AddElement(sheet,obj.kluch27.id);
			MoveObjectToTree(obj.kluch27.id);		
			obj.kluch27.is_stored = true;			
	end	
	
	if flags.use_rent then                 
        flags.rentgen=true;
       	speciale_action(4,61);
		speciale_action(2,61,true);
		flags.xray = true;
		Set_Cursor(57,2);			
	end;
				
		if flags.xray_done then
			Set_Cursor(57,2);
		end;
		
			
		-- Third Comics --
		if flags.comics3 and flags.xray_done   then
			flags.comics3 = false;
			rentgen_is_usable = false;
			flags.xray = false;
			set_visible_object(61,false);			
			StartEmiter("Highlight_door");
			CreatePlashechka(79,"105","goodgirl")	
			flags.use_rent=false;
		return; end;
		-- End Third Comics --		
		
		if flags.first_time_load then
				flags.first_time_load=false
			set_visible_object(obj.intro.id,true);
			speciale_action(4,obj.intro.id);
			-- StartEmiter("Level");
		return; end;
		
--при сохранении в мини.	
		if flags.xray_done and not flags.mini1 and flags.dver then				
			leafobj={2234}
			GetRenderTarget(2234,"rendertar");	
			mininame="mini";
			mininum1=27;
			mininum2=10;
			mininame2="dark_cave";	
		return;end;				

		
	return; end;
	-- End WaitRender() --

	-- Left click active object --
	
	if sender == 8 then
		HideGlove();
	takeobjecttohand=false
		HideScaner();
		HideRentgen()
	if flags.light then
		HideNvg();
	end
	return end;

	
	if sender == 1 then
	
		if scaner_on then
			CreatePlashechka(9999,"70","goodgirl")
		return;end;
			
			if obj_id >= obj.kinzhal_27.id and obj_id <= obj.kinzhal_27.id + 15 and obj_id ~= obj.molot_27.id then
					if scaner_on then
						CreatePlashechka(9999,"70","goodgirl")
					return;end;
				CollapseObj(obj_id);
				flags.n = flags.n + 1;
			return;end
			if obj_id == obj.molot_27.id then
				if scaner_on then
					CreatePlashechka(9999,"70","goodgirl")
				return;end;
				CollapseObj(obj_id);
				set_visible_object(15,false);
				flags.n = flags.n + 1;
			return;end;	
--тыкамем на дверь
			if obj_id == 57 and attachedID==-1 then
				if scaner_on then
					CreatePlashechka(9999,"70","goodgirl")
				return;end;
				if flags.xray_done and not flags.mini1  then
				
				if flags.n<15 then
				CreatePlashechka(4,"303","goodgirl")
				return;end
					ClosePlushes()
					flags.dver=true;	
					SwitchToSheet("gr")			
					DeleteElement("gr",obj.kluch27.id);
				end;
			return;end;
			if flags.n_vision and obj_id == 60 then
				if scaner_on then
					CreatePlashechka(9999,"70","goodgirl")
				return;end;
			if attachedID == 111 then
				takeobjecttohand=false
				RemoveFromMouse(attachedID);
				DeleteElement(sheet,attachedID);
				
				playeffect("112")
				playeffect("113",true)
				declineGadjet=true
				speciale_action(2,55);
				speciale_action(2,54);
				speciale_action(2,60);
				speciale_action(2,56);
				speciale_action(2,obj.bat_27.id);
				StartAnimation(obj.bat_27.id);
				SwitchToSheet("re")
				flags.light = true;
				flags.comics4=true;	
				StartTimer(2323232,0.3,"canmenu2")
				-- flags.lvl27flag=true;
				function canmenu2()
					canmenu=false					
					declineGadjet=true
					nvgselect=true
				end
				CreatePlashechka(4,"202","goodgirl")				
			else
				CreatePlashechka(4,"204","goodgirl")
			end;
		end;
	return; end;
	
	if sender == 14 then
		
			-- takeobjecttohand=true
			addObjectToMouse(obj_id);
		
	return;end;
	
	if sender == 12 then
		if not flags.all_items27 then
		if obj.kinzhal_27.is_collapsed and obj.mech_27.is_collapsed and obj.topor_27.is_collapsed and obj.amfora1_27.is_collapsed and 
			obj.amfora2_27.is_collapsed and obj.zamok_27.is_collapsed and obj.strekoza_27.is_collapsed and obj.kubok1_27.is_collapsed and
			obj.kubok2_27.is_collapsed and obj.kubok3_27.is_collapsed and obj.pauk_27.is_collapsed and	obj.veer_27.is_collapsed
			and obj.slitok_27.is_collapsed and obj.amfora3_27.is_collapsed and obj.molot_27.is_collapsed then
			flags.all_items27 = true;		
			-- Second Comics --
			if flags.comics2 and not flags.rentgen then
				flags.comics2 = false;
				rentgen_is_usable = true;
				CreatePlashechka(79,"104","goodgirl")	
			return; end;
			-- End Second Comics --
		return;end;
		end
	end;
	
	if sender == 15 then
		if obj_id == 61 then
			flags.xray_done = true;
		end;
		WaitRender();
	end;
	
	if sender == 36 then
	 if obj_id ==555 then
	 	StartTravel(obj.bat_27.id,1,nil,nil,{"InstantiationOfLine",2,-100,403,1200,403,4,false});
	 
	 return;end
	   
		
	end;
		
end;

function SelectRandom()
local dist=-1;local a=-1;local b=-1;local v=100;local t=-1;local diag=-1;
local width = -1;local height = -1;local radius=1.2;
				
	if flags.n >= 15 or not flags.light then
		if not flags.nv_done then
		computation(60);				
		elseif flags.xray_done then
		computation(57);				
		elseif not flags.xray_done then
			if not flags.xray then
				CreatePlashechka(4,"203","goodgirl")
				StartTimer(43224,0.1,"muha")
				
				function muha ()
					StartAnimation( 5555555555,1,5 );			
				end
				
			else
				StartTimer(43224,0.1,"muha")
				
				function muha ()
					StartAnimation( 5555555555,1,5 );				
				end
				CreatePlashechka(4,"205","goodgirl")
			end;
		return;end;
		
		return
	end
	ok = false
	while not ok do
		help_id = GetRandomObject();
		for i,v in pairs(obj) do
			if v.id == help_id and not v.is_collapsed then
				ok = true
				x,y=GetObjectPosition(v.id);
				x1,y1=GetObjectPosition(obj.dragonfly.id);
				width,height = GetObjectSize(v.id)
				a= (x-x1); b= (y-y1);  dist= math.sqrt (a^2+b^2);				
		        t=dist/400;		
                r = (math.sqrt(width^2+height^2)*0.5);		
				
				if r<50 then	r=75;	radius=4;	end  -- при радиусе меньше 50 определяем время кружения и радиус стрекозы
				
				if r>50 and r <100 then	r=87 radius=2.5;  end  --при радиусе больше 50 и меньше 100
				
				if r>100 then 	r=100 	radius=0.75;  end  -- при радиусе больше 100
				
			StartBigTravel(obj.dragonfly.id, v.id, 0, t, r/90, t, 2 ,radius);
			return end
		end
	end
end;