how can i use and check date timers on pawn?
# support-forum
c
how can i use and check date timers on pawn? what should i do to put this code to work:
Copy code
c++
CMD:atmrob(playerid) {
    if(AtmInfo[atmid][atmRobExausted] ???) {
        format(string, sizeof(string), "This ATM is blocked to rob until: 07:33:00");
        SendClientMessage(playerid, COLOR_LIGHTRED, string);
        return 1;
    }
    AtmInfo[atmid][atmRobExausted] = ???;
}
g
i think its better to use gettime/getdate
cuz it works with date/hour
use pawn-chrono
c
how to use gettime/getdate to to this?
do i need a external lib for this?
how can i print how many minutes and seconds left to use it again?
Copy code
new timeExaustedSecs = 10 * 60 * 1000;
    if(tickcount() - gPlayerAllowedTick[playerid] > timeExaustedSecs)
    {
        SendClientMessage(playerid, -1, "Works!");
        gPlayerAllowedTick[playerid] = tickcount(); // Update the tick count with the latest time.
    }
    else
    {
        new str[128];
        format(str, sizeof(str), "You can only use this command in 5 minutes and 12 seconds");
        SendClientMessage(playerid, -1, str);
    }
g
use what edgyaf sent
its easier than what i thought
c
did u know how to finish that
format(str, sizeof(str), "You can only use this command in 5 minutes and 12 seconds");
part?
g
no
but u can do the timeExaustedSecs with gettime
and use a function to return unix timestamp to hours/date
s
gettime() returns the current unix time stamp. If you have the difference between two points in time you can easily convert that to hours, minutes, seconds with division and modulo. For example
Copy code
minutes = difference_in_seconds / 60;
and
Copy code
seconds = difference_in_seconds % 60;
g
i have a function that does it to me and i do not need create the vars. i'd just do like: format(str, sizeof(str), "You can only use this command in %s", returnDate(timeExaustedSecs);
and the function is this one:
Copy code
c
returnDate( timestamp, _form=0 )
{
    new year=1970, day=0, month=0, hourt=0, mins=0, sec=0;

    new days_of_month[12] = { 31,28,31,30,31,30,31,31,30,31,30,31 };
    new names_of_month[12][10] = {"January","February","March","April","May","June","July","August","September","October","November","December"};
    new returnstring[32];

    while(timestamp>31622400){
        timestamp -= 31536000;
        if ( ((year % 4 == 0) && (year % 100 != 0)) || (year % 400 == 0) ) timestamp -= 86400;
        year++;
    }

    if ( ((year % 4 == 0) && (year % 100 != 0)) || (year % 400 == 0) )
        days_of_month[1] = 29;
    else
        days_of_month[1] = 28;


    while(timestamp>86400){
        timestamp -= 86400, day++;
        if(day==days_of_month[month]) day=0, month++;
    }

    while(timestamp>60){
        timestamp -= 60, mins++;
        if( mins == 60) mins=0, hourt++;
    }

    sec=timestamp;

    switch( _form ){
        case 1: format(returnstring, 31, "%02d/%02d/%d %02d:%02d:%02d", day+1, month+1, year, hourt, mins, sec);
        case 2: format(returnstring, 31, "%s %02d, %d, %02d:%02d:%02d", names_of_month[month],day+1,year, hourt, mins, sec);
        case 3: format(returnstring, 31, "%d %c%c%c %d, %02d:%02d", day+1,names_of_month[month][0],names_of_month[month][1],names_of_month[month][2], year,hourt,mins);
        case 4: format(returnstring, 31, "%s %02d, %d", names_of_month[month],day+1,year);
        default: format(returnstring, 31, "%02d/%02d/%d %02d:%02d:%02d", day+1, month+1, year, hourt, mins, sec);
    }

    return returnstring;
}
or u can use pawn-chrono, idk.