VIP System -
Lidor124 - 21.05.2014
Hey,
I have VIP System that i have written but since i have switched it by Timer for second only when the player is online the VIP time is counts down.
How to make it a real month even the server is closed or the player isn't online?
I think with gettime getdate but i have no idea how to do it.
+REP
Re: VIP System -
Threshold - 21.05.2014
pawn Код:
//When player becomes a VIP:
VIP[playerid] = (gettime() + ConvertToSeconds());
//At the bottom of your script:
stock ConvertToSeconds(years = 0, months = 0, days = 0, hours = 0, minutes = 0, seconds = 0)
{
new time = 0;
time += (years * 31536000); //Assumptions that each year is 365 days.
time += (months * 2592000); //Assumptions that each month is 30 days.
time += (days * 86400);
time += (hours * 3600);
time += (minutes * 60);
time += seconds;
return time;
}
For example, if you wanted to make a player a VIP for 3 months, 23 days, 14 hours and 12 seconds, you would do:
pawn Код:
VIP[playerid] = (gettime() + ConvertToSeconds(.months = 3, .days = 23, .hours = 14, .seconds = 12));
You can replace these with your own variables, and I'm not sure what your /setvip or whatever command is, so I can't do it for you without that code.
--
Then technically you can just create a minute timer to check all online players to see if their VIP has expired.
pawn Код:
public OnGameModeInit()
{
SetTimer("CheckVIP", 60000, true);
return 1;
}
forward CheckVIP();
public CheckVIP()
{
for(new i = 0; i < MAX_PLAYERS; i++) //foreach is the better option
{
if(!IsPlayerConnected(i)) continue;
if(!VIP[i]) continue;
if(VIP[i] <= gettime())
{
VIP[i] = 0;
SendClientMessage(i, -1, "Your VIP has expired.");
}
}
return 1;
}
This is just a small example of how you would go about doing it easily with timestamps etc.
Re: VIP System -
Lidor124 - 21.05.2014
Quote:
Originally Posted by BenzoAMG
pawn Код:
//When player becomes a VIP: VIP[playerid] = (gettime() + ConvertToSeconds());
//At the bottom of your script: stock ConvertToSeconds(years = 0, months = 0, days = 0, hours = 0, minutes = 0, seconds = 0) { new time = 0; time += (years * 31536000); //Assumptions that each year is 365 days. time += (months * 2592000); //Assumptions that each month is 30 days. time += (days * 86400); time += (hours * 3600); time += (minutes * 60); time += seconds; return time; }
For example, if you wanted to make a player a VIP for 3 months, 23 days, 14 hours and 12 seconds, you would do:
pawn Код:
VIP[playerid] = (gettime() + ConvertToSeconds(.months = 3, .days = 23, .hours = 14, .seconds = 12));
You can replace these with your own variables, and I'm not sure what your /setvip or whatever command is, so I can't do it for you without that code.
--
Then technically you can just create a minute timer to check all online players to see if their VIP has expired.
pawn Код:
public OnGameModeInit() { SetTimer("CheckVIP", 60000, true); return 1; }
forward CheckVIP(); public CheckVIP() { for(new i = 0; i < MAX_PLAYERS; i++) //foreach is the better option { if(!IsPlayerConnected(i)) continue; if(!VIP[i]) continue; if(VIP[i] <= gettime()) { VIP[i] = 0; SendClientMessage(i, -1, "Your VIP has expired."); } } return 1; }
This is just a small example of how you would go about doing it easily with timestamps etc.
|
Yes my command is /setvip and the VIP variable is PlayerInfo[playerid][pDonateRank].
Also i have more 2 questions:
1. Will it keep counting while the server offline? Even if i will save it on INI file of the player.
2. How the hell i save this on INI file? I'm using Y INI, the variable is PlayerInfo[playerid][pTempVIP], Its about 6 time types (year, month, day, hour, minute, second) How to save it on one line?
Код:
INI_WriteInt(File, "DonateRank", PlayerInfo[playerid][pDonateRank]);
INI_WriteInt(File, "VIPInviteDay", PlayerInfo[playerid][pVIPInviteDay]);
INI_WriteInt(File, "TempVIP", PlayerInfo[playerid][pTempVIP]);
What its print on INI file of user:
Код:
DonateRank = 3
VIPInviteDay = 0
TempVIP = 200754
Here the important part of the /setvip which doing the VIP time in seconds and saves it to INI file: (the 200754)
Код:
CMD:setvip(playerid, params[])
{
if(PlayerInfo[playerid][pAdmin] >= 99999 || PlayerInfo[playerid][pShopTech] >= 1)
{
new string[128], giveplayerid, level, days, hours;
if(sscanf(params, "uddd", giveplayerid, level, days, hours))
{
SendClientMessageEx(playerid, COLOR_WHITE, "USAGE: /setvip [playerid] [level] [days] [hours]");
SendClientMessageEx(playerid, COLOR_GRAD3, "Available Levels: |0| None |1| Bronze |2| Silver |3| Gold |4| Platinum |5| Moderator");
return 1;
}
if(IsPlayerConnected(giveplayerid))
{
if(giveplayerid != INVALID_PLAYER_ID)
{
if(level < 0 || level > 5) return SendClientMessageEx(playerid, COLOR_GRAD1, "VIP Level can not be below 0 or above 6.");
if(days < 0 || days > 30) return SendClientMessageEx(playerid, COLOR_GREY, "VIP Days can't be bigger than 30 days.");
if(hours < 0 || hours > 24) return SendClientMessageEx(playerid, COLOR_GREY, "VIP Hours can't be bigger than 24 hours.");
new daycal = 86400*days;
new hourcal = 3600*hours;
new viptime = daycal+hourcal;
PlayerInfo[giveplayerid][pDonateRank] = level;
PlayerInfo[giveplayerid][pTempVIP] = viptime;
PlayerInfo[giveplayerid][pBuddyInvited] = 1;
Re: VIP System -
BroZeus - 21.05.2014
https://sampforum.blast.hk/showthread.php?tid=254915
Re: VIP System -
Lidor124 - 21.05.2014
Quote:
Originally Posted by BroZeus
|
Yes but how to save it with Y_INI?
Re: VIP System -
DobbysGamertag - 21.05.2014
Simple way (exampe of 60 day VIP):
pawn Код:
PlayerVIP[playerid] = gettime()+60*8400;
/*
PlayerVIP[playerid] is the player variable.
60 being the amount of days.
*86400 times it. Basically sets an expiry some time in the future, and yes, this will decrease even when the server is offline since gettime() uses UNIX timestamps.
*/
IniWriteInt(somefile,"VIP",PlayerVIP[playerid]);
//checking if they're VIP still:
if(PlayerVIP[playerid] > gettime())
{
//they are
}
else
{
//they arent.
}
Re: VIP System -
Lidor124 - 22.05.2014
Quote:
Originally Posted by DobbysGamertag
Simple way (exampe of 60 day VIP):
pawn Код:
PlayerVIP[playerid] = gettime()+60*8400; /* PlayerVIP[playerid] is the player variable. 60 being the amount of days. *86400 times it. Basically sets an expiry some time in the future, and yes, this will decrease even when the server is offline since gettime() uses UNIX timestamps.
*/
IniWriteInt(somefile,"VIP",PlayerVIP[playerid]);
//checking if they're VIP still:
if(PlayerVIP[playerid] > gettime()) { //they are } else { //they arent. }
|
Okay that part i already understood, how do i write it with Y INI?
on the command /setvip - what will it do?
Код:
if(sscanf(params, "uddd", giveplayerid, level, days, hours))
new daycal = 86400*days;
new hourcal = 3600*hours;
new viptime = daycal+hourcal;
PlayerInfo[giveplayerid][pTempVIP] = gettime() + viptime;
new File: File = INI_Open("user.ini");
INI_WriteInt(File, "TempVIP", PlayerInfo[playerid][pTempVIP]);
Re: VIP System -
Threshold - 22.05.2014
pawn Код:
public OnGameModeInit()
{
SetTimer("CheckVIP", 60000, true);
return 1;
}
CMD:setvip(playerid, params[])
{
if(PlayerInfo[playerid][pAdmin] < 99999 && !PlayerInfo[playerid][pShopTech]) 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 SendClientMessageEx(playerid, COLOR_WHITE, "USAGE: /setvip [playerid] [level] [days] [hours]") &&
SendClientMessageEx(playerid, COLOR_GRAD3, "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 SendClientMessageEx(playerid, COLOR_GRAD1, "VIP Level can not be below 0 or above 5.");
if(!(0 <= days <= 30)) return SendClientMessageEx(playerid, COLOR_GREY, "VIP Days can't be bigger than 30 days.");
if(!(0 <= hours <= 23)) return SendClientMessageEx(playerid, COLOR_GREY, "VIP Hours can't be bigger than 23 hours.");
new string[128], viptime = (gettime() + ConvertToSeconds(.days = days, .hours = hours));
PlayerInfo[giveplayerid][pDonateRank] = level;
PlayerInfo[giveplayerid][pTempVIP] = viptime;
PlayerInfo[giveplayerid][pBuddyInvited] = 1;
new INI:File = INI_Open("user.ini");
INI_SetTag(File, "data");
INI_WriteInt(File, "TempVIP", PlayerInfo[giveplayerid][pTempVIP]);
INI_WriteInt(File, "DonateRank", PlayerInfo[giveplayerid][pDonateRank]);
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;
}
forward CheckVIP();
public CheckVIP()
{
for(new i = 0; i < MAX_PLAYERS; i++) //foreach is the better option
{
if(!IsPlayerConnected(i)) continue;
if(!PlayerInfo[i][pTempVIP]) continue;
if(PlayerInfo[i][pTempVIP] <= gettime())
{
PlayerInfo[i][pTempVIP] = 0;
PlayerInfo[i][pDonateRank] = 0;
SendClientMessage(i, -1, "Your VIP has expired.");
}
}
return 1;
}
stock ConvertToSeconds(years = 0, months = 0, days = 0, hours = 0, minutes = 0, seconds = 0)
{
new time = 0;
time += (years * 31536000); //Assumptions that each year is 365 days.
time += (months * 2592000); //Assumptions that each month is 30 days.
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;
}
forward LoadDonator_data(playerid, name[], value[]);
public LoadDonator_data(playerid, name[], value[])
{
INI_Int("TempVIP", PlayerInfo[playerid][pTempVIP]);
INI_Int("DonateRank", PlayerInfo[playerid][pDonateRank]);
return 1;
}
Then when the player logs in:
pawn Код:
//When user logs in:
INI_ParseFile("user.ini", "LoadDonator_%s", .bExtra = true, .extra = playerid);
You didn't post the rest of your code, so I made up the rest with what I thought you would be wanting.
Re: VIP System -
Lidor124 - 22.05.2014
Quote:
Originally Posted by BenzoAMG
pawn Код:
public OnGameModeInit() { SetTimer("CheckVIP", 60000, true); return 1; }
CMD:setvip(playerid, params[]) { if(PlayerInfo[playerid][pAdmin] < 99999 && !PlayerInfo[playerid][pShopTech]) 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 SendClientMessageEx(playerid, COLOR_WHITE, "USAGE: /setvip [playerid] [level] [days] [hours]") && SendClientMessageEx(playerid, COLOR_GRAD3, "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 SendClientMessageEx(playerid, COLOR_GRAD1, "VIP Level can not be below 0 or above 5."); if(!(0 <= days <= 30)) return SendClientMessageEx(playerid, COLOR_GREY, "VIP Days can't be bigger than 30 days."); if(!(0 <= hours <= 23)) return SendClientMessageEx(playerid, COLOR_GREY, "VIP Hours can't be bigger than 23 hours."); new string[128], viptime = (gettime() + ConvertToSeconds(.days = days, .hours = hours)); PlayerInfo[giveplayerid][pDonateRank] = level; PlayerInfo[giveplayerid][pTempVIP] = viptime; PlayerInfo[giveplayerid][pBuddyInvited] = 1; new INI:File = INI_Open("user.ini"); INI_SetTag(File, "data"); INI_WriteInt(File, "TempVIP", PlayerInfo[giveplayerid][pTempVIP]); INI_WriteInt(File, "DonateRank", PlayerInfo[giveplayerid][pDonateRank]); 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; }
forward CheckVIP(); public CheckVIP() { for(new i = 0; i < MAX_PLAYERS; i++) //foreach is the better option { if(!IsPlayerConnected(i)) continue; if(!PlayerInfo[i][pTempVIP]) continue; if(PlayerInfo[i][pTempVIP] <= gettime()) { PlayerInfo[i][pTempVIP] = 0; PlayerInfo[i][pDonateRank] = 0; SendClientMessage(i, -1, "Your VIP has expired."); } } return 1; }
stock ConvertToSeconds(years = 0, months = 0, days = 0, hours = 0, minutes = 0, seconds = 0) { new time = 0; time += (years * 31536000); //Assumptions that each year is 365 days. time += (months * 2592000); //Assumptions that each month is 30 days. 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; }
forward LoadDonator_data(playerid, name[], value[]); public LoadDonator_data(playerid, name[], value[]) { INI_Int("TempVIP", PlayerInfo[playerid][pTempVIP]); INI_Int("DonateRank", PlayerInfo[playerid][pDonateRank]); return 1; }
Then when the player logs in:
pawn Код:
//When user logs in: INI_ParseFile("user.ini", "LoadDonator_%s", .bExtra = true, .extra = playerid);
You didn't post the rest of your code, so I made up the rest with what I thought you would be wanting.
|
Thanks Benzo, i understood the point, +REP for your efforts.