How to calculate time?
#1

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"
Reply
#2

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
Reply
#3

Solved, thanks!
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)