SA-MP Forums Archive
How to calculate time? - 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: How to calculate time? (/showthread.php?tid=319546)



How to calculate time? - Luka P. - 19.02.2012

Hello! I made a ban command with duration parameter. Now, I need to check is player still banned, but I don't know how to. In "bans" table in database I made a "Banned On" DATETIME field, and "Duration" INT field, because duration is expressed in hours. So, this is a pseudocode of what I want:

Код:
Player connects
    Get "Banned On" and "Duration" field from database
    Compare "Banned On" + "Duration" with the current time < This is my problem

    If the ban didn't expire
           Ban player again for "ban evading"



Re: How to calculate time? - FuTuяe - 19.02.2012

Use unixtime for this.
pawn Код:
new dateofban = gettime();
Insert the above code into your database when the person gets banned
Also, insert the time of ban in seconds (1 day = 86400 seconds).
(I'm going to use 1 day for a example)

pawn Код:
CheckIfBanExpired(playerid) {

    //Get the unix time from your database
    //Get the amount of time being banned.
    //For this example, 1 day.
    //1 day contains 86400 seconds.

    new day = 86400;

    new timenow = gettime();
    if((dateofban + day) <= timenow) {
        //unban the player
    } else {
        //ban the player for evading as you stated.
    }
}
Goodluck


Re: How to calculate time? - Luka P. - 19.02.2012

Solved, thanks!