VIP days, looking for code check & explanation
#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


Messages In This Thread

Forum Jump:


Users browsing this thread: 1 Guest(s)