timestamp. remaining days.
#1

I have create a temporary VIP system. But I want to create a command that shows the number of days left in vip expiry.
I did " gettime() + 86400 " = 1 month

Here's the command

pawn Код:
COMMAND:viptime(playerid, params[])
{
    new diff_secs = ( GetPVarInt(playerid, "VIPTime") - gettime() );
    new remain_days = floatround( diff_secs / 60 * 60 * 24);
   
    new estring[128];
    format(estring, 128, "%d days remaining in your VIP Expiry.", remain_days);
    SendClientMessage(playerid, -1, estring);
    return 1;
}
this command need some fixes to get the exact days left in vip expiry.
Can you help ?
Reply
#2

There's a few threads for temporary VIP, check them out in the tutorials section.

If there's no fix then reply to the topic stating so.
Reply
#3

it looks alright it will give it right

try changing this line
new remain_days = floatround( diff_secs / 60 * 60 * 24);
to this
new remain_days = floatround( diff_secs / (60 * 60 * 24));
Reply
#4

it is returning something like this :
0 days remaining in your VIP Expiry.

please check this code again

pawn Код:
COMMAND:viptime(playerid, params[])
{
    if(GetPVarInt(playerid, "VIP") == 1)
    {
        new diff_secs = ( GetPVarInt(playerid, "VIPTime") - gettime() );
        new remain_days = floatround( diff_secs / (60 * 60 * 24 * 30));

        new estring[128];
        format(estring, 128, "%d days remaining in your VIP Expiry.", remain_days);
        SendClientMessage(playerid, -1, estring);
    }
    return 1;
}
Reply
#5

Well the truth is you don't need to round the result since it is an integer operation
pawn Код:
new remain_days = (diff_secs / (60 * 60 * 24));
And a month is 60 * 60 * 24 * 30 = 2592000
Reply
#6

bro, check in my above reply. I fixed it. but still showing 0 days
When i check my MySQL db. The timestamp is stored in it.
Reply
#7

Quote:
Originally Posted by Champ
Посмотреть сообщение
bro, check in my above reply. I fixed it. but still showing 0 days
When i check my MySQL db. The timestamp is stored in it.
Just print out everything and you should know how much time is left, if it is still (with this code) under one day you probably made a mistake while setting "VIPTime"
pawn Код:
COMMAND:viptime(playerid, params[])
{
    if(GetPVarInt(playerid, "VIP") == 1)
    {
        new diff_secs = ( GetPVarInt(playerid, "VIPTime") - gettime() );
        new remain_months = ( diff_secs / (60 * 60 * 24 * 30) );
        diff_secs -= remain_months * 60 * 60 * 24 * 30;
        new remain_days = ( diff_secs / (60 * 60 * 24) );
        diff_secs -= remain_days * 60 * 60 * 24;
        new remain_hours = ( diff_secs / (60 * 60) );
        diff_secs -= remain_hours * 60 * 60;
        new remain_minutes = ( diff_secs / 60 );
        diff_secs -= remain_minutes * 60;

        new estring[128];
        format(estring, 128, "%d months / %d days / %d hours / %d minutes / %d seconds.", remain_months, remain_days, remain_hours, remain_minutes, diff_secs);
        SendClientMessage(playerid, -1, estring);
    }
    return 1;
}
Either way I don't see why you use two variables for VIP and use PVars if the data is already stored outside
Reply
#8

thank you
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)