Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* daily_reward - por EnzoMetlc 21/11/2015 */
- #include <a_samp>
- #include <iZCMD>
- #include <sscanf2>
- #include <file_system>
- #define IsNextDay([%1,%2,%3],[%4,%5,%6]) IsNextDay_ex(%1, %2, %3, %4, %5, %6)
- static DailyReward_Count[MAX_PLAYERS];
- public OnPlayerConnect(playerid)
- {
- new file[34];
- GetPlayerName(playerid, file, sizeof(file));
- format(file, sizeof(file), "users/%s.txt", file);
- File_Open(file, io_read)
- {
- new date[3], fdate[3];
- getdate(date[0], date[1], date[2]);
- File_ReadInt("Year", fdate[0]);
- File_ReadInt("Month", fdate[0]);
- File_ReadInt("Day", fdate[0]);
- File_ReadInt("Count", DailyReward_Count[playerid]);
- switch(IsNextDay([date[0], date[1], date[2]], [fdate[0], fdate[1], fdate[2]]))
- {
- //case -1: return 1; // Es el mismo día.
- case 0: // No es el día siguiente.
- {
- if(DailyReward_Count[playerid] != 0)
- {
- SendClientMessage(playerid, -1, "* Rompiste tus Recompensas Diarias, cónectate diaramente para conseguirlas!");
- DailyReward_Count[playerid] = 0;
- }
- }
- case 1: // Es el día siguiente a su última conexión
- {
- if(++DailyReward_Count[playerid] == 8)
- {
- SendClientMessage(playerid, -1, "[Recompensa Diaria] Llegaste a tu séptimo día de conexión diaria, las recompensas se restablecieron.");
- DailyReward_Count[playerid] = 1;
- }
- new str[128];
- format(str, sizeof(str), "[Recompensa Diaria] Ganaste $%i y %i XP por tu conexión diaria.", DailyReward_Count[playerid] * 100, DailyReward_Count[playerid] * 10);
- SendClientMessage(playerid, -1, str);
- GivePlayerMoney(playerid, DailyReward_Count[playerid] * 100);
- SetPlayerScore(playerid, GetPlayerScore(playerid) + DailyReward_Count[playerid] * 10);
- }
- }
- }
- return 1;
- }
- public OnPlayerDisconnect(playerid, reason)
- {
- new file[34];
- GetPlayerName(playerid, file, sizeof(file));
- format(file, sizeof(file), "users/%s.txt", file);
- File_Open(file, io_write)
- {
- new date[3];
- getdate(date[0], date[1], date[2]);
- File_WriteInt("Year", date[0]);
- File_WriteInt("Month", date[0]);
- File_WriteInt("Day", date[0]);
- File_WriteInt("Count", DailyReward_Count[playerid]);
- }
- return 1;
- }
- /* Retornos:
- (1) es el día siguiente
- (0) no es el día siguiente
- (-1) es el mismo día
- */
- stock IsNextDay_ex(cur_year, cur_month, cur_day, prev_year, prev_month, prev_day)
- {
- if(cur_month == prev_month) // Es el mismo mes
- {
- if(cur_day == prev_day) return -1; // Es el mismo día
- return ((cur_day - prev_day) == 1); // Retorna si es el día siguiente o si no lo es
- }
- // Desde aquí en adelante verificamos si es el día siguiente de diferentes meses
- if((cur_month - prev_month) != 1) // Si no es el mes siguiente, procedemos a verificar si es por el cambio de año
- {
- if(cur_year - prev_year != 1) return 0; // No es el año siguiente, por lógica no es el día siguiente
- if(!(prev_month == 12 && cur_month == 1)) return 0; // No es el mes siguiente, por lógica no es el día siguiente
- }
- // 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
- return ((cur_day == 1) && (prev_day == GetMaxDaysOfMonth(prev_year, prev_month)));
- }
- stock GetMaxDaysOfMonth(year, month)
- {
- if(month == 2) return (!(year % 4)) ? (29) : (28);
- new const MaxDayOfMonth[12] = {31, -1, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
- return MaxDayOfMonth[month - 1];
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement