main()
{
	self endon("ex_gameover");
		
	for(;;)
	{
		wait 1;
		players = getentarray("player", "classname");
		if(players.size <= 0 ) continue; 
		
		for(i = 0; i < players.size; i++)
		{
			player = players[i];
			
			if(player.pers["dontkick"] == true) continue;
			
			if(isDefined(player.spec_time))
			{
				if(player.sessionstate == "playing" && !level.ex_inactive_plyr || player.sessionstate != "playing" && !level.ex_inactive_spec) 
				{
					player.spec_time = undefined;
					continue;
				}
			}
			
			if(player.sessionstate != "playing" && level.ex_inactive_spec || player.sessionstate == "playing" && level.ex_inactive_plyr)
	        {
				
				
				if(!isDefined(player.spec_time)) 
				{	
					player.spec_time = level.ex_inactive_time * 60; 
					player.oldorg = player.origin;
					player.act = 0;
					continue;
				}
				
				else if(isDefined(player.spec_time))
				{	
					//check if player is afk
					player.org = player.origin;
					
					if(!level.ex_afk && player.sessionstate != "playing") 
						{
							player.org = player.oldorg;
						}
						
					if(player.oldorg != player.org)
					{	
						
						player.oldorg = player.origin;
						player.spec_time = level.ex_inactive_time * 60;
						if(player.act) player playLocalSound("US_mp_rsp_tooklongenough");player.act = 0;
						continue; 
					}
					
					player.spec_time = (player.spec_time - 1);
					
					if(player.spec_time == 30 || player.spec_time == 20 || player.spec_time == 10)
					{
					 player iprintln(player,&"CLIENTCONTROL_INACTIVITY_WARNING_A_1", player.spec_time,&"CLIENTCONTROL_INACTIVITY_WARNING_B_1");
					 if(player.sessionstate == "playing") player playLocalSound("move_it_" + player.spec_time);
					 else player playLocalSound("US_1_rank_private");
					 player.act = 1;
					 continue;
					}
				
					else if(player.spec_time < 1)
				    {
						kick(player getEntityNumber());
					    players = getentarray("player", "classname");
	                    for(i = 0; i < players.size; i++)
	                    {
		                    plyrs = players[i];
		                    plyrs iprintln(&"CLIENTCONTROL_INACTIVITY_WARNING_2", plyrs);
						}
					}	
				}
			}
		}
	}
}

