Advertisement
Guest User

MaxPing

a guest
Apr 1st, 2013
438
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 2.81 KB | None | 0 0
  1. /*
  2.  
  3. This is a slightly more advanced version of hustrine's anti-ping. I'm hoping it will be an improvement.
  4.  
  5. */
  6.  
  7. #include <a_samp>
  8. #include <sscanf>
  9. #include <zcmd>
  10.  
  11.  
  12. new MAX_PING = 1000; // Change this to your needs.
  13. new Warning[MAX_PLAYERS];
  14.  
  15.  
  16. forward PingCheck();
  17.  
  18. CMD:setping(playerid, params[])
  19. {
  20.     if(IsPlayerAdmin(playerid))
  21.     {
  22.         new NewPing, OldPing, String[128];
  23.         if(sscanf(params, "d", NewPing))
  24.         {
  25.             OldPing = MAX_PING;
  26.             format(String, sizeof(String), "{FF0000}PingCheck:{FFFFFF} The current Max ping has been changed by an administrator. Old Ping: %d, New Ping: %d", OldPing, NewPing);
  27.             SendClientMessageToAll(-1, String);
  28.             MAX_PING = NewPing;
  29.         }
  30.     }
  31.     return 1;
  32. }
  33.  
  34. public OnFilterScriptInit()
  35. {
  36.     SetTimer("PingCheck", 10000, true); // Couldn't decide on this or OnPlayerUpdate
  37.     return 1;
  38. }
  39.  
  40. public OnPlayerConnect(playerid) { Warning[playerid]=0; return 1; }
  41.  
  42. OnPlayerPingUpdate(playerid)
  43. {
  44.     new String[128], PlayerName[MAX_PLAYER_NAME];
  45.     GetPlayerName(playerid, PlayerName, MAX_PLAYER_NAME);
  46.     if(GetPlayerPing(playerid) < MAX_PING - 100)
  47.     {
  48.         format(String, sizeof(String), "{FF0000}PingCheck:{FFFFFF} Your current ping is: %d. The maximum ping is %d.", GetPlayerPing(playerid), MAX_PING);
  49.         SendClientMessage(playerid, -1, String);
  50.     }
  51.     if(GetPlayerPing(playerid) < MAX_PING)
  52.     {
  53.         switch(Warning[playerid])
  54.         {
  55.             case 0:
  56.             {
  57.                 format(String, sizeof(String), "{FF0000}PingCheck:{FFFFFF} Your current ping is: %d.", GetPlayerPing(playerid));
  58.                 SendClientMessage(playerid, -1, String);
  59.                 SendClientMessage(playerid, -1, "{FF0000}PingCheck:{FFFFFF} Please try to reduce your ping by closing a few web based programs. (2/3)");
  60.                 Warning[playerid] ++;
  61.             }
  62.             case 1:
  63.             {
  64.                 format(String, sizeof(String), "{FF0000}PingCheck:{FFFFFF} Your current ping is: %d.", GetPlayerPing(playerid));
  65.                 SendClientMessage(playerid, -1, String);
  66.                 SendClientMessage(playerid, -1, "{FF0000}PingCheck:{FFFFFF} Please try to reduce your ping by closing a few web based programs. (2/3)");
  67.                 Warning[playerid] ++;
  68.             }
  69.             case 2:
  70.             {
  71.                 format(String, sizeof(String), "{FF0000}PingCheck:{FFFFFF} Your current ping is: %d.", GetPlayerPing(playerid));
  72.                 SendClientMessage(playerid, -1, String);
  73.                 SendClientMessage(playerid, -1, "{FF0000}PingCheck:{FFFFFF} You have recieved three warnings for excessive ping.");
  74.                 format(String, sizeof(String), "{FF0000}PingCheck{FFFFFF} %s has been kicked from the server. Reason: Excessive Ping. (%d)", PlayerName, MAX_PING);
  75.                 SendClientMessageToAll(-1, String);
  76.                 Warning[playerid] = 0;
  77.                 Kick(playerid);
  78.             }
  79.         }
  80.     }
  81.     return 1;
  82. }
  83.  
  84.  
  85. public PingCheck()
  86. {
  87.     for(new i=0;i < MAX_PLAYERS;i++)
  88.     {
  89.         if(IsPlayerConnected(i))
  90.         {
  91.             OnPlayerPingUpdate(i);
  92.         }
  93.     }
  94.     return 1;
  95. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement