#include <a_samp>

stock AntiGunCheat(playerid)
{
	if(IsPlayerConnected(playerid))
	{
		if(IsPlayerSpawned[playerid])
		{
		    if(IsACheatState(playerid))
		    {
				if(IntroState[playerid] != -1) return true;
		    	new gunid, ammo;
			    for(new s = 0;s < 13;s++)
			    {
	          		if(!AntiCheatOFF[playerid][GUN_HACK][s])
					{
				        GetPlayerWeaponData(playerid,s,gunid,ammo);
						if(gunid != 0 && gunid != 46)
						{
							if(ammo > GunAmmo[playerid][s])
       						{
        						CheatWarns[playerid][cwGun] ++;
								J_ResetPlayerWeapons(playerid);
								if(CheatWarns[playerid][cwGun] >= 3)
							 	{
				        			new string[150];
									format(string,sizeof(string),"Игрок %s[%d] кикнут за читерство оружия (%s | %d) | Ping: %d",PN(playerid),playerid,GunName(gunid),ammo-GunAmmo[playerid][s],GetPlayerPing(playerid));
									SendAdminsMessage(COLOR_LIGHTRED,string,1);
									J_Kick(playerid,"Читы");
								}
								break;
							}
							else if(GunAmmo[playerid][s] > ammo)
							{
							    if(IsAFireGun(gunid) && gunid == CurrentWeapon[playerid] && !ammo)
							    {
							        new nogun = -1;
							        for(new g; g < 3; g ++)
									{
									    if(!PlayerInfo[playerid][pWeapon][g] && nogun == -1)
									    {
									        nogun = g;
									    }
										else if(PlayerInfo[playerid][pWeapon][g] == gunid)
										{
										    nogun = -1;
										}
									}
									if(nogun != -1)
									{
									    PlayerInfo[playerid][pWeapon][nogun] = gunid;
									    PlayerInfo[playerid][pAmmo][nogun] = 0;
									}
									CurrentWeapon[playerid] = 0;
									RemovePlayerWeaponEx(playerid, gunid);
							    }
								GunAmmo[playerid][s] = ammo;
								if(CheatWarns[playerid][cwGun] > 0)
								{
								    CheatWarns[playerid][cwGun] --;
								}
							}
						}
					}
	    			else
					{
						AntiCheatOFF[playerid][GUN_HACK][s] --;
						if(CheatWarns[playerid][cwGun] > 0)
						{
						    CheatWarns[playerid][cwGun] --;
						}
					}
				}
			}
		}
	}
	return true;
}

stock GetMaxHealth(playerid)
{
    if(PlayerInfo[playerid][pHeal] > 0)
    {
        if(PlayerLie[playerid]) return 10;
        else return 5;
    }
    return 1;
}

stock AntiHealthCheat(playerid)
{
    if(IsPlayerConnected(playerid))
	{
	    if(IsPlayerSpawned[playerid])
		{
		    if(IsACheatState(playerid))
		    {
		        if(IntroState[playerid] != -1) return true;
			    if(!AntiCheatOFF[playerid][HEALTH_HACK])
				{
				    if(IsNoAFK(playerid))
				    {
						new Float:Health;
						GetPlayerHealth(playerid,Health);
						if( (Health - PlayerInfo[playerid][pHealth]) > GetMaxHealth(playerid))
						{
						    new Float:health = Health - PlayerInfo[playerid][pHealth];
							SetPlayerHealth(playerid,PlayerInfo[playerid][pHealth]);
							CheatWarns[playerid][cwHealth] ++;
						    if(CheatWarns[playerid][cwHealth] >= 3)
						    {
								new string[100];
								CheatMessage(playerid);
								format(string,sizeof(string),"Игрок %s[%d] кикнут за читерство ХП (%.0f ХП) | Ping: %d",PN(playerid),playerid,health,GetPlayerPing(playerid));
								SendAdminsMessage(COLOR_LIGHTRED,string,1);
								J_Kick(playerid,"Читы");
							}
						}
						else
						{
						    CheatWarns[playerid][cwHealth] = 0;
							PlayerInfo[playerid][pHealth] = Health;
							DamageHealth[playerid] = Health;
						}
					}
				}
				else
				{
				    CheatWarns[playerid][cwHealth] = 0;
				    AntiCheatOFF[playerid][HEALTH_HACK] --;
				}
			}
		}
	}
	return true;
}

stock AntiArmourCheat(playerid)
{
    if(IsPlayerConnected(playerid))
	{
	    if(IsPlayerSpawned[playerid])
		{
		    if(IsACheatState(playerid))
		    {
		        if(IntroState[playerid] != -1) return true;
			    if(!AntiCheatOFF[playerid][ARMOUR_HACK])
				{
				    if(IsNoAFK(playerid))
				    {
						new Float:Armour;
						GetPlayerArmour(playerid,Armour);
						if( (Armour - PlayerInfo[playerid][pArmour]) >= 1)
						{
							CheatWarns[playerid][cwArmour] ++;
							SetPlayerArmour(playerid,PlayerInfo[playerid][pArmour]);
						    if(CheatWarns[playerid][cwArmour] >= 3)
						    {
								new string[100];
								CheatMessage(playerid);
								format(string,sizeof(string),"Игрок %s[%d] кикнут за читерство брони (%.0f) | Ping: %d",PN(playerid),playerid,Armour - PlayerInfo[playerid][pArmour],GetPlayerPing(playerid));
								SendAdminsMessage(COLOR_LIGHTRED,string,1);
								J_Kick(playerid,"Читы");
							}
						}
						else
						{
						    CheatWarns[playerid][cwArmour] = 0;
							PlayerInfo[playerid][pArmour] = Armour;
							DamageArmour[playerid] = Armour;
						}
					}
				}
				else
				{
				    CheatWarns[playerid][cwArmour] = 0;
				    AntiCheatOFF[playerid][ARMOUR_HACK] --;
				}
			}
		}
	}
	return true;
}

stock AntiCarHealthCheat(playerid)
{
    if(IsPlayerConnected(playerid))
	{
	    if(IsPlayerSpawned[playerid])
		{
		    if(IsACheatState(playerid))
		    {
		        if(IntroState[playerid] != -1) return true;
				if(IsPlayerInAnyVehicle(playerid))
				{
				    if(GetPlayerState(playerid) == PLAYER_STATE_DRIVER)
				    {
				        new carid = GetPlayerVehicleID(playerid), Float:VHealth;
				        if(!AntiCarHealthCheatOFF[carid])
						{
						    if(IsNoAFK(playerid))
						    {
								GetVehicleHealth(carid,VHealth);
								if( (VHealth - VehicleHealth[carid]) > 10.0)
								{
									if(!IsAtTunning(playerid))
									{
									    SetVehicleHealth(carid,VehicleHealth[carid]);
									    CheatWarns[playerid][cwCarHP] ++;
									    if(CheatWarns[playerid][cwCarHP] >= 3)
							    		{
											new string[150];
											CheatMessage(playerid);
											format(string,sizeof(string),"Игрок %s[%d] кикнут за читерство ХП транспорта (%.0f) | Ping: %d",PN(playerid),playerid,(VHealth - VehicleHealth[carid])/10,GetPlayerPing(playerid));
											SendAdminsMessage(COLOR_LIGHTRED,string,1);
											J_Kick(playerid,"Читы");
										}
									}
									else
									{
									    CheatWarns[playerid][cwCarHP] = 0;
									   	VehicleHealth[carid] = VHealth;
									}
								}
								else
								{
								    if(VHealth < 250.0)
								    {
								        new c_panels, c_doors, c_lights, c_tires;
										GetVehicleDamageStatus(carid, c_panels, c_doors, c_lights, c_tires);
										if(c_panels == 0 && c_doors == 0 && c_tires == 15)
										{
										    new string[150];
											CheatMessage(playerid);
											format(string,sizeof(string),"Игрок %s[%d] кикнут за Car Explode (%.0f) | Ping: %d",PN(playerid),playerid,(VHealth - VehicleHealth[carid])/10,GetPlayerPing(playerid));
											SendAdminsMessage(COLOR_LIGHTRED,string,1);
											J_Kick(playerid,"Читы");
										}
								    }
								    CheatWarns[playerid][cwCarHP] = 0;
								    VehicleHealth[carid] = VHealth;
								}
							}
						}
						else
						{
						    CheatWarns[playerid][cwCarHP] = 0;
						    AntiCarHealthCheatOFF[carid] --;
						}
					}
				}
			}
		}
	}
	return true;
}

stock AntiControllableHack(playerid)
{
    if(!Controllable[playerid])
	{
	    if(IntroState[playerid] != -1) return true;
	    if(PlayerInfo[playerid][pHeal] > 0) return true;
		if(GetPlayerState(playerid) == PLAYER_STATE_ONFOOT)
		{
		    if(!AntiCheatOFF[playerid][CONTROLLABLE_HACK])
		    {
       			if(!IsPlayerInRangeOfPoint(playerid,2.0,PlayerInfo[playerid][pCPos_X],PlayerInfo[playerid][pCPos_Y],PlayerInfo[playerid][pCPos_Z]))
			    {
			        new string[100];
				    format(string,sizeof(string),"Игрок %s[%d] был кикнут за использование собейта (#4)",PN(playerid),playerid);
					SendAdminsMessage(COLOR_LIGHTRED,string,1);
					WriteLog("CheatLog.log",string);
					CheatMessage(playerid);
					J_Kick(playerid,"Читы");
			    }
		    }
      		else
			{
	 			GetPlayerPos(playerid,PlayerInfo[playerid][pCPos_X],PlayerInfo[playerid][pCPos_Y],PlayerInfo[playerid][pCPos_Z]);
	 			AntiCheatOFF[playerid][CONTROLLABLE_HACK] --;
	 		}
 		}
	}
	return true;
}

stock AntiSpeedHack(playerid)
{
    if(IntroState[playerid] != -1) return true;
	new string[100];
	new carid = GetPlayerVehicleID(playerid);
 	new Float:Health;
 	GetVehicleHealth(carid,Health);
 	new speed = GetPlayerVehicleSpeed(playerid);
	if(!AntiCheatOFF[playerid][SPEED_HACK])
	{
		new Float:X,Float:Y,Float:Z;
		GetVehicleVelocity(carid, X, Y, Z);
		if(speed > 300)
		{
		    if(Z > -0.5)
		    {
			    if(!IsAPlane(carid))
			    {
				    format(string,sizeof(string),"Игрок %s[%d] был кикнут за SpeedHack (%d КМ/ч) | Ping: %d",PN(playerid),playerid,speed,GetPlayerPing(playerid));
					SendAdminsMessage(COLOR_LIGHTRED,string,1);
					SendClientMessage(playerid, COLOR_LIGHTRED, "Вы были кикнуты! Настоятельно просим не использовать читы!");
					ShowPlayerDialogEx(playerid, INVALID_DIALOG_ID, 0, "Не читерите", "Вы были кикнуты! Настоятельно просим не использовать читы!", "Ок", "");
					J_Kick(playerid, "SpeedHack");
					return true;
				}
			}
		}
	}
	else
	{
	    AntiCheatOFF[playerid][SPEED_HACK] --;
	}
	PlayerAntiCheat[playerid][OLD_CAR_HEALTH] = Health;
	PlayerAntiCheat[playerid][OLD_SPEED] = speed;
    return true;
}

stock AntiMoneyCheat(playerid)
{
    if(IsPlayerConnected(playerid))
	{
	    if(IsPlayerSpawned[playerid])
		{
		    if(IntroState[playerid] != -1) return true;
		    if(!AntiCheatOFF[playerid][MONEY_HACK])
			{
				if(PlayerInfo[playerid][pMoney] > GetPlayerMoney(playerid))
				{
					PlayerInfo[playerid][pMoney] = GetPlayerMoney(playerid);
				}
				else if(PlayerInfo[playerid][pMoney] < GetPlayerMoney(playerid))
				{
					SetPlayerMoney(playerid,GetMoney(playerid));
				}
			}
			else
			{
				AntiCheatOFF[playerid][MONEY_HACK] --;
			}
		}
	}
	return true;
}

stock AntiAirBreak(playerid)
{
    if(IsPlayerConnected(playerid))
	{
	    if(IsPlayerSpawned[playerid] && TutState[playerid] == -1)
		{
		    if(IsACheatState(playerid))
		    {
		        if(IntroState[playerid] != -1) return true;
				new Float:X, Float:Y, Float:Z, string[150], State, var;
				GetPlayerPos(playerid,X,Y,Z);
				if(ShowDistance[playerid])
				{
				    new Float:dis = (floatround(floatsqroot(J_GetSquareDistance(X,Y,Z,PlayerInfo[playerid][pPos_X],PlayerInfo[playerid][pPos_Y],PlayerInfo[playerid][pPos_Z]))*3600)/(GetTickCount()-PlayerAntiCheat[playerid][LAST_CHECK]));
				    format(string,sizeof(string),"Distance: %.0f",dis);
				    SendClientMessage(playerid, COLOR_WHITE, string);
				}
				State = GetPlayerState(playerid);
				if(!AntiCheatOFF[playerid][TELEPORT_HACK])
				{
	   				if(PlayerInfo[playerid][pAdmin] < ADM_GRAND_ADMIN)
    				{
    					if( (Z < 900.0) == (PlayerInfo[playerid][pPos_Z] < 900.0) )
    					{
    						if(State != PLAYER_STATE_SPECTATING && State != PLAYER_STATE_PASSENGER && GetPlayerSurfingVehicleID(playerid) == INVALID_VEHICLE_ID)
							{
    							if(!IsPlayerInRangeOfPoint(playerid,500.0,PlayerInfo[playerid][pPos_X],PlayerInfo[playerid][pPos_Y],PlayerInfo[playerid][pPos_Z]))
								{
								    if(!IsPlayerInRangeOfPoint(playerid, 5.0, PlayerInfo[playerid][pOld_X], PlayerInfo[playerid][pOld_Y], PlayerInfo[playerid][pOld_Z]))
									{
										PlayerInfo[playerid][pOld_X] = -99999.9;
										PlayerInfo[playerid][pOld_Y] = -99999.9;
										PlayerInfo[playerid][pOld_Z] = -99999.9;
										if(!IsPlayerInRangeOfPoint(playerid,1.5,SetPos[playerid][0],SetPos[playerid][1],SetPos[playerid][2]))
										{
											format(string,sizeof(string),"Игрок %s кикнут за подозрение в Teleport | Ping: %d",PN(playerid),GetPlayerPing(playerid));
											SendAdminsMessage(COLOR_LIGHTRED,string,1);
											SendClientMessage(playerid, COLOR_LIGHTRED, "Вы были кикнуты! Настоятельно просим не использовать читы!");
											ShowPlayerDialogEx(playerid, INVALID_DIALOG_ID, 0, "Не читерите", "Вы были кикнуты! Настоятельно просим не использовать читы!", "Ок", "");
		                                    J_Kick(playerid, "Teleport");
										}
									}
								}
							}
					    }
					    if(State == PLAYER_STATE_ONFOOT || ( State == PLAYER_STATE_DRIVER && GetPlayerVehicleSpeed(playerid) < 5 ) )
						{
							var = (floatround(floatsqroot(J_GetSquareDistance(X,Y,Z,PlayerInfo[playerid][pPos_X],PlayerInfo[playerid][pPos_Y],PlayerInfo[playerid][pPos_Z]))*3600)/(GetTickCount()-PlayerAntiCheat[playerid][LAST_CHECK]));
							if(var >= 500 && var <= 1500)
							{
							    if(!IsPlayerInRangeOfPoint(playerid, 5.0, 132.1207,-67.3141,1.5781))
					       		{
								    format(string,sizeof(string),"Игрок %s кикнут за подозрение в AirBreak | Ping: %d",PN(playerid),GetPlayerPing(playerid));
									SendAdminsMessage(COLOR_LIGHTRED,string,1);
									SendClientMessage(playerid, COLOR_LIGHTRED, "Вы были кикнуты! Настоятельно просим не использовать читы!");
									ShowPlayerDialogEx(playerid, INVALID_DIALOG_ID, 0, "Не читерите", "Вы были кикнуты! Настоятельно просим не использовать читы!", "Ок", "");
           							J_Kick(playerid, "AirBreak");
								}
							}
						}
					}
					else
					{
					    AntiCheatOFF[playerid][TELEPORT_HACK] --;
					}
				}
				ReturnCords(playerid);
				PlayerAntiCheat[playerid][LAST_CHECK] = GetTickCount();
			}
		}
	}
	return true;
}

stock AntiBeskGuns(playerid)
{
	if(Controllable[playerid])
	{
		switch(GetPlayerAnimationIndex(playerid))
		{
		    case 220,360,363,1160..1163,1167,1331,1365,1449,1643:
		    {
			    if(IsAFireGun(GetPlayerWeapon(playerid)))
			    {
				    if(FireKey[playerid])
				    {
				        if(GetPlayerWeapon(playerid) == FireGun[playerid])
				        {
				            if(GetPlayerAmmo(playerid) == FireAmmo[playerid])
				            {
				                if(!IsAimingToAnyPlayer(playerid,1.5))
				                {
					                new string[150];
									format(string,sizeof(string),"Похоже у игрока %s[%d] бесконечные патроны,проверьте его (/spec %d)",PN(playerid),playerid,playerid);
									SendAdminsMessage(COLOR_LIGHTRED,string,1);
								}
				  	        }
				        }
				        FireGun[playerid] = GetPlayerWeapon(playerid);
				        FireAmmo[playerid] = GetPlayerAmmo(playerid);
				    }
			    }
			}
		}
	}
	return true;
}

stock AntiVehRotCheat(playerid)
{
	if(IsNoAFK(playerid))
	{
	    if(IntroState[playerid] != -1) return true;
		if(IsPlayerInAnyVehicle(playerid) && GetPlayerState(playerid) == 2)
		{
		    new string[150];
		    new carid = GetPlayerVehicleID(playerid);
			GetVehicleZAngle(carid,vRut[playerid][1]);
			new Float:Rot = vRut[playerid][0] - vRut[playerid][1];
			if(!AntiCheatOFF[playerid][VEH_ROOT_HACK])
			{
				if( (Rot >= 177 && Rot <= 183) || (Rot <= -177 && Rot >= -183) )
				{
					if(!IsABike(carid) && !IsAVelik(carid) && GetVehicleModelEx(carid) != 520)
				    {
				        if(!IsAtTunning(playerid))
				        {
						    format(string,sizeof(string),"Игрок %s[%d] подозревается в использовании собейта (#3)",PN(playerid),playerid);
							SendAdminsMessage(COLOR_LIGHTRED,string,1);
							SetVehicleZAngle(carid,vRut[playerid][0]);
							SendClientMessage(playerid, COLOR_LIGHTRED, "Вы были кикнуты! Настоятельно просим не использовать читы!");
							ShowPlayerDialogEx(playerid, INVALID_DIALOG_ID, 0, "Не читерите", "{FFFFFF}Вы были кикнуты! Настоятельно просим не использовать читы!", "Ок", "");
							J_Kick(playerid, "S0beit #3");
							return true;
						}
					}
			    }
			}
			GetVehicleZAngle(carid,vRut[playerid][0]);
		}
	}
	return true;
}
