VIP System HELP!
#1

Hello, I am using y_ini to save the temp vip time and every 60 secounds checking if player has vip time passed.

When i set /setvip [id] [viprank] [day] [hours]
i get random numbers in the file that are so big not even close to what i set.

BEGIN
Код:
#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;
}
OnGameModeInit

Код:
SetTimer("CheckVIP", 60000, true);
CheckVIP
Код:
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;
}
AND the main cmd
Код:
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;
}
After i set my vip to be 1 day and 1 hour in the .ini stays VipTime = 1552683918 !!!
Please help me i am new to this
Reply
#2

And the public load data.
Код:
public LoadDonator_data(playerid, name[], value[])
{

	INI_Int("VipRank", PlayerInfo[playerid][pVipRank]);
	INI_Int("VipTime", PlayerInfo[playerid][pVipTime]);
	return 1;
}
Reply
#3

This are not random numbers. You're saving an integer, and what is saved in VipTime is the UNIX timestamp.

In the file the VipTime saved is: 1552683918, means the VIP status will expire on Friday 15 Mar 2019 21:05:18.

What's wrong with that? If you want to save readable numbers, then just use ConvertToDaysAndHours and ConvertToSeconds, but you've to edit it accordingly to your VIP system.
Reply
#4

its TimeStamp (UNIX) Format not the usual time format !
https://sampforum.blast.hk/showthread.php?tid=254915
Reply
#5

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!
Reply
#6

Quote:
Originally Posted by lynxhero1337
Посмотреть сообщение
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!
pawn Код:
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;
}
Now everytime you set someone VIP for, example, 1 day, it'll show 86400 in the .ini file, instead of that UNIX timestamp.
Reply
#7

Код:
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;
}
Reply
#8

And if i relog and restart the server it gives me message that vip has expired but in the .ini

[data]
VipRank = 1
VipTime = 3600
Reply
#9

You're still saving as UNIX timestamp. Also to show it in readable numbers you have to convert it using ConvertToDaysAndHours.
Reply
#10

Can you explain me how can i convert using ConvertToDaysAndHours?
Reply
#11

bump
Reply
#12

bump need help so much!
Reply
#13

Use new DaysLeft = viptime - gettime() / 86400;
Reply
#14

Where should i put this?
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)