#define DONATORPATH "/donators/%s.ini" enum pInfo { pPass, pCash, pKills, pDeaths, pVipRank, pVipTime, pAdmin, pBanned } forward LoadDonator_data(playerid, name[], value[]); stock DonatorPath(playerid) { new string[128],playername[MAX_PLAYER_NAME]; GetPlayerName(playerid, playername, sizeof(playername)); format(string,sizeof(string),DONATORPATH,playername); return string; } stock ConvertToSeconds(years = 0, months = 0, days = 0, hours = 0, minutes = 0, seconds = 0) { new time = 0; time += (years * 31536000); time += (months * 2592000); time += (days * 86400); time += (hours * 3600); time += (minutes * 60); time += seconds; return time; } stock ConvertToDaysAndHours(days = 0, hours = 0, minutes = 0, seconds = 0) { while(seconds >= 60) minutes++, seconds -= 60; while(minutes >= 60) hours++, minutes -= 60; while(hours >= 24) days++, hours -= 24; new string[55], fstr[20]; if(days) format(fstr, sizeof(fstr), (hours || minutes || seconds) ? ("%d days, ") : ("%d days"), days), strins(string, fstr, 0); if(hours) format(fstr, sizeof(fstr), (minutes || seconds) ? ("%d hours, ") : ("%d hours"), hours), strins(string, fstr, strlen(string)); if(minutes) format(fstr, sizeof(fstr), (seconds) ? ("%d minutes, ") : ("%d minutes"), minutes), strins(string, fstr, strlen(string)); if(seconds) format(fstr, sizeof(fstr), "%d seconds", seconds), strins(string, fstr, strlen(string)); return string; }
SetTimer("CheckVIP", 60000, true);
forward CheckVIP(); public CheckVIP() { for(new i = 0; i < MAX_PLAYERS; i++) { if(!IsPlayerConnected(i)) continue; if(!PlayerInfo[i][pVipTime]) continue; if(PlayerInfo[i][pVipTime] <= gettime()) { PlayerInfo[i][pVipTime] = 0; PlayerInfo[i][pVipRank] = 0; SendClientMessage(i, -1, "Your VIP has expired."); } } return 1; }
CMD:setvip(playerid, params[]) { if(PlayerInfo[playerid][pAdmin] < 5) return SendClientMessage(playerid, -1, "You are not authorised to use this command."); new giveplayerid, level, days, hours; if(sscanf(params, "uddd", giveplayerid, level, days, hours)) return SendClientMessage(playerid, COLOR_WHITE, "USAGE: /setvip [playerid] [level] [days] [hours]") && SendClientMessage(playerid, COLOR_SIVA, "Available Levels: |0| None |1| Bronze |2| Silver |3| Gold |4| Platinum |5| Moderator"); if(!IsPlayerConnected(giveplayerid) || giveplayerid == INVALID_PLAYER_ID) return SendClientMessage(playerid, -1, "Player is not connected."); if(!(0 <= level <= 5)) return SendClientMessage(playerid, COLOR_SIVA, "VIP Level can not be below 0 or above 5."); if(!(0 <= days <= 30)) return SendClientMessage(playerid, COLOR_SIVA, "VIP Days can't be bigger than 30 days."); if(!(0 <= hours <= 23)) return SendClientMessage(playerid, COLOR_SIVA, "VIP Hours can't be bigger than 23 hours."); new string[128], viptime = (gettime() + ConvertToSeconds(.days = days, .hours = hours)); PlayerInfo[giveplayerid][pVipRank] = level; PlayerInfo[giveplayerid][pVipTime] = viptime; new INI:File = INI_Open(DonatorPath(playerid)); INI_SetTag(File, "data"); INI_WriteInt(File, "VipTime", PlayerInfo[giveplayerid][pVipTime]); INI_WriteInt(File, "VipRank", PlayerInfo[giveplayerid][pVipRank]); INI_Close(File); new rank[15]; switch(level) { case 0: rank = "Normal Player"; case 1: rank = "Bronze VIP"; case 2: rank = "Silver VIP"; case 3: rank = "Gold VIP"; case 4: rank = "Platinum VIP"; case 5: rank = "Moderator"; } format(string, sizeof(string), "You have been given a %s status.", rank); SendClientMessage(giveplayerid, -1, string); format(string, sizeof(string), "You have given a %s status.", rank); SendClientMessage(playerid, -1, string); return 1; }
public LoadDonator_data(playerid, name[], value[]) { INI_Int("VipRank", PlayerInfo[playerid][pVipRank]); INI_Int("VipTime", PlayerInfo[playerid][pVipTime]); return 1; }
Ohhh, i thought the timestamp will be readable numbers.
Can you give me an example how to use the ConvertToDaysAndHours to save in y_ini? Thanks btw i am learning! |
CMD:setvip(playerid, params[])
{
if(PlayerInfo[playerid][pAdmin] < 5) return SendClientMessage(playerid, -1, "You are not authorised to use this command.");
new giveplayerid, level, days, hours;
if(sscanf(params, "uddd", giveplayerid, level, days, hours))
return SendClientMessage(playerid, COLOR_WHITE, "USAGE: /setvip [playerid] [level] [days] [hours]") &&
SendClientMessage(playerid, COLOR_SIVA, "Available Levels: |0| None |1| Bronze |2| Silver |3| Gold |4| Platinum |5| Moderator");
if(!IsPlayerConnected(giveplayerid) || giveplayerid == INVALID_PLAYER_ID) return SendClientMessage(playerid, -1, "Player is not connected.");
if(!(0 <= level <= 5)) return SendClientMessage(playerid, COLOR_SIVA, "VIP Level can not be below 0 or above 5.");
if(!(0 <= days <= 30)) return SendClientMessage(playerid, COLOR_SIVA, "VIP Days can't be bigger than 30 days.");
if(!(0 <= hours <= 23)) return SendClientMessage(playerid, COLOR_SIVA, "VIP Hours can't be bigger than 23 hours.");
new string[128], viptime = (gettime() + ConvertToSeconds(.days = days, .hours = hours));
PlayerInfo[giveplayerid][pVipRank] = level;
PlayerInfo[giveplayerid][pVipTime] = viptime;
new INI:File = INI_Open(DonatorPath(playerid));
INI_SetTag(File, "data");
INI_WriteInt(File, "VipTime", ConvertToSeconds(0, 0, days, hours, 0, 0);
INI_WriteInt(File, "VipRank", PlayerInfo[giveplayerid][pVipRank]);
INI_Close(File);
new rank[15];
switch(level)
{
case 0: rank = "Normal Player";
case 1: rank = "Bronze VIP";
case 2: rank = "Silver VIP";
case 3: rank = "Gold VIP";
case 4: rank = "Platinum VIP";
case 5: rank = "Moderator";
}
format(string, sizeof(string), "You have been given a %s status.", rank);
SendClientMessage(giveplayerid, -1, string);
format(string, sizeof(string), "You have given a %s status.", rank);
SendClientMessage(playerid, -1, string);
return 1;
}
public OnPlayerClickPlayer(playerid, clickedplayerid, source) { new clickigrac[512]; new coordstring1[128]; new coordstring2[128]; new coordstring3[128]; new coordstring4[128]; new kills = PlayerInfo[clickedplayerid][pKills]; new deaths = PlayerInfo[clickedplayerid][pDeaths]; new viprank = PlayerInfo[clickedplayerid][pVipRank]; new viptime = PlayerInfo[clickedplayerid][pVipTime]; format(coordstring1, sizeof(coordstring1), "Ubistva:[%d]\n",kills); format(coordstring2, sizeof(coordstring2), "Umreno:[%d]\n",deaths); format(coordstring3, sizeof(coordstring3), "Vip Rank:[%d]\n",viprank); format(coordstring4, sizeof(coordstring4), "Vip Time:[%d]",viptime); format(clickigrac, 512,"%s%s%s%s",coordstring1,coordstring2,coordstring3,coordstring4); ShowPlayerDialog(playerid,KLIKMENU, DIALOG_STYLE_MSGBOX, "INFORMACIJA", clickigrac , "Dobro", ""); return 1; }