VIP days, looking for code check & explanation
#1

Alright so Ive made some code for temporarly donations, aka for example 30 days and shit, altho I dont get it at all, would this even work?
I cant really test it since I Need 1 day to expire...


This is how im saving it into the sql
pawn Код:
pInfo[playerid][VIPDays]+ getdate()
`VIPDays`=%d

pawn Код:
pInfo[playerid][VIPDays] -30 > getdate())
                {
                    SendClientMessage(playerid,COLOR_GREEN,"Your VIP has expired! Thank you for donating!");
                    pInfo[playerid][VIP] = 0;
                }

Now if im correct, its saved in the SQL as int 205 (205 days since new year)
Now it will compare if VIP Days (lets say 30) are greater than current date?

AKA VIPDays are old date and getdate() is getting new date? Correct?

And also will that code even work
Reply
#2

Take a moment to read this tutorial: https://sampforum.blast.hk/showthread.php?tid=254915

getdate() returns a Unix Timestamp, you will need to calculate how many seconds are in a day and add that on to the current date to figure out when +1 day is.
Reply
#3

Read it like 100 times atleast mate, I still dont get it how to use it to be honest.
Reply
#4

Quote:

This is how im saving it into the sql

SQL?

Код:
"CREATE EVENT `removevip_%i` ON SCHEDULE EVERY 1 MONTH STARTS NOW() DO UPDATE `users` SET `playerVIP`=0 WHERE `uniqeID`=%i", playerData[toplayerid][uID], playerData[toplayerid][uID] // (uniqueid)
I suppose you can change it to your own things?
Reply
#5

A unix timestamp is a number, the amount of seconds it has been since January 1, 1970. Right now, that's approximately at 1437784996 seconds - though it doesn't account for timezones, it accounts for the time of the server it's being checked from (the server will generate a unix timestamp by calculating how many seconds it has been since 1970).

So now you have this number, you have a rough guide of where we are at in time, we can add to that time or subtract from it for measurement purposes. We can add a day to the current timestamp (1437784996) which is (1437784996+86400), that number will now represent 01:43 on the 26th of July instead of 01:43 (a day ahead) on the 25th of July (the current time, well, close enough, I forgot when I started writing this post).

If you set your VIPDays variable to the current unix timestamp then add 31 days (86400 * 31; that is 1 day in seconds multiplied by 31, number of days in a month) you can check if that timestamp is in the future or the past. So at this point we would write this code:
pawn Код:
pInfo[playerid][VIPDays] = (getdate() + (86400 * 31)); // Giving the player 31 days of VIP
Remember, we get the current unix timestamp, then add 31 days (in seconds) to that value. Now we can check if that date has passed when the player logs in:

pawn Код:
if(pInfo[playerid][VIPDays] < getdate()) { // The player's VIP has expired, do what you want here.
}
So you're checking if the value is in the future or the past, fairly simple?
Reply
#6

Okay so I get one part, lets say
pawn Код:
(86400 * 31);
86400 (seconds in day) x 31 day

And I will get int such as 2,678,812 seconds

Okay now I have those 2 milion seconds, and I compare it with getdate?

Also how could I format it to tell player how many days he has left?
Reply
#7

Quote:
Originally Posted by TwinkiDaBoss
Посмотреть сообщение
Okay now I have those 2 milion seconds, and I compare it with getdate?
I have just shown you.

pawn Код:
pInfo[playerid][VIPDays] = (getdate() + (86400 * 31)); // This is how you give the player 31 days.

if(pInfo[playerid][VIPDays] < getdate()) { // This is how you check if the VIP timestamp was in the past, or is in the future
}
Remember, getdate() gives you the current timestamp. The value of pInfo[playerid][VIPDays] will be behind getdate() in 31 days, the number in getdate() changes every second but pInfo[playerid][VIPDays] will stay the same, eventually getdate() will be a larger number than pInfo[playerid][VIPDays] so when you run a check using if(), it will tell you that getdate() is a larger number.

Quote:
Originally Posted by TwinkiDaBoss
Посмотреть сообщение
Also how could I format it to tell player how many days he has left?
SickAttack has given you a good example, check how he's used the custom ConvertToTime function.
Reply
#8

EDIT: Okay sorry I havent seen that, but the code you gave me for example wont work. Whenever I connect it says that it expired.

PHP код:
if(pInfo[playerid][VIPDays] < getdate()) 
Reply
#9

Quote:
Originally Posted by TwinkiDaBoss
Посмотреть сообщение
And how could I print out time left for it if its even possible?
You can read SickAttack's example.
Reply
#10

Quote:
Originally Posted by TwinkiDaBoss
Посмотреть сообщение
EDIT: Okay sorry I havent seen that, but the code you gave me for example wont work. Whenever I connect it says that it expired.

PHP код:
if(pInfo[playerid][VIPDays] < getdate()) 
Here's another method:

When you give someone VIP, set their existent list element to gettime() (the one you already created, the one that saves the timestamp). Make a new field in your database containing the days that their VIP membership will expire in advance.

Replace the following temp-text codes with their respective fields:
  • Replace '(PLACE THE TIMESTAMP LIST ELEMENT HERE)' for your list element that contains the timestamp when you gave the player VIP status.
  • Replace '(PLACE THE DAY LIST ELEMENT HERE)' for your list element that contains the days they were given.
And then use the following code as a reference.

pawn Код:
// [ DEVELOPMENT GAMEMODE ]

// INCLUDES:

#include <a_samp>
#include <zcmd>

// DEFINES:

// FUNCTIONS:

#define plural_singular(%0,%1,%2) ((%0) == 1) ? ((#%1)) : ((#%2))

// MAIN:

main()
{
    print("Development Mode: expire_time.amx");
}

// CALLBACKS:

public OnGameModeInit()
{
    return 1;
}

public OnGameModeExit()
{
    return 1;
}

// COMMANDS:

CMD:timeleft(playerid, params[])
{
    if((gettime() - (PLACE THE TIMESTAMP LIST ELEMENT HERE)) < (PLACE THE DAY LIST ELEMENT HERE))
    {
        new string[144], second = (PLACE THE TIMESTAMP LIST ELEMENT HERE) - gettime() + (PLACE THE DAY LIST ELEMENT HERE), minute, hour, day, week, month, year;
        format(string, sizeof(string), "Time left: %s.", ConvertToTime(second, minute, hour, day, week, month, year));
        SendClientMessage(playerid, -1, string);
    }
    else
    {
        SendClientMessage(playerid, -1, "30 days have passed.");
    }
    return 1;
}

CMD:timeover(playerid, params[])
{
    if((gettime() - (PLACE THE TIMESTAMP LIST ELEMENT HERE)) < (PLACE THE DAY LIST ELEMENT HERE))
    {
        SendClientMessage(playerid, -1, "30 days hasn't passed yet.");
        return cmd_timeleft(playerid, "");
    }
    else
    {
        SendClientMessage(playerid, -1, "30 days have passed.");
    }
    return 1;
}

// FUNCTIONS:

stock ConvertToTime(&second, &minute = -1, &hour = -1, &day = -1, &week = -1, &month = -1, &year = -1)
{
    #define seconds_in_year 31536000
    #define seconds_in_month 2628000
    #define seconds_in_week 604800
    #define seconds_in_day 86400
    #define seconds_in_hour 3600
    #define seconds_in_minute 60
    #define convert_seconds(%1) %1 = second / seconds_in_%1; second %= seconds_in_%1

    new string[128];
    if(year != -1 && (second / seconds_in_year))
    {
        convert_seconds(year); convert_seconds(month); convert_seconds(week); convert_seconds(day); convert_seconds(hour); convert_seconds(minute);
        format(string, sizeof(string), "%d %s, %d %s, %d %s, %d %s, %d %s, %d %s, and %d %s", year, plural_singular(year, "year", "years"), month, plural_singular(month, "month", "months"), \
        week, plural_singular(week, "week", "weeks"), day, plural_singular(day, "day", "days"), hour, plural_singular(hour, "hour", "hours"), minute, plural_singular(minute, "minute", "minutes"), \
        second, plural_singular(second, "second", "seconds"));
        return string;
    }
    if(month != -1 && (second / seconds_in_month))
    {
        year = 0; convert_seconds(month); convert_seconds(week); convert_seconds(day); convert_seconds(hour); convert_seconds(minute);
        format(string, sizeof(string), "%d %s, %d %s, %d %s, %d %s, %d %s, and %d %s", month, plural_singular(month, "month", "months"), week, plural_singular(week, "week", "weeks"), \
        day, plural_singular(day, "day", "days"), hour, plural_singular(hour, "hour", "hours"), minute, plural_singular(minute, "minute", "minutes"), second, plural_singular(second, "second", "seconds"));
        return string;
    }
    if(week != -1 && (second / seconds_in_week))
    {
        year = 0, month = 0; convert_seconds(week); convert_seconds(day); convert_seconds(hour); convert_seconds(minute);
        format(string, sizeof(string), "%d %s, %d %s, %d %s, %d %s, and %d %s", week, plural_singular(week, "week", "weeks"), day, plural_singular(day, "day", "days"), \
        hour, plural_singular(hour, "hour", "hours"), minute, plural_singular(minute, "minute", "minutes"), second, plural_singular(second, "second", "seconds"));
        return string;
    }
    if(day != -1 && (second / seconds_in_day))
    {
        year = 0, month = 0, week = 0; convert_seconds(day); convert_seconds(hour); convert_seconds(minute);
        format(string, sizeof(string), "%d %s, %d %s, %d %s, and %d %s", day, plural_singular(day, "day", "days"), hour, plural_singular(hour, "hour", "hours"), \
        minute, plural_singular(minute, "minute", "minutes"), second, plural_singular(second, "second", "seconds"));
        return string;
    }
    if(hour != -1 && (second / seconds_in_hour))
    {
        year = 0, month = 0, week = 0, day = 0; convert_seconds(hour); convert_seconds(minute);
        format(string, sizeof(string), "%d %s, %d %s, and %d %s", hour, plural_singular(hour, "hour", "hours"), minute, plural_singular(minute, "minute", "minutes"), \
        second, plural_singular(second, "second", "seconds"));
        return string;
    }
    if(minute != -1 && (second / seconds_in_minute))
    {
        year = 0, month = 0, week = 0, day = 0, hour = 0; convert_seconds(minute);
        format(string, sizeof(string), "%d %s, and %d %s", minute, plural_singular(minute, "minute", "minutes"), second, plural_singular(second, "second", "seconds"));
        return string;
    }

    year = 0, month = 0, week = 0, day = 0, hour = 0, minute = 0;
    format(string, sizeof(string), "%d %s", second, plural_singular(second, "second", "seconds"));
    return string;
}
If everything is super dully dew, then make it do what is suppose to do in play.

I personally would do it like this. Less hassle when alternating someone's time left. Like extend a member's time left from 30 days to 60 days as they purchased another week in advance. You could either alter it straight via the database's content or with a custom command, I find it to be very useful for such matters. But, do as you wish.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)