Advertisement
EnzoMetlc

[FilterScript] Recompensa diaria.

Nov 27th, 2015
349
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.88 KB | None | 0 0
  1. /* daily_reward - por EnzoMetlc 21/11/2015 */
  2. #include <a_samp>
  3. #include <iZCMD>
  4. #include <sscanf2>
  5. #include <file_system>
  6.  
  7.  
  8. #define IsNextDay([%1,%2,%3],[%4,%5,%6]) IsNextDay_ex(%1, %2, %3, %4, %5, %6)
  9.  
  10.  
  11. static DailyReward_Count[MAX_PLAYERS];
  12.  
  13.  
  14. public OnPlayerConnect(playerid)
  15. {
  16. new file[34];
  17. GetPlayerName(playerid, file, sizeof(file));
  18. format(file, sizeof(file), "users/%s.txt", file);
  19.  
  20. File_Open(file, io_read)
  21. {
  22. new date[3], fdate[3];
  23. getdate(date[0], date[1], date[2]);
  24.  
  25. File_ReadInt("Year", fdate[0]);
  26. File_ReadInt("Month", fdate[0]);
  27. File_ReadInt("Day", fdate[0]);
  28. File_ReadInt("Count", DailyReward_Count[playerid]);
  29.  
  30. switch(IsNextDay([date[0], date[1], date[2]], [fdate[0], fdate[1], fdate[2]]))
  31. {
  32. //case -1: return 1; // Es el mismo día.
  33. case 0: // No es el día siguiente.
  34. {
  35. if(DailyReward_Count[playerid] != 0)
  36. {
  37. SendClientMessage(playerid, -1, "* Rompiste tus Recompensas Diarias, cónectate diaramente para conseguirlas!");
  38. DailyReward_Count[playerid] = 0;
  39. }
  40. }
  41. case 1: // Es el día siguiente a su última conexión
  42. {
  43. if(++DailyReward_Count[playerid] == 8)
  44. {
  45. SendClientMessage(playerid, -1, "[Recompensa Diaria] Llegaste a tu séptimo día de conexión diaria, las recompensas se restablecieron.");
  46. DailyReward_Count[playerid] = 1;
  47. }
  48.  
  49. new str[128];
  50. format(str, sizeof(str), "[Recompensa Diaria] Ganaste $%i y %i XP por tu conexión diaria.", DailyReward_Count[playerid] * 100, DailyReward_Count[playerid] * 10);
  51. SendClientMessage(playerid, -1, str);
  52. GivePlayerMoney(playerid, DailyReward_Count[playerid] * 100);
  53. SetPlayerScore(playerid, GetPlayerScore(playerid) + DailyReward_Count[playerid] * 10);
  54. }
  55. }
  56. }
  57. return 1;
  58. }
  59.  
  60.  
  61. public OnPlayerDisconnect(playerid, reason)
  62. {
  63. new file[34];
  64. GetPlayerName(playerid, file, sizeof(file));
  65. format(file, sizeof(file), "users/%s.txt", file);
  66.  
  67. File_Open(file, io_write)
  68. {
  69. new date[3];
  70. getdate(date[0], date[1], date[2]);
  71.  
  72. File_WriteInt("Year", date[0]);
  73. File_WriteInt("Month", date[0]);
  74. File_WriteInt("Day", date[0]);
  75. File_WriteInt("Count", DailyReward_Count[playerid]);
  76. }
  77. return 1;
  78. }
  79.  
  80.  
  81.  
  82. /* Retornos:
  83.  
  84. (1) es el día siguiente
  85. (0) no es el día siguiente
  86. (-1) es el mismo día
  87. */
  88. stock IsNextDay_ex(cur_year, cur_month, cur_day, prev_year, prev_month, prev_day)
  89. {
  90. if(cur_month == prev_month) // Es el mismo mes
  91. {
  92. if(cur_day == prev_day) return -1; // Es el mismo día
  93. return ((cur_day - prev_day) == 1); // Retorna si es el día siguiente o si no lo es
  94. }
  95.  
  96. // Desde aquí en adelante verificamos si es el día siguiente de diferentes meses
  97.  
  98. if((cur_month - prev_month) != 1) // Si no es el mes siguiente, procedemos a verificar si es por el cambio de año
  99. {
  100. if(cur_year - prev_year != 1) return 0; // No es el año siguiente, por lógica no es el día siguiente
  101. if(!(prev_month == 12 && cur_month == 1)) return 0; // No es el mes siguiente, por lógica no es el día siguiente
  102. }
  103.  
  104. // Si "cur_day" es igual a (1) y "prev_day" es igual al último día del mes anterior, entonces es el día siguiente
  105. return ((cur_day == 1) && (prev_day == GetMaxDaysOfMonth(prev_year, prev_month)));
  106. }
  107.  
  108.  
  109. stock GetMaxDaysOfMonth(year, month)
  110. {
  111. if(month == 2) return (!(year % 4)) ? (29) : (28);
  112.  
  113. new const MaxDayOfMonth[12] = {31, -1, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
  114. return MaxDayOfMonth[month - 1];
  115. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement