inactivechecker.inc 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. /*
  2. Author: $kylar
  3. Title: Inactive property checker
  4. Description: This script checks all properties (houses & businesses) on payday. If the property is owned by a player then
  5. it checks their last login. If it exceeds more than 30 days. Then it resets it.
  6. */
  7. // Every file where y_hooks is used must have this included. Do not remove! //
  8. #include <YSI\y_hooks>
  9. // Function that does the property activity checking //
  10. CheckInactiveHouses(){
  11. // INLINE FUNCTIONS. Look below to know which is hooked to which. //
  12. //________________________________________________________________//
  13. inline SQLFetchHouses(){
  14. // Storing the number of rows //
  15. new rows = cache_num_rows();
  16. // If there were any rows fetched at all then do the next steps otherwise simply get out of the inline function //
  17. if(rows > 0){
  18. new
  19. i,j, // loop variables //
  20. count, // Stores total houses that were reset //
  21. houseid, // Stores the SQL ID of the house //
  22. ownerid, // Stores the SQL ID of the owner of the house //
  23. name[MAX_PLAYER_NAME + 1], // Stores the name of the player //
  24. lastlogin[30], // Stores the last login of the player //
  25. day, month, year; // Stores the date month year respectively //
  26. // Looping though all the rows //
  27. for(i = 0; i < rows; i++){
  28. // Storing the data in the variables
  29. houseid = cache_get_field_content_int(i, "HouseID");
  30. ownerid = cache_get_field_content_int(i, "OwnerID");
  31. cache_get_field_content(i, "LastLogin", lastlogin);
  32. cache_get_field_content(i, "Name", name);
  33. // If the last login is none, continue //
  34. if(!strcmp(lastlogin, "none", .ignorecase = true))
  35. continue;
  36. // If the SQL ID of the player is offline //
  37. if(!IsSQLPlayerOnline(ownerid)){
  38. new
  39. dateString[15], // Stores the date string which is sliced from 'LastLogin' column
  40. timeString[15]; // Stores the time string which is sliced from 'LastLogin' column
  41. // Seperating the date and time from the 'LastLogin' string //
  42. sscanf(lastlogin, "s[15]s[15]", dateString, timeString);
  43. // Seperating the date / month / year from the dateString //
  44. sscanf(dateString, "p</>iii", month, day, year);
  45. new
  46. todayDay, // Stores today's date
  47. todayMonth, // Stores today's month
  48. todayYear; // Stores today's year
  49. // Get todays date, month and year //
  50. getdate(todayYear, todayMonth, todayDay);
  51. // Store the difference in days from lastlogin to today's date //
  52. new daysDifference = GetDaysDifference(day, month, year, todayDay, todayMonth, todayYear);
  53. // If the difference is less than a month //
  54. if(daysDifference <= 31)
  55. continue;
  56. // Getting the ID of the house //
  57. for(j = 1; j < MAX_HOUSES; j++){
  58. if(HouseInfo[j][hOwnerID] == ownerid){
  59. SetHouseOnSale(j);
  60. printf("[INACTIVE HOUSE] [%d]%s's house [%d] has been reset for $%d. Last login: %s", ownerid, name, houseid, HouseInfo[j][hValue], lastlogin);
  61. count++;
  62. break;
  63. }
  64. }
  65. }
  66. }
  67. // Sending the count of houses that were reset to every online Property Moderator //
  68. if(count > 0){
  69. new msg[128];
  70. format(msg, sizeof(msg), "[INACTIVE HOUSES] %d houses were reset due to their owners' inactivity", count);
  71. foreach(i:Player){
  72. if(PlayerInfo[i][pBizMod])
  73. SendClientMessage(i, COLOR_GRAD1, msg);
  74. }
  75. SaveHouses();
  76. }
  77. }
  78. }
  79. //_______________________________________________________________//
  80. // End of inline functions. Check functions below which call these inline functions //
  81. // First to deal with houses //
  82. // Fetching the houses data along with player SQL ID//
  83. mysql_pquery_inline(sqlGameConnection, "SELECT houses.HouseID, houses.OwnerID, players.ID, players.LastLogin, players.Name FROM houses INNER JOIN players ON houses.OwnerID = players.ID", using inline SQLFetchHouses, "");
  84. return 1;
  85. }
  86. // A function which returns true if the SQL ID player is online //
  87. IsSQLPlayerOnline(SQLID){
  88. foreach(new i: Player){
  89. if(SQLID == PlayerInfo[i][pID])
  90. return true;
  91. }
  92. return false;
  93. }