Guest User

Untitled

a guest
May 9th, 2009
448
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 7.86 KB | None | 0 0
  1. /*    __     ______     ______     __   __        ______     ______   ______     ______   ______    **
  2. **   /\ \   /\  ___\   /\  __ \   /\ "-.\ \      /\  ___\   /\__  _\ /\  __ \   /\__  _\ /\  ___\   **
  3. **  _\_\ \  \ \___  \  \ \ \/\ \  \ \ \-.  \     \ \___  \  \/_/\ \/ \ \  __ \  \/_/\ \/ \ \___  \  **
  4. ** /\_____\  \/\_____\  \ \_____\  \ \_\\"\_\     \/\_____\    \ \_\  \ \_\ \_\    \ \_\  \/\_____\ **
  5. ** \/_____/   \/_____/   \/_____/   \/_/ \/_/      \/_____/     \/_/   \/_/\/_/     \/_/   \/_____/ **
  6. **                                                                                                  **
  7. **Coded By R@f (www.rafweb.ch / www.gtaonline.fr) - DJson include by DracoBlue (www.dracoblue.net)  **
  8. **                                                                                                  **/
  9.  
  10. /*=== INCLUDES ===*/
  11. #include <a_samp>
  12. #include <djson>
  13.  
  14. /*=== DEFINES ===*/
  15. #define COLOR_GREEN         0x33AA33AA
  16. #define COLOR_BLUE          0x33AAFFFF
  17. #define UPDATE_TIME 10 /*Time in seconds for the server stats update*/
  18.  
  19. /*=== VARIABLES ===*/
  20. new S_LUPDATE[10] = "09.05.09";
  21.  
  22. enum sInfo
  23. {
  24.     sRestarts,
  25.     sVisits,
  26.     sLeaves,
  27.     sTimeouts,
  28.     sKicks,
  29.     sDeaths,
  30.     sKills,
  31.     sCommands,
  32.     sMessages,
  33.     sPMessages,
  34.     sDays,
  35.     sHours,
  36.     sMinutes,
  37.     sSeconds,
  38. }
  39. new ServerInfo[sInfo];
  40.  
  41. /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
  42.  
  43. public OnFilterScriptInit()
  44. {
  45.     /*Load DJson*/
  46.     djson_GameModeInit();
  47.     /*Add djStyled - Comment this line for faster performence*/
  48.     djStyled(1);
  49.    
  50.     /*Little Message =P*/
  51.     printf("\n\n+++++++++++++++++++++++++++++++++++++++++++++++");
  52.     printf("++ R@f's JSon Stats + Last Update @ %s ++",S_LUPDATE);
  53.     printf("++ Script by Rafael 'R@f' Keramidas          ++");
  54.     printf("+++++++++++++++++++++++++++++++++++++++++++++++\n\n");
  55.    
  56.     /*Count server starts*/
  57.     djSetInt("data.json","starts",djInt("data.json","starts")+1);
  58.    
  59.     /*Load all the variables*/
  60.     ServerInfo[sVisits] = djInt("data.json","visits");
  61.     ServerInfo[sLeaves] = djInt("data.json","leaves");
  62.     ServerInfo[sTimeouts] = djInt("data.json","timeouts");
  63.     ServerInfo[sKicks] = djInt("data.json","kicks");
  64.     ServerInfo[sDeaths] = djInt("data.json","deaths");
  65.     ServerInfo[sKills] = djInt("data.json","kills");
  66.     ServerInfo[sCommands] = djInt("data.json","commands");
  67.     ServerInfo[sMessages] = djInt("data.json","messages");
  68.     ServerInfo[sPMessages] = djInt("data.json","pmessages");
  69.     ServerInfo[sSeconds] = djInt("data.json","seconds");
  70.     ServerInfo[sMinutes] = djInt("data.json","minutes");
  71.     ServerInfo[sHours] = djInt("data.json","hours");
  72.     ServerInfo[sDays] = djInt("data.json","days");
  73.     ServerInfo[sRestarts] = djInt("data.json","starts");
  74.    
  75.     /*Show the server stats*/
  76.     print("++++++++++++++++++++Server Stats++++++++++++++++++++++");
  77.     printf("++ Restarts: %d | Visits: %d | Timeouts: %d", ServerInfo[sRestarts], ServerInfo[sVisits], ServerInfo[sTimeouts]);
  78.     printf("++ Deaths: %d | Kills: %d | Commands: %d", ServerInfo[sDeaths], ServerInfo[sKills], ServerInfo[sCommands]);
  79.     printf("++ Chat Messages: %d | Private Messages: %d", ServerInfo[sMessages], ServerInfo[sPMessages]);
  80.     print("++++++++++++++++++++Online Time+++++++++++++++++++++++");
  81.     printf("++ Days: %d | Hours: %d | Minutes: %d | Seconds : %d", ServerInfo[sDays], ServerInfo[sHours], ServerInfo[sMinutes], ServerInfo[sSeconds]);
  82.     print("++++++++++++++++++++++++++++++++++++++++++++++++++++++");
  83.    
  84.     /*Timer for updating the server stats. Update time can be changed @ ligne 15*/
  85.     SetTimer("UpdateServerStats", UPDATE_TIME*1000, 1);
  86.     /*Timer for updating the Uptime info*/
  87.     SetTimer("TimeUpdate", 10000, 1);
  88.     return 1;
  89. }
  90.  
  91. /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
  92.  
  93. public OnFilterScriptExit()
  94. {
  95.     /*Save all !*/
  96.     UpdateServerStats();
  97.     /*Unload DJson*/
  98.     djson_GameModeExit();
  99.     return 1;
  100. }
  101.  
  102. /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
  103.  
  104. public OnPlayerConnect(playerid)
  105. {
  106.     /*Augment the variable of the visits*/
  107.     ServerInfo[sVisits]++;
  108.     return 1;
  109. }
  110.  
  111. /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
  112.  
  113. public OnPlayerDisconnect(playerid, reason)
  114. {
  115.     /*If the reason is 0 : Timeout*/
  116.     if(reason == 0) ServerInfo[sTimeouts]++;
  117.     /*If the reason is 1 : Leaving*/
  118.     else if(reason == 1) ServerInfo[sLeaves]++;
  119.     /*If the reason is 2 : Kicked or banned*/
  120.     else if(reason == 2) ServerInfo[sKicks]++;
  121.     return 1;
  122. }
  123.  
  124. /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
  125.  
  126. public OnPlayerDeath(playerid, killerid, reason)
  127. {
  128.     /*If the killed is not an invalid player id*/
  129.     if(killerid != INVALID_PLAYER_ID)
  130.     {
  131.         /*Then augment both variables*/
  132.         ServerInfo[sDeaths]++;
  133.         ServerInfo[sKills]++;
  134.     }
  135.     /*If the killerid is an invalid player id*/
  136.     else
  137.     {
  138.         /*Then just augment one variable*/
  139.         ServerInfo[sDeaths]++;
  140.     }
  141.     return 1;
  142. }
  143.  
  144. /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
  145.  
  146. public OnPlayerText(playerid, text[])
  147. {
  148.     /*For every message in the chat, augment the variable*/
  149.     ServerInfo[sMessages]++;
  150.     return 1;
  151. }
  152.  
  153. /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
  154.  
  155. public OnPlayerPrivmsg(playerid, recieverid, text[])
  156. {
  157.     /*Same that chat message but this is PM*/
  158.     ServerInfo[sPMessages]++;
  159.     return 1;
  160. }
  161.  
  162. /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
  163.  
  164. public OnPlayerCommandText(playerid, cmdtext[])
  165. {
  166.     /*Same for the commands*/
  167.     ServerInfo[sCommands]++;
  168.     if (strcmp("/sstats", cmdtext, true) == 0)
  169.     {
  170.         new string[128];
  171.         ServerInfo[sRestarts] = djInt("data.json","starts");
  172.         SendClientMessage(playerid, COLOR_GREEN, "=== Server Stats ===");
  173.         format(string, sizeof(string), "Restarts : %d | Visits : %d | Leaves : %d", ServerInfo[sRestarts], ServerInfo[sVisits], ServerInfo[sLeaves]);
  174.         SendClientMessage(playerid, COLOR_BLUE, string);
  175.         format(string, sizeof(string), "Timeouts : %d | Kicks : %d | Commands : %d", ServerInfo[sTimeouts], ServerInfo[sKicks], ServerInfo[sCommands]);
  176.         SendClientMessage(playerid, COLOR_BLUE, string);
  177.         format(string, sizeof(string), "Deaths : %d | Kills : %d | Messages : %d | PMs : %d", ServerInfo[sDeaths], ServerInfo[sKills], ServerInfo[sMessages], ServerInfo[sPMessages]);
  178.         SendClientMessage(playerid, COLOR_BLUE, string);
  179.         format(string, sizeof(string), "Days : %d | Hours : %d | Minutes : %d | Seconds : %d", ServerInfo[sDays], ServerInfo[sHours], ServerInfo[sMinutes], ServerInfo[sSeconds]);
  180.         SendClientMessage(playerid, COLOR_BLUE, string);
  181.         return 1;
  182.     }
  183.     return 0;
  184. }
  185.  
  186. /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
  187.  
  188. /*Save all the stats =O */
  189. forward UpdateServerStats();
  190. public UpdateServerStats()
  191. {
  192.     djSetInt("data.json","visits",ServerInfo[sVisits]);
  193.     djSetInt("data.json","leaves",ServerInfo[sLeaves]);
  194.     djSetInt("data.json","timeouts",ServerInfo[sTimeouts]);
  195.     djSetInt("data.json","kicks",ServerInfo[sKicks]);
  196.     djSetInt("data.json","deaths",ServerInfo[sDeaths]);
  197.     djSetInt("data.json","kills",ServerInfo[sKills]);
  198.     djSetInt("data.json","commands",ServerInfo[sCommands]);
  199.     djSetInt("data.json","messages",ServerInfo[sMessages]);
  200.     djSetInt("data.json","pmessages",ServerInfo[sPMessages]);
  201.     djSetInt("data.json","seconds",ServerInfo[sSeconds]);
  202.     djSetInt("data.json","minutes",ServerInfo[sMinutes]);
  203.     djSetInt("data.json","hours",ServerInfo[sHours]);
  204.     djSetInt("data.json","days",ServerInfo[sDays]);
  205. }
  206.  
  207. /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
  208.  
  209. forward TimeUpdate();
  210. public TimeUpdate()
  211. {
  212.     ServerInfo[sSeconds] += 10;
  213.     if(ServerInfo[sSeconds] == 60)
  214.     {
  215.         ServerInfo[sMinutes]++;
  216.         ServerInfo[sSeconds] = 0;
  217.     }
  218.     if(ServerInfo[sMinutes] == 60)
  219.     {
  220.         ServerInfo[sHours]++;
  221.         ServerInfo[sMinutes] = 0;
  222.     }
  223.     if(ServerInfo[sHours] == 24)
  224.     {
  225.         ServerInfo[sDays]++;
  226.         ServerInfo[sHours] = 0;
  227.     }
  228. }
Advertisement
Add Comment
Please, Sign In to add comment