20.01.2015, 13:37
I've also used this timestamp feature for a temporary ban system and wrote a few things:
You can supply this function with a given timestamp difference (to check how much time it still takes until the ban is automatically removed, and supply 4 variables in which the function returns it's calculations.
This function actually converts the amounts of seconds you supply into Days, Hours, Minutes and Seconds.
A small snippet from my current code show it in action:
It reads the unbantime from the database (the timestamp when the ban will expire), substracts the current timestamp and the result is how long the ban remains in effect (in seconds).
The function converts it into Days, Hours, Minutes and Seconds and displays the remaining bantime to the player and kicks him.
pawn Code:
// Convert Seconds to Days, Hours, Minutes and Seconds
StoDHMS(Time, &Days, &Hours, &Minutes, &Seconds)
{
// Convert the given time in seconds to days, hours, minutes and seconds
Days = Time / 86400;
Time = Time - (Days * 86400);
Hours = Time / 3600;
Time = Time - (Hours * 3600);
Minutes = Time / 60;
Seconds = Time - (Minutes * 60);
}
This function actually converts the amounts of seconds you supply into Days, Hours, Minutes and Seconds.
A small snippet from my current code show it in action:
pawn Code:
// Setup local variables
new Msg[128], UnbanTime, RemainingBanTime, Days, Hours, Minutes, Seconds;
// Check if this account is still banned
UnbanTime = cache_get_field_content_int(0, "UnbanTime", SQL_db);
if (UnbanTime > gettime())
{
// Get the remaining bantime (unbantime - current time)
RemainingBanTime = UnbanTime - gettime();
// Convert the remaining bantime to Days, Hours, Minutes and Seconds
StoDHMS(RemainingBanTime, Days, Hours, Minutes, Seconds);
// Kick the player
format(Msg, sizeof(Msg), "{FF0000}Your account is still banned for %i days, %i hours, %i minutes and %i seconds", Days, Hours, Minutes, Seconds);
Player_Kick(playerid, Msg);
// Exit the function
return 1;
}
The function converts it into Days, Hours, Minutes and Seconds and displays the remaining bantime to the player and kicks him.