//==============================================================================
#include 									<a_samp>
//==============================================================================
main( ){}

new PlayerName [ MAX_PLAYERS ] [ MAX_PLAYER_NAME ] ;
new Float:vehicle_health [ MAX_PLAYERS ];
new Float:speed_player [ MAX_PLAYERS ];
new player_vehicle [ MAX_PLAYERS ];
//==============================================================================
public OnPlayerConnect(playerid)
{
	speed_player [ playerid ] = 0;
	player_vehicle [ playerid ] = INVALID_VEHICLE_ID;
	GetPlayerName ( playerid, PlayerName [ playerid ] , MAX_PLAYER_NAME ) ;
	return 1;
}
public OnPlayerUpdate ( playerid )
{
	if( player_vehicle [playerid ] != INVALID_VEHICLE_ID )
	{
//      static speed_player [ MAX_PLAYERS ] ;
        new Float:veh_health_now;
        GetVehicleHealth(player_vehicle[ playerid ],veh_health_now);
        if ( GetPlayerSpeed ( playerid ) - speed_player [ playerid ] > 20 && veh_health_now - vehicle_health [ playerid ] == 0 && GetPVarInt(playerid,"Speed_hack_kick") != 1)
        {
        	printf("%f %f %d",GetPlayerSpeed ( playerid ) - speed_player [ playerid ],veh_health_now - vehicle_health [ playerid ],player_vehicle [playerid ]);
			SetTimerEx("Speed_hack_Check",500,false,"i",playerid);
			SetPVarInt(playerid , "Speed_hack_kick",1);
            return 1;
        }
		if(GetPVarInt(playerid , "Speed_hack_kick") != 1)
		{
			speed_player [ playerid ] = GetPlayerSpeed ( playerid ) ;
	  		GetVehicleHealth(player_vehicle[ playerid ],vehicle_health [ playerid ]);
  		}
    }
    return 1;
}
forward Speed_hack_Check( playerid );
public Speed_hack_Check( playerid )
{
    new Float:veh_health_now;
    GetVehicleHealth(player_vehicle[ playerid ],veh_health_now);
    if(veh_health_now - vehicle_health [ playerid ] == 0)
    {
    	AntiCheatMessage(playerid, "Speed Hack");
    }
    else DeletePVar(playerid ,"Speed_hack_kick");

}
public OnPlayerStateChange(playerid, newstate, oldstate)
{
	new vehicleid = GetPlayerVehicleID(playerid);
    if(newstate == PLAYER_STATE_DRIVER)
	{
		player_vehicle[ playerid ] = vehicleid;
	}
	else if(player_vehicle[ playerid ] != INVALID_VEHICLE_ID)
	{
		player_vehicle[ playerid ] = INVALID_VEHICLE_ID;
	}
	return 1;
}


stock GetPlayerSpeed ( playerid )
{
	new Float:x, Float:y, Float:z;
    GetVehicleVelocity ( player_vehicle[ playerid ], x, y, z ) ;
    return floatround ( floatsqroot ( x * x + y * y + z * z ) * 200  ) ;
}
stock AntiCheatMessage ( playerid, reason [ ] )
{
	new string [ 42 + 24 + 3 + 32 ] ;
	format ( string, sizeof string, "[Guard System]%s[%d] was blocked. Reason: %s", PlayerName [ playerid ], playerid, reason ) ;
	SendClientMessageToAll (0xFF644BFF, string ) ;
	KickEx ( playerid ) ;
	return 1;
}

stock KickEx ( playerid )
{
	new ms = GetPlayerPing ( playerid ) > 200 ? 200 : GetPlayerPing ( playerid ) + 50 ;
	return SetTimerEx ( "MyKick", ms , 0, "i", playerid ) ;
}
forward MyKick ( playerid );
public MyKick ( playerid ) { Kick ( playerid ) ;}

