Loops + Textdraws
#1

When a round starts, 2 TDs are created for each player in the (ATT & DEF) teams. I want to show every player from both teams the created textdraws, but it's only showing the textdraws on your screen. It should show every created textdraw in every player's screen ( Not only yours ).

pawn Код:
foreach(Player, i)
    {
        if(PVar[i][InRound] && PVar[i][Team] != T_BUM && PVar[i][Team] != T_AWAY && PVar[i][Team] != SUB_ATT && PVar[i][Team] != SUB_DEF)
        {
            if(PVar[i][Team] == T_ATT)
            {
                Line[i] = TextDrawCreate(566.00, AttStartY, "_");
                Name[i] = TextDrawCreate(561.00, AttNameStartY, "_");

                format(AttNameStr, sizeof(AttNameStr), "~r~%s", pName(i));
                TextDrawSetString(Name[i], AttNameStr);

                AttStartY += 6.40;
                AttNameStartY += 6.40;

                //TextDrawShowForPlayer(i, Name[i]);
            }
            else if(PVar[i][Team] == T_DEF)
            {
                Line[i] = TextDrawCreate(5.00, DefStartY, "_");
                Name[i] = TextDrawCreate(74.00, DefNameStartY, "_");

                format(DefNameStr, sizeof(DefNameStr), "~r~%s", pName(i));
                TextDrawSetString(Name[i], DefNameStr);

                DefStartY += 6.40;
                DefNameStartY += 6.40;

                //TextDrawShowForPlayer(i, Name[i]);
            }
            TextDrawShowForPlayer(i, Name[i]);
        }
    }
I'm pretty sure I must do another loop or something. I tried a lot of diff ways to get it working, its always showing only your textdraws on your screen!
Reply
#2

If you are wanting to show textdraws for every player, then just use TextDrawShowForAll.
Reply
#3

^ What he said.
Reply
#4

I don't think so at TheKiller and John Cooper's post, because
pawn Код:
if(PVar[i][InRound] && PVar[i][Team] != T_BUM && PVar[i][Team] != T_AWAY && PVar[i][Team] != SUB_ATT && PVar[i][Team] != SUB_DEF)

if(PVar[i][Team] == T_ATT)

else if(PVar[i][Team] == T_DEF)
What about showing it's textdraw first before setting the string?
Reply
#5

Quote:
Originally Posted by Basicz
Посмотреть сообщение
I don't think so at TheKiller and John Cooper's post, because
pawn Код:
if(PVar[i][InRound] && PVar[i][Team] != T_BUM && PVar[i][Team] != T_AWAY && PVar[i][Team] != SUB_ATT && PVar[i][Team] != SUB_DEF)

if(PVar[i][Team] == T_ATT)

else if(PVar[i][Team] == T_DEF)
What about showing it's textdraw first before setting the string?
That would make no difference. The reason why it is only showing the player the textdraw is how the loop is structured. You either need a loop inside a loop or use TextDrawShowForAll. This is why below:

pawn Код:
foreach(Player, i) //This loops through all players
    {
        if(PVar[i][InRound] && PVar[i][Team] != T_BUM && PVar[i][Team] != T_AWAY && PVar[i][Team] != SUB_ATT && PVar[i][Team] != SUB_DEF) //This part doesn't really matter, just checks if the player is in teams
        {
            if(PVar[i][Team] == T_ATT)
            {
                Line[i] = TextDrawCreate(566.00, AttStartY, "_"); //This creates the players textdraw
                Name[i] = TextDrawCreate(561.00, AttNameStartY, "_"); //This creates the players second td

                format(AttNameStr, sizeof(AttNameStr), "~r~%s", pName(i));
                TextDrawSetString(Name[i], AttNameStr);

                AttStartY += 6.40;
                AttNameStartY += 6.40;

                //TextDrawShowForPlayer(i, Name[i]);
            }
            else if(PVar[i][Team] == T_DEF)
            {
                Line[i] = TextDrawCreate(5.00, DefStartY, "_");
                Name[i] = TextDrawCreate(74.00, DefNameStartY, "_");

                format(DefNameStr, sizeof(DefNameStr), "~r~%s", pName(i));
                TextDrawSetString(Name[i], DefNameStr);

                DefStartY += 6.40;
                DefNameStartY += 6.40;

                //TextDrawShowForPlayer(i, Name[i]);
            }
            TextDrawShowForPlayer(i, Name[i]); //Here it only shows the textdraw for the player that we are currently on.
        }
    }
See, you need to have a loop after you created the textdraw or just use TextDrawShowForAll.
Reply
#6

Not to everyone, just the players from team ATT & DEF. I once manage to make it using another loop, and I also debugged it, and found out that the text was being shown "x amount of times per player". So if there were 4 players that I wanted to show the TDs, the TDs would show 4 times. A mistake of mine ( Wrong location to place the loop ).
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)