Getting negative values when updating remaining time
#1

Hello I have repeating timer for player that updates remaining time -> Hours and Minutes.

pawn Код:
gettime(hour, minute, second);
format(time, sizeof(time), "%02d:%02d", gSettingMaintenanceInfo[MAINTENANCE_HOUR] - hour, gSettingMaintenanceInfo[MAINTENANCE_MINUTE] - minute);
//Setting string to textdraw as next
It's working, but If I enter lower minute then I get negative minute in string.

For example, if it's 18:30 and I plan maintenance for 19:20 the remaining minute will be negative number, how to fix it? Thanks
Reply
#2

Could you explain some more? like showing where this gSettingMaintenanceInfo[ is from? and what is MAINTENANCE_HOUR
Reply
#3

The time set, when server will restart is stored in these variables.
If player sets restart to 19:30 then --> MAINTENANCE_HOUR equals to 19, and MAINTENANCE_MINUTE equals to 30.
This means: Server will restart in this time.
//
And I want to update in timer (1 minute interval) remaining time in textdraw from NOW to SET time from these two variables.
Reply
#4

Okay. So you're using server's time (when you use gettime), you make your own timer for your game time which can be adjusted however you'd like. I'll show you.

Код:
new Clock;
new hour, minute, second;
Clock = SetTimer("ClockTimer", 1000, true);

forward ClockTimer();
public ClockTimer()
{
    second++;
    if(second >= 60)
    {
        minute++;
        if(minute >= 60)
        {
            hour++;
        }
    }
}
And these hour, second, minutes are the global variables, you can save time whenever you restart the server and load it again on game mode init. Use this (your own custom clock) for the your game time and set the textdraws using these variables.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)