SA-MP Forums Archive
timestamp. remaining days. - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: timestamp. remaining days. (/showthread.php?tid=523514)



timestamp. remaining days. - Champ - 02.07.2014

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 ?


Re: timestamp. remaining days. - sammp - 02.07.2014

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.


Re: timestamp. remaining days. - BroZeus - 02.07.2014

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));


Re: timestamp. remaining days. - Champ - 02.07.2014

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;
}



AW: Re: timestamp. remaining days. - Nero_3D - 02.07.2014

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


Re: timestamp. remaining days. - Champ - 02.07.2014

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.


AW: Re: timestamp. remaining days. - Nero_3D - 02.07.2014

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


Re: timestamp. remaining days. - Champ - 03.07.2014

thank you