Loop only works for ID 0.
#1

My title says everything. My loop only works for ID 0. I've never had this before, so I thought I am going to post this.

This is one of the loops I am using:
pawn Код:
public GameEnd2()
{
    new string[128];
    format(string, sizeof(string), "Next map: {A52A2A}%s", GetMapName());
    for(new i; i < MAX_PLAYERS; i++)
    {
        TextDrawShowForPlayer(i, Textdraw0);
        TextDrawShowForPlayer(i, Textdraw1); // 1
        TextDrawShowForPlayer(i, Textdraw2); // 2
        TextDrawShowForPlayer(i, Textdraw3); // 3
        TextDrawShowForPlayer(i, Textdraw4); // 4
        TextDrawShowForPlayer(i, Textdraw5); // 5
        TextDrawShowForPlayer(i, Textdraw6);
        TextDrawShowForPlayer(i, Textdraw7);
        TextDrawShowForPlayer(i, Textdraw8);
        TextDrawShowForPlayer(i, Textdraw9);
        TextDrawShowForPlayer(i, Textdraw10);
        TextDrawShowForPlayer(i, Textdraw11);
        TextDrawShowForPlayer(i, Textdraw12);
        TextDrawShowForPlayer(i, Textdraw13);
        TextDrawShowForPlayer(i, Textdraw14);
        TextDrawShowForPlayer(i, Textdraw15);
        TextDrawShowForPlayer(i, Textdraw16);
        TextDrawShowForPlayer(i, Textdraw17);
        TextDrawShowForPlayer(i, Textdraw18);
        TextDrawShowForPlayer(i, Textdraw19);
        GameTextForPlayer(i, "~b~Game ended!~n~ ~r~Time's up", 5000, 3);
        SendClientMessageToAll(COLOR_YELLOW, string);
        SetTimerEx("SpawnThePlayer", 10000, false, "i", i);
        break;
    }
    SetTimer("NextMap", 10000, false);
    return 1;
}
It doesn't show me the textdraws if I'm ID 1 or higher. It only sends the textdraw and gametext to players with the ID 0.

(I do not have IsPlayerConnected because if there aren't players in the game, it should still end the game. I also tried IsPlayerConnected, it also failed.)
Reply
#2

remove the break; and make for(new i; i < MAX_PLAYERS; i++) this for(new i=0; i < MAX_PLAYERS; i++)

break - stop loop.
Reply
#3

Thanks, it worked.
Except the break part.

I'm using break so it won't spam the text "NextMap".
So, what should I use then instead of break; and return 1;.
Reply
#4

It wont spam the timer function. It will only execute the code between the brackets of the loop.
Though you should move the SendClientMessageToAll function out of the loop, because it will send loads of times.



pawn Код:
public GameEnd2()
{
    new string[128];
    format(string, sizeof(string), "Next map: {A52A2A}%s", GetMapName());
    for(new i=0; i < MAX_PLAYERS; i++)
    {
        TextDrawShowForPlayer(i, Textdraw0);
        TextDrawShowForPlayer(i, Textdraw1); // 1
        TextDrawShowForPlayer(i, Textdraw2); // 2
        TextDrawShowForPlayer(i, Textdraw3); // 3
        TextDrawShowForPlayer(i, Textdraw4); // 4
        TextDrawShowForPlayer(i, Textdraw5); // 5
        TextDrawShowForPlayer(i, Textdraw6);
        TextDrawShowForPlayer(i, Textdraw7);
        TextDrawShowForPlayer(i, Textdraw8);
        TextDrawShowForPlayer(i, Textdraw9);
        TextDrawShowForPlayer(i, Textdraw10);
        TextDrawShowForPlayer(i, Textdraw11);
        TextDrawShowForPlayer(i, Textdraw12);
        TextDrawShowForPlayer(i, Textdraw13);
        TextDrawShowForPlayer(i, Textdraw14);
        TextDrawShowForPlayer(i, Textdraw15);
        TextDrawShowForPlayer(i, Textdraw16);
        TextDrawShowForPlayer(i, Textdraw17);
        TextDrawShowForPlayer(i, Textdraw18);
        TextDrawShowForPlayer(i, Textdraw19);
        GameTextForPlayer(i, "~b~Game ended!~n~ ~r~Time's up", 5000, 3);
        SetTimerEx("SpawnThePlayer", 10000, false, "i", i);
    }
    SendClientMessageToAll(COLOR_YELLOW, string);
    SetTimer("NextMap", 10000, false);
    return 1;
}
Why are you using a loop anyway? Can't you just use TextDrawShowForAll and a loop in the SpawnThePlayer timer? Aswell as GameTextForAll?
Reply
#5

I didn't make this "gameend" for players, but for the server.
So it should set a timer for the server, not the players. I hope you get what I mean.

This is to end the game and switch the spawn location.

If I do not use break and return 1, it will still spam the SendClientMessageToAll, because it will spam that timer.
Reply
#6

So you're ending the game for all players? I'll refer back to my question then - why are you using a loop? You should simply use the functions that affect all players like TextDrawShowForPlayer.
Reply
#7

So you prefer me to make the timer for 'playerids'?
Reply
#8

Use SetTimer instead of SetTimerEx. Why make a timer for every player when you can have one that affects all?
Reply
#9

Ah, I replaced the SetTimerEx with SpawnPlayer(i) since it works now.

But, as I said before, If I do not use break and return 1, it will still spam the SendClientMessageToAll, because it will spam that timer.

There's an other "callback" I made which sets a timer to GameEnd2.
Reply
#10

So put the SendClientMessageToAll outside the loop!
Reply


Forum Jump:


Users browsing this thread: 3 Guest(s)