SA-MP Forums Archive
How can I make this stop showing 0 minutes? /ajail - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: How can I make this stop showing 0 minutes? /ajail (/showthread.php?tid=480640)



How can I make this stop showing 0 minutes? /ajail - Dokins - 11.12.2013

pawn Код:
for(new p = 0; p < MAX_PLAYERS; p++)
    {
        if(LoggedIn[p] == 1 && IsPlayerConnected(p))
        {
            if(AdminJail[p] >= 1 && AdminJail[p] != 0)
            {
                AdminJail[p] --;
               
                format(string, sizeof(string), "You have %d minute(s) left in Admin Jail.", AdminJail[p]);
                SendClientMessage(p, COLOUR_GREY, string);

                if(AdminJail[p] == 0)
                {
                    SendClientMessage(p, COLOUR_LIGHTBLUE, "You have been released from Admin Jail");
                    MySQL_SetInteger(PlayerSQLID[p], "AdminJail", -1, "accounts");
                    AdminJail[p] = -1;
                    SetPlayerPos(p, -216.0915,972.2845,19.3201);
                    SetPlayerVirtualWorld(p, 0);
                    SetPlayerInterior(p, 0);
                    SetCameraBehindPlayer(p);//release.
                }
            }
        }
    }
This may seem like a stupid question, but when the timer reaches 0, it still sends a client message and I've no idea why. Could someone tell me what I'm doing wrong?


Re: How can I make this stop showing 0 minutes? /ajail - Tayab - 11.12.2013

How about killing the timer after SetCameraBehindPlayer(p);

KillTimer(timerid);
pawn Код:
for(new p = 0; p < MAX_PLAYERS; p++)
    {
        if(LoggedIn[p] == 1 && IsPlayerConnected(p))
        {
            if(AdminJail[p] >= 1 && AdminJail[p] != 0)
            {
                AdminJail[p] --;
               
                format(string, sizeof(string), "You have %d minute(s) left in Admin Jail.", AdminJail[p]);
                SendClientMessage(p, COLOUR_GREY, string);

                if(AdminJail[p] == 0)
                {
                    SendClientMessage(p, COLOUR_LIGHTBLUE, "You have been released from Admin Jail");
                    MySQL_SetInteger(PlayerSQLID[p], "AdminJail", -1, "accounts");
                    AdminJail[p] = -1;
                    SetPlayerPos(p, -216.0915,972.2845,19.3201);
                    SetPlayerVirtualWorld(p, 0);
                    SetPlayerInterior(p, 0);
                    SetCameraBehindPlayer(p);//release.
                    // Kill Timer over here
                }
            }
        }
    }



Re: How can I make this stop showing 0 minutes? /ajail - xVIP3Rx - 11.12.2013

it looks like it's more then a player's loop, it's for each player, so you should only skip that loop, continue does that..
pawn Код:
for(new p = 0; p < MAX_PLAYERS; p++)
    {
        if(LoggedIn[p] == 1 && IsPlayerConnected(p))
        {
            if(AdminJail[p] >= 1 && AdminJail[p] != 0)
            {
                if(AdminJail[p] == 0)
                {
                    SendClientMessage(p, COLOUR_LIGHTBLUE, "You have been released from Admin Jail");
                    MySQL_SetInteger(PlayerSQLID[p], "AdminJail", -1, "accounts");
                    AdminJail[p] = -1;
                    SetPlayerPos(p, -216.0915,972.2845,19.3201);
                    SetPlayerVirtualWorld(p, 0);
                    SetPlayerInterior(p, 0);
                    SetCameraBehindPlayer(p);//release.
                    continue;
                }
                AdminJail[p] --;

                format(string, sizeof(string), "You have %d minute(s) left in Admin Jail.", AdminJail[p]);
                SendClientMessage(p, COLOUR_GREY, string);
            }
        }
    }



Re: How can I make this stop showing 0 minutes? /ajail - Dokins - 11.12.2013

Ahh thank you.

I have another question....


in
OnGameModeInit sometimes various textdraws don't load, sometimes. Is there any reason for this? Usually they always do, sometimes they don't.


Re: How can I make this stop showing 0 minutes? /ajail - Dokins - 12.12.2013

That didn't fix it, I'm afraid.


Re: How can I make this stop showing 0 minutes? /ajail - Loot - 12.12.2013

Is this a global timer or a player timer?
P.S I'm not sure why are you checking the value twice, the first check should return true since the value is not 0, and right after you're checking again if the value is not 0.
pawn Код:
if(AdminJail[p] >= 1 && AdminJail[p] != 0)
This should be enough:
pawn Код:
if(AdminJail[p] > 0)



Re: How can I make this stop showing 0 minutes? /ajail - Dokins - 12.12.2013

Global time, I know...

Yeah that's what it originally was. It didn't work.


Re: How can I make this stop showing 0 minutes? /ajail - Loot - 12.12.2013

If none if the above helps, I'd suggest to debug in order to see what is its current value.
pawn Код:
for(new p = 0; p < MAX_PLAYERS; p++)
    {
        if(LoggedIn[p] == 1 && IsPlayerConnected(p))
        {
            if(AdminJail[p] >= 1 && AdminJail[p] != 0)
            {
                AdminJail[p] --;
               
                format(string, sizeof(string), "You have %d minute(s) left in Admin Jail.", AdminJail[p]);
                SendClientMessage(p, COLOUR_GREY, string);

                if(AdminJail[p] == 0)
                {
                    SendClientMessage(p, COLOUR_LIGHTBLUE, "You have been released from Admin Jail");
                    MySQL_SetInteger(PlayerSQLID[p], "AdminJail", -1, "accounts");
                    AdminJail[p] = -1;
                    SetPlayerPos(p, -216.0915,972.2845,19.3201);
                    SetPlayerVirtualWorld(p, 0);
                    SetPlayerInterior(p, 0);
                    SetCameraBehindPlayer(p);//release.
                }
            }
            printf("Player %d AdminJail value: %d", p, AdminJail[p]);
        }
    }



Re: How can I make this stop showing 0 minutes? /ajail - Dokins - 12.12.2013

It returned -1.


Re: How can I make this stop showing 0 minutes? /ajail - Dokins - 13.12.2013

Still unresolved.