
forward PlayerControl ( playerid ) ;
public PlayerControl ( playerid )
{
	if ( !IsLogged ( playerid ) ) return 1;
	
	GetPlayerPos ( playerid, PLAYER [ playerid ] [ POSITION ] [ 0 ], PLAYER [ playerid ] [ POSITION ] [ 1 ], PLAYER [ playerid ] [ POSITION ] [ 2 ] ) ;
	GetPlayerFacingAngle ( playerid, PLAYER [ playerid ] [ POSITION ] [ 3 ] ) ;
	
	switch ( GetPlayerState ( playerid ) )
	{
		case PLAYER_STATE_DRIVER:
		{
			new check_veh = GetPVarInt ( playerid, "VehicleID" ),
				use_enter = GetPVarInt ( playerid, "UseEnterVehicle" ),
				crash,
				vehicleid = GetPlayerVehicleID ( playerid ),
				Float:VHealth ;
			
			if ( check_veh != -1 && use_enter == 0 && vehicleid != check_veh )
				return AntiCheatMessage ( playerid, "Угон авто с помощью читов" ) ;
			
			GetVehicleHealth ( vehicleid, VHealth ) ;
			
			if ( VHealth > VEHICLE [ vehicleid ] [ HEALTH ] ) 
				SetVehicleHealth ( vehicleid, VEHICLE [ vehicleid ] [ HEALTH ] ) ; 
			else if ( VHealth < VEHICLE [ vehicleid ] [ HEALTH ] ) 
			{
				new Float:amount = VEHICLE [ vehicleid ] [ HEALTH ] - VHealth;
				
				if ( amount > 150 ) crash = 1;
				
				if ( GetPVarInt ( playerid, "Belt" ) == 1 ) amount = amount / 5 ; else amount = amount / 10 ;
				OnPlayerTakeDamage ( playerid, 1001, amount, -1001 ) ;
				
				SetPlayerHealthAC ( playerid, ( PLAYER [ playerid ] [ HEALTH ] - amount ) ) ;
				
				if ( PLAYER [ playerid ] [ HEALTH ] <= 0 ) OnPlayerCommandText ( playerid, "/me разбился в ДТП" ) ;
				VEHICLE [ vehicleid ] [ HEALTH ] = VHealth;
			}
			
			if ( VEHICLE [ vehicleid ] [ TYPE ] == VPLAYER || VEHICLE [ vehicleid ] [ TYPE ] == VFRACTION )
			{
				GetVehiclePos ( vehicleid, VEHICLE [ vehicleid ] [ POSITION ] [ 0 ], VEHICLE [ vehicleid ] [ POSITION ] [ 1 ], VEHICLE [ vehicleid ] [ POSITION ] [ 2 ] ) ;
				GetVehicleZAngle ( vehicleid, VEHICLE [ vehicleid ] [ POSITION ] [ 3 ] ) ;
			}
			
			if ( VEHICLE [ vehicleid ] [ ENGINE ] == VEHICLE_PARAMS_ON )
			{
				VEHICLE [ vehicleid ] [ FUEL ] -= 0.004;
				if ( VEHICLE [ vehicleid ] [ FUEL ] < 1 || crash == 1 || VEHICLE [ vehicleid ] [ HEALTH ] <= 300 )
				{
					new engine, lights, alarm, doors, bonnet, boot, objective;
					GetVehicleParamsEx ( vehicleid, engine, lights, alarm, doors, bonnet, boot, objective ) ;
					SetVehicleParamsEx ( vehicleid, VEHICLE_PARAMS_OFF, lights, alarm, doors, bonnet, boot, objective ) ;
					VEHICLE [ vehicleid ] [ ENGINE ] = VEHICLE_PARAMS_OFF;
					OnPlayerCommandText ( playerid, "/до Двигатель заглох." ) ;
				}
			}
			else
			{
				if ( GetPlayerSpeed ( playerid ) > 50 ) SetPVarInt ( playerid, "EngineWarn", GetPVarInt ( playerid, "EngineWarn" ) + 1 ) ;
				if ( GetPVarInt ( playerid, "EngineWarn" ) > 10 ) return AntiCheatMessage ( playerid, "Езда на заглушеном авто" ) ;
			}
			
			new string [ 64 ];
			echo ( string,"~y~F: %s%.0f", ( VEHICLE [ vehicleid ] [ FUEL ] < 10 ) ? ( "~r~" ) : ( "~w~" ), VEHICLE [ vehicleid ] [ FUEL ] ) ;
			PlayerTextDrawSetString ( playerid, Speed [ playerid ] [ 3 ], string ) ;
		}
		
		case PLAYER_STATE_ONFOOT:
		{
			
		}
	}
	
	/*#######################################################################################################################################################
	################################################# 	Античит на деньги	 			  ###################################################################
	#########################################################################################################################################################*/
	
	if ( GetPlayerMoney ( playerid ) != PLAYER [ playerid ] [ MONEY ] )
		ResetPlayerMoney ( playerid ), GivePlayerMoney ( playerid, PLAYER [ playerid ] [ MONEY ] );
	
	/*#######################################################################################################################################################
	################################################# 	Ограничение админам 			  ###################################################################
	#########################################################################################################################################################*/
	
	if ( 1 <= PLAYER [ playerid ] [ ADMIN ] <= 7 )
	{
		if ( PLAYER [ playerid ] [ MONEY ] > 100 ) 	PLAYER [ playerid ] [ MONEY ] = 100;
		if ( PLAYER [ playerid ] [ BANK ] > 100 ) 	PLAYER [ playerid ] [ BANK ] = 100;
	}
	
	/*#######################################################################################################################################################
	################################################# 	Жизни и бронь		 			  ###################################################################
	#########################################################################################################################################################*/
	
	new Float:health, Float:armour;
	GetPlayerArmour ( playerid, armour ), GetPlayerHealth ( playerid, health ) ;
	
	if ( health > PLAYER [ playerid ] [ HEALTH ] )
		SetPlayerHealth ( playerid, PLAYER [ playerid ] [ HEALTH ] ) ;
	else
		PLAYER [ playerid ] [ HEALTH ] = health;
	
	if ( armour > PLAYER [ playerid ] [ ARMOUR ] )
		SetPlayerArmour ( playerid, PLAYER [ playerid ] [ ARMOUR ] ) ;
	else
		PLAYER [ playerid ] [ ARMOUR ] = armour;
	
	/*#######################################################################################################################################################
	################################################# 	Запрещенное оружие	 			  ###################################################################
	#########################################################################################################################################################*/
	
	switch ( GetPlayerWeapon ( playerid ) )
	{
		case 35..40,44..45:
		{
			ResetPlayerWeapons ( playerid ) ;
			return AntiCheatMessage ( playerid, "WeaponHack (Запрещенное оружие)" ) ;
		}
	}
	
	/*#######################################################################################################################################################
	################################################# 			Джетпак		 			  ###################################################################
	#########################################################################################################################################################*/
	
	if ( GetPlayerSpecialAction ( playerid ) == SPECIAL_ACTION_USEJETPACK ) return AntiCheatMessage ( playerid, "JetPack" ) ;
	
	return 1;
}


forward OneSecond ( playerid ) ;
public OneSecond ( playerid ) 
{
	new string [ 64 ];
	
	if ( !IsLogged ( playerid ) ) return 1;
	
	if ( GetPVarInt ( playerid, "ActivateAnim" ) > 0 ) SetPVarInt ( playerid, "ActivateAnim", GetPVarInt ( playerid, "ActivateAnim" ) - 1 ) ;
			
	//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////		
	///////////////////////////////////////////////////////// БОЛЬНИЦА ///////////////////////////////////////////////////////////////////////		
	//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	
	new idh = 	PLAYER [ playerid ] [ HOSPITAL ], 
		ht 	= 	PLAYER [ playerid ] [ HOSPITAL_TIME ], 
		hm 	= 	GetPVarInt ( playerid, "HospitalMoney" ),
		hmt = 	GetPVarInt ( playerid, "HospitalMoneyTime" ),
		jid = 	PLAYER [ playerid ] [ JAIL ], 
		jt 	= 	PLAYER [ playerid ] [ JAIL_TIME ], 
		jw 	= 	GetPVarInt ( playerid, "JailWarn" ) ;
		
	if ( idh != -1 && ht != -1  )
	{
		if ( !IsPlayerInRangeOfPoint ( playerid, 1.0, Hospital [ idh ] [ Position ] [ 0 ], Hospital [ idh ] [ Position ] [ 1 ], Hospital [ idh ] [ Position ] [ 2 ] ) )
		{
			SendClientMessage ( playerid, COLOR_GRAY, "Ты не можешь встать с койки до окончания курса лечения!" );			
			MySetPlayerPos ( playerid, Hospital [ idh ] [ Position ] [ 0 ], Hospital [ idh ] [ Position ] [ 1 ], Hospital [ idh ] [ Position ] [ 2 ], Hospital [ idh ] [ Position ] [ 3 ], Hospital [ idh ] [ Interior ], Hospital [ idh ] [ World ] ) ;
		}

		if ( ht > 0 )
		{
			if ( PLAYER [ playerid ] [ HEALTH ] < 100 )
			SetPlayerHealthAC ( playerid, PLAYER [ playerid ] [ HEALTH ] + 1.0 );
			
			PLAYER [ playerid ] [ HOSPITAL_TIME ]--;
			SetPVarInt ( playerid, "HospitalMoneyTime", hmt + 1 ) ;
			
			ApplyAnimation ( playerid, "CRACK", "crckdeth2" , 4.1, 1, 1, 1, 1, 0 ) ;
			
			if ( hmt >= 5 )
			{
				if ( PLAYER [ playerid ] [ MONEY ] > 5 )
					FRACTION [ INDEX_MEDIC ] [ Money ] += hmt, GivePlayerMoneyAC ( playerid, -hmt ), SetPVarInt ( playerid, "HospitalMoney", hm + hmt ) ;
				else if ( PLAYER [ playerid ] [ BANK ] > 5 )
					FRACTION [ INDEX_MEDIC ] [ Money ] += hmt, GivePlayerBankMoney ( playerid, -hmt ), SetPVarInt ( playerid, "HospitalMoney", hm + hmt ) ;
				else
					GameTextForPlayer ( playerid, "~y~ћEЌEм…E ЂECЊ‡AЏмO", 1000, 4 ) ;
				
				SetPVarInt ( playerid, "HospitalMoneyTime", 0 ) ;
			}
			
			echo ( string, "OCЏA‡OC’ ‡E„AЏ’: %02d:%02d", ht / 60, ht % 60 ) ;
			PlayerTextDrawSetString ( playerid, HospitalTimeDraw [ playerid ], string ) ;
		}
		
		if ( ht == 0 )
		{
			echo ( string, "Доктор выписал Вас из больницы! Лечение стоило $%d", hm ) ;
			SendClientMessage ( playerid, COLOR_SAFE, string );
			
			FreeHospitalBed ( playerid ) ;
			ClearAnimations ( playerid ) ;
			
			PLAYER [ playerid ] [ HOSPITAL ] = -1;
			PLAYER [ playerid ] [ HOSPITAL_TIME ] = -1;
			SetPVarInt ( playerid, "HospitalMoney", 0 ) ;
			SetPVarInt ( playerid, "HospitalMoneyTime", 0 ) ;
		}
	}
	
	//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////		
	///////////////////////////////////////////////////////// ТЮРЬМА   ///////////////////////////////////////////////////////////////////////		
	//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	
	if ( jid != -1 && jt != -1  )
	{
		switch ( jid )
		{
			case 0:
			{
				if ( !IsPlayerInRangeOfPoint( playerid, 15.0, 1000.0, 1000.0, 1000.0 ) )
				{
					SetPVarInt ( playerid, "JailWarn", jw + 1 ) ;
					MySetPlayerPos ( playerid, 1000.0 + random ( 10 ), 1000.0 + random ( 10 ), 1000.0, 0.0, 0, 0 ) ;
					
					if ( jw > 3 ) return AntiCheatMessage ( playerid, "Побег из АдминТюрьмы" ) ;
				}
			}
		}
		
		if ( jt > 0 )
		{
			PLAYER [ playerid ] [ JAIL_TIME ]--;
			
			if ( jt > 3599 )
				echo ( string, "OCЏA‡OC’ C…ѓEЏ’: %02d:%02d:%02d", jt / 3600, ( jt / 60 ) % 60, jt % 60  ) ;
			else
				echo ( string, "OCЏA‡OC’ C…ѓEЏ’: %02d:%02d", jt / 60, jt % 60  ) ;
			
			PlayerTextDrawSetString ( playerid, JailTimeDraw [ playerid ], string ) ;
		}
		
		if ( jt == 0 )
		{
			SetPVarInt ( playerid, "JailWarn", 0 ) ;
			PLAYER [ playerid ] [ JAIL ] = -1;
			PLAYER [ playerid ] [ JAIL_TIME ] = -1;
			
			PlayerTextDrawHide ( playerid, JailTimeDraw [ playerid ] ) ;
			SendClientMessage ( playerid, COLOR_ADM, "Ты отсидел свой срок! Впредь не нарушай!" );
			MySetPlayerPos ( playerid, 1805.4094, -1519.0677, 1700.4287, 358.4954, 1, 1 ) ;
		}
	}
	
	
	//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////		
	//////////////////////////////////////////////////// АНТИЗАМОРОЗКА ///////////////////////////////////////////////////////////////////////		
	//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	
	if ( GetPVarInt ( playerid, "AntiToggle" ) == 1  )
	{
		new Float:TPOS [ 3 ] ;
		
		TPOS [ 0 ] = GetPVarFloat ( playerid, "ToggleposX" );
		TPOS [ 1 ] = GetPVarFloat ( playerid, "ToggleposY" );
		TPOS [ 2 ] = GetPVarFloat ( playerid, "ToggleposZ" );
		
		if ( !IsPlayerInRangeOfPoint ( playerid, 5.0, TPOS [ 0 ], TPOS [ 1 ], TPOS [ 2 ] ) )
		{
			if ( GetPVarInt ( playerid, "AntiToggleWarn" ) > 4 ) return AntiCheatMessage ( playerid, "Антизаморозка" ) ;
			
			SetPVarInt 					( playerid, "AntiToggleWarn", GetPVarInt ( playerid, "AntiToggleWarn" ) + 1 ) ;
			AdminWarns 					( playerid, GetPVarInt ( playerid, "AntiToggleWarn" ), "использует антизаморозку" ) ;
			
			if ( GetPlayerState ( playerid ) == PLAYER_STATE_DRIVER )
			{
				SetVehiclePos 			( GetPlayerVehicleID ( playerid ), TPOS [ 0 ], TPOS [ 1 ], TPOS [ 2 ] ) ;
			}
			else
			{
				SetPlayerInterior 		( playerid, GetPVarInt( playerid, "ToggleInterior" ) ) ;
				SetPlayerVirtualWorld 	( playerid, GetPVarInt ( playerid, "ToggleWorld" ) ) ;
				SetPlayerPos 			( playerid, TPOS [ 0 ], TPOS [ 1 ], TPOS [ 2 ] ) ;
			}
			TogglePlayerControllable 	( playerid, 0 ) ;
		}
	}
	
	//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////		
	//////////////////////////////////////////////////// АНТИ FLY HACK ///////////////////////////////////////////////////////////////////////		
	//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	
	new AnimLib [ 30 ], AnimName [ 30 ] ;
	GetAnimationName ( GetPlayerAnimationIndex ( playerid ), AnimLib, sizeof ( AnimLib ), AnimName, sizeof ( AnimName ) ) ;
	
	if 
	(
		!IsPlayerInAnyVehicle ( playerid ) && 
		GetPlayerSpeed ( playerid ) > 40 && 
		PLAYER [ playerid ] [ POSITION ] [ 2 ] > 30.0 && 
		GetPlayerState ( playerid ) != PLAYER_STATE_SPECTATING && 
		strcmp ( AnimLib, "SWIM", true ) == 0 && 
		CheckFlyAnim ( AnimName ) 
	)
	{
		if ( GetPVarInt ( playerid, "AntiFlyHackWarn" ) > 4 ) return AntiCheatMessage ( playerid, "FlyHack" ) ;
		
		SetPVarInt ( playerid, "AntiFlyHackWarn", GetPVarInt ( playerid, "AntiFlyHackWarn" ) + 1 ) ;
		
		echo ( string, "использует FlyHack. Высота: %.2f. Скорость: %d KM/H", PLAYER [ playerid ] [ POSITION ] [ 2 ], GetPlayerSpeed ( playerid ) ) ;
		AdminWarns ( playerid, GetPVarInt ( playerid, "AntiFlyHackWarn" ), string ) ;
	}
	
	//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////		
	////////////////////////////////////////////////// ОБНОВЛЯЕМ РАЙОН ///////////////////////////////////////////////////////////////////////		
	//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	
	//GetPlayer3DZone ( playerid, string, MAX_ZONE_NAME ), PlayerTextDrawSetString ( playerid, ZoneName [ playerid ], string ) ;
			
	//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////		
	///////////////////////////////////////////////////////// АНТИ АФК ///////////////////////////////////////////////////////////////////////		
	//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	
	new afkt = GetPVarInt ( playerid, "AfkTime" ) ;
	
	if ( GetPVarInt ( playerid, "LastTime" ) < gettime() )
	{
		SetPVarInt ( playerid, "AfkTime", afkt + 1 ) ;
		
		echo ( string, "(( Свернул: %02d:%02d сек. ))", afkt / 60, afkt % 60  );
		SetPlayerChatBubble ( playerid, string, -1, 15.0, 2000 ) ;
	}
	else
	{
		if ( PLAYER [ playerid ] [ POSITION ] [ 0 ] == GetPVarFloat ( playerid, "Afkpos_X" ) || PLAYER [ playerid ] [ POSITION ] [ 1 ] == GetPVarFloat ( playerid, "Afkpos_Y" ) )
		{
			SetPVarInt ( playerid, "AfkTime", afkt + 1 ) ;
			
			if ( afkt > 60 )
			{
				echo ( string, "(( Ушел в астрал %02d:%02d сек. ))", afkt / 60, afkt % 60  );
				SetPlayerChatBubble ( playerid, string, COLOR_GRAY, 15.0, 2000 ) ;
			}
		}
		else
		{
			if ( afkt > 120 )
			{
				SetPVarInt ( playerid, "AfkWarns", GetPVarInt ( playerid, "AfkWarns" ) + 1 ) ;
				echo ( string, "сбил АФК (%02d:%02d)", afkt / 60, afkt % 60 ) ;
				AdminWarns ( playerid, GetPVarInt ( playerid, "AfkWarns" ), string ) ;
			}
			SetPVarInt ( playerid, "AfkTime", 0 ) ;
		}
		
		SetPVarFloat ( playerid, "Afkpos_X", PLAYER [ playerid ] [ POSITION ] [ 0 ] ) ;
		SetPVarFloat ( playerid, "Afkpos_Z", PLAYER [ playerid ] [ POSITION ] [ 1 ] ) ;
	}
	
	if ( PLAYER [ playerid ] [ ADMIN ] < 8 && afkt > 300 ) return Send ( playerid, COLOR_ADM, "Ты был(а) кикнут(а) за AFK" ), KickEx ( playerid ) ;
	
	if ( ( PLAYER [ playerid ] [ GAME_SESSION ] + ( gettime () - GetPVarInt ( playerid, "Session" ) ) ) >= 3600 )
	{
		SetPVarInt ( playerid, "Session", gettime ( ) ) ;
		PLAYER [ playerid ] [ GAME_SESSION ] = 0;
		PLAYER [ playerid ] [ HOUR ]++;
		
		if ( PLAYER [ playerid ] [ HOUR ] >= 36 )
		{
			PLAYER [ playerid ] [ AGE ]++;
			SetPlayerScore ( playerid, PLAYER [ playerid ] [ AGE ] ) ;
			PLAYER [ playerid ] [ HOUR ] = 0;
			
			echo ( string, "Поздравляю с днем рождения, тебе стукнуло %d!", PLAYER [ playerid ] [ AGE ] ) ;
			SendClientMessage ( playerid, COLOR_GREEN, string ) ;
		}
	}
	return 1; 
}