[HELP] Unix Timestamp
#1

I need help on getting the date when the player will lost his VIP.
For example, Today is November 24, and i set someone's VIP for 2 days, It should display something like this

"You are now VIP, Your VIP will expire in November 26".

I am using Unix Timestamp to do these expiration stuffs, and SQLite to save the timestamp.

I've used Vince's advice on someone's topic about the temporary VIP system, Do you think it would work?

And is it even possible to get the date of the expiration?

pawn Code:
CMD:setvip(playerid, params[])
{
    new
        string[200],
        id,
        level,
        days
    ;

    LoginCheck(playerid);
    if(User[playerid][accountAdmin] >= 3)
    {
        if(sscanf(params, "uii", id, level, days)) return SendClientMessage(playerid, COLOR_RED, "USAGE: /setvip [playerid] [level(0/1)] [days]");
        if(id == INVALID_PLAYER_ID) return SendClientMessage(playerid, -1, "» "red"Player not connected.");
        if(level < 0 || level > 1) return SendClientMessage(playerid, -1, "» "red"Levels shouldn't go below zero and shouldn't go above one.");
        if(level == User[id][accountVIP]) return SendClientMessage(playerid, -1, "» "red"Player is already in that VIP level.");
        if(User[id][accountLogged] == false) return SendClientMessage(playerid, -1, "» "red"Player not logged in.");
        if(level != 0)
        {
            if(days < 2 || days > 363) return SendClientMessage(playerid, -1, "» "red"Expiration shouldn't go below two and shouldn't go abovee three hundred three.");
            return 1;
        }

        if(level == 1)
        {
            User[id][ExpirationVIP] = gettime() + 60*60*24*days;
       
            format(string, 128, "» "newb"You have been invited to the VIP Team by %s.", GetName(playerid));
            SendClientMessage(id, -1, string);
            format(string, 128, "» "newb"You have invited %s to VIP Team rank.", GetName(id));
            SendClientMessage(playerid, -1, string);

            format(string, 128, "%s has been invited to the VIP Team by %s.", GetName(id), GetName(playerid));
            Log("premium.txt", string);
        }
        else if(level == 0)
        {
            days = 0;
       
            format(string, 128, "» "newb"You have been kicked out from the VIP Team by %s.", GetName(playerid));
            SendClientMessage(id, -1, string);
            format(string, 128, "» "newb"You have kicked out %s from the VIP team.", GetName(id));
            SendClientMessage(playerid, -1, string);

            format(string, 128, "%s has been kicked out from the VIP Team by %s.", GetName(id), GetName(playerid));
            Log("premium.txt", string);
        }

        User[id][accountVIP] = level;

        SaveData(id);
    }
    else
    {
        SendClientMessage(playerid, -1, "» "red"You are not authorized to use this command.");
    }
    return 1;
}
Reply
#2

One assumes you're using MySQL.

You can store the expiry date of the VIP to a person's data inside their MySQL table and then pull the information through either inside the command, or in your stock loading the player data. I would recommend the stock.
Reply
#3

I know that ..

I was asking how do i get the expiration date of my VIP System..

Thanks for trying by the way.
Reply
#4

Getting the actual date from a unix timestamp isnt easy, as there are several things to consider (leap years, leap seconds, etc).
I wouldnt attempt to do that manually in pawn, rather take a converter that already exists. 'date' works for linux when using e.g. the shell plugin. SQLite also offers time and date functions: https://www.sqlite.org/lang_datefunc.html
Reply
#5

Oh sorry, I misread what you needed. Did some research and found this, using SQL.

select FROM_UNIXTIME(UNIX_TIMESTAMP(),'%a %b %d %H:%i:%s UTC %Y');

According to the website, this would output the following format: 'Wed Feb 05 05:36:16 UTC 2014'

Look here for further: http://stackoverflow.com/questions/2...atetime-format
Reply
#6

If that's the case, Is it possible to get the remaining days instead?

Like "You have %d (E.G. 7 days) left on your VIP."
Reply
#7

Quote:
Originally Posted by _Jake_
View Post
If that's the case, Is it possible to get the remaining days instead?

Like "You have %d (E.G. 7 days) left on your VIP."
Sure, getting the remaining days is much easier, just compare the current time to the expiration time you stored before.

pawn Code:
new remaining_seconds = gettime() - User[id][ExpirationVIP];
new remaining_days = remaining_seconds / 3600 / 24;
Reply
#8

Alright, What if the expiration date is for example Today, Is the code you given are accurate ?

Well sorry about for asking lots of questions, I am not that good at timestamp stuffs.
Reply
#9

Its actually just using the remaining seconds, and calculates the days from it. If the expiration time is in less than 24 hours, it will show "0 days remaining". So if it e.g. expires at 1AM the next day, and currently its 11PM it will also show 0 days. Is this the behaviour you want? Or should it actually consider the date, so in the "expires-at-1AM" example it would show 1 day until its 0AM?
This would be more work then, and its hard to do that accurately as players timezones dont have to be the same as the servers timezone.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)