GangstaSunny

Watch server and player statistics (26.07.2016)

Jul 26th, 2016
108
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //created by GangstaSunny - Have a great day!
  2. //Copyright by www.german-samplife.de (2016)
  3.  
  4. #include <a_samp>
  5. #define RCON_ADMIN_ONLY // comment this out if erveryone should can check the server and player statistics
  6. #define REFRESH_SECONDS 1 // set the time (in seconds) when the statistics should be refreshed
  7.  
  8. forward sSShowServerStatistics(playerid);
  9. forward sSShowPlayerStatistics(playerid, clickedplayerid);
  10. new sSShowStats[MAX_PLAYERS];
  11.  
  12. public OnPlayerCommandText(playerid, cmdtext[])
  13. {
  14.     if (strcmp("/serverstats", cmdtext, true, 10) == 0)
  15.     {
  16.         #if defined RCON_ADMIN_ONLY
  17.         if(!IsPlayerAdmin(playerid))return SendClientMessage(playerid,0xFFFFFFFF,"{FFE600}[Info]: {FFFFFF}This command is for RCON Administrators only.");
  18.         #endif
  19.         sSShowStats[playerid] = SetTimerEx("sSShowServerStatistics", REFRESH_SECONDS*1000, 1, "i", playerid);
  20.         new sSheadline[64], sSregex[128];
  21.         GetServerVarAsString("hostname", sSheadline, sizeof(sSheadline));
  22.         format(sSregex,128,"{FFE600}[Info]: Watching server statistics of - %s (refreshing every %d second(s))",sSheadline,REFRESH_SECONDS);
  23.         SendClientMessage(playerid,0xFFFFFFFF,sSregex);
  24.         return 1;
  25.     }
  26.     return 0;
  27. }
  28.  
  29. public OnPlayerClickPlayer(playerid, clickedplayerid, source)
  30. {
  31.     #if defined RCON_ADMIN_ONLY
  32.     if(!IsPlayerAdmin(playerid))return 0;
  33.     #endif
  34.     new sSname[MAX_PLAYER_NAME], sSregex[128];
  35.     GetPlayerName(playerid, sSname, MAX_PLAYER_NAME);
  36.     format(sSregex,128,"{FFE600}[Info]: Watching player statistics of - {FFC800}%s (id: %i) - (refreshing every %d second(s))",sSname,clickedplayerid,REFRESH_SECONDS);
  37.     SendClientMessage(playerid,0xFFFFFFFF,sSregex);
  38.     sSShowStats[playerid] = SetTimerEx("sSShowPlayerStatistics", REFRESH_SECONDS*1000, 1, "ii", playerid, clickedplayerid);
  39.     return 1;
  40. }
  41.  
  42. public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[]){if(dialogid == 9988){KillTimer(sSShowStats[playerid]);}}
  43.  
  44. public sSShowServerStatistics(playerid)
  45. {
  46.     ShowPlayerDialog(playerid, -1, 1, "", "", "", "");//Safley closing the dialog first
  47.     new sSheadline[64], sSregex[1024];
  48.     GetServerVarAsString("hostname", sSheadline, sizeof(sSheadline));
  49.     GetNetworkStats(sSregex, sizeof(sSregex));
  50.     strins(sSregex, "Statistic\tValue\n", 0);
  51.     strins(sSheadline, "{FFC800}", 0);
  52.     for(new stat = 0; stat < 17; stat++)
  53.     {
  54.         new delpos = strfind(sSregex, ":", true);
  55.         strdel(sSregex, delpos, delpos+1);
  56.         strins(sSregex, "\t", delpos);
  57.     }
  58.     ShowPlayerDialog(playerid,9988,DIALOG_STYLE_TABLIST_HEADERS,sSheadline,sSregex,"Close","");
  59.     return 1;
  60. }
  61.  
  62. public sSShowPlayerStatistics(playerid, clickedplayerid)
  63. {
  64.     ShowPlayerDialog(playerid, -1, 1, "", "", "", "");//Safley closing the dialog first
  65.     new sSheadline[64], sSregex[1024];
  66.     GetServerVarAsString("hostname", sSheadline, sizeof(sSheadline));
  67.     GetPlayerNetworkStats(clickedplayerid, sSregex, sizeof(sSregex));
  68.     strins(sSregex, "Statistic\tValue\n", 0);
  69.     strins(sSheadline, "{FFE600}", 0);
  70.     for(new stat = 0; stat < 18; stat++)
  71.     {
  72.         new delpos = strfind(sSregex, ":", true);
  73.         strdel(sSregex, delpos, delpos+1);
  74.         strins(sSregex, "\t", delpos);
  75.     }
  76.     ShowPlayerDialog(playerid,9988,DIALOG_STYLE_TABLIST_HEADERS,sSheadline,sSregex,"Close","");
  77.     return 1;
  78. }
RAW Paste Data