Timer Problem (Y_Timers)
#1

pawn Code:
task GlobalTimer[1000]()
{
    new
        string[ 128]
    ;
    foreach(Player, i)
    {
        if(pCuffTime[i] >= 1)
        {
            pCuffTime[i] --;
            printf("%i", pCuffTime[i]);
        }
        else if(pCuffTime[i] == 1)
        {
            format(string, sizeof(string), "[SERVER]"COL_WHITE": %s(%d) Has been uncuffed by our System, reason: Anti Abuse", PlayerName(i), i);
            SendClientMessageToAll(COLOR_LIGHTYELLOW, string);
            TogglePlayerControllable(i, 1);
            IsPlayerCuffed[i] = false;
            pCuffTime[i] = 0;
            SetPlayerSpecialAction(i, SPECIAL_ACTION_NONE);
            print("[pCuffTime]: pCuffTime has been executed, the player has been released");
        }
    }
    return 1;
}
The timer counts down properly, but for some reason when the timer variable reaches to 1 it should release the player but it doesn't, I've debug alot of times as you can see on the code to check if my code is right. the debug shows perfect

Debug Information
pawn Code:
[16:24:56] 19
[16:24:58] 18
[16:24:59] 17
[16:25:00] 16
[16:25:01] 15
[16:25:02] 14
[16:25:03] 13
[16:25:04] 12
[16:25:06] 11
[16:25:07] 10
[16:25:08] 9
[16:25:09] 8
[16:25:10] 7
[16:25:11] 6
[16:25:12] 5
[16:25:13] 4
[16:25:14] 3
[16:25:16] 2
[16:25:17] 1
[16:25:18] 0
The code should work but it doesn't.
Reply
#2

Change this:
pawn Code:
if(pCuffTime[i] >= 1)
to:
pawn Code:
if(pCuffTime[i] > 1)
Edit: If you want to know, when the first statement (Which contains "if") is true, and the others contain "else if", they will automatically be skipped. The ">=" was actually making the first statement true, so even if it was 1, the second part would get skipped. Hope I was clear.
Reply
#3

Quote:
Originally Posted by Dragonsaurus
View Post
Change this:
pawn Code:
if(pCuffTime[i] >= 1)
to:
pawn Code:
if(pCuffTime[i] > 1)
Edit: If you want to know, when the first statement (Which contains "if") is true, and the others contain "else if", they will automatically be skipped. The ">=" was actually making the first statement true, so even if it was 1, the second part gets skipped. Hope I was clear.
Thanks. Because I used this method before using SetTimer and it worked properly.
Reply
#4

You can use that

pawn Code:
task GlobalTimer[1000]()
{
    new
        string[ 128 ]
    ;

    foreach(Player, i)
    {
        if(pCuffTime[i] < 1) continue;

        if(--pCuffTime[i] < 1)
        {
            format(string, sizeof(string), "[SERVER]"COL_WHITE": %s(%d) Has been uncuffed by our System, reason: Anti Abuse", PlayerName(i), i);
            SendClientMessageToAll(COLOR_LIGHTYELLOW, string);
            TogglePlayerControllable(i, 1);
            IsPlayerCuffed[i] = false;
            pCuffTime[i] = 0;
            SetPlayerSpecialAction(i, SPECIAL_ACTION_NONE);
            print("[pCuffTime]: pCuffTime has been executed, the player has been released");
        }
    }
    return 1;
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)