names are repeated in a list.
#1

i am trying to create a list of top players but when there is one player connected the list shows this ↓

Код:
1. Player1
2. Player1
3. Player1
4. Player1
5. Player1
but i want it like this if there is only one player connect then it should be shown like this.

Код:
1. Player1
2. --
3. --
4. --
5. --
here is the code.

pawn Код:
new string[5][200];
            for(new i =0;i<5;++i)
            {
                new name[MAX_PLAYER_NAME];
                GetPlayerName(scoreid[i],name,sizeof(name));
                format(string[i],200,"{FFFFFF}%d. {DE1868}%s (ID %d) : {3EA63A}%d",i+1,name,scoreid[i],score[i]);
            }
            new fstring[300];
            format(fstring,300,"%s\n%s\n%s\n%s\n%s",string[0],string[1],string[2],string[3],string[4]);
I exactly want to explain that if player no connect it should show this "--" sign in the list.

hope you have understood.
Reply
#2

Yup. First of all, you need to change your scoreid array structure. Somewhere in your code you have
pawn Код:
new scoreid[5];
//change it to
new scoreid[5] = { INVALID_PLAYER_ID, ... };
Why? Because 0 is a valid user id, and that's why you get what you have currently.

Now, you don't need 5 strings with 200 char length. It's a lot of good memory gone to waste. We can simply add to single string over and over, then remove the newline sign.

pawn Код:
new fstring[256], name[MAX_PLAYER_NAME];
for(new i = 0; i < 5; ++i)
{
    if(INVALID_PLAYER_ID != scoreid[i]) {
        GetPlayerName(scoreid[i], name, sizeof(name));
        format(fstring, sizeof fstring, "%s{FFFFFF}%d. {DE1868}%s (ID %d) : {3EA63A}%d\n", fstring, i+1, name, scoreid[i], score[i]);
    } else {
        format(fstring, sizeof fstring, "%s{FFFFFF}%d. {DE1868}---\n", fstring, i+1);
    }
}
new indexLast = strlen(fstring) - 1;
strdel(fstring, indexLast - 1, indexLast);
Reply
#3



Now there is no name even not mine
Reply
#4

Any professional scripter is here ?

// sorry for double posting
Reply
#5

You change scoreid value?
Reply
#6

Use format inside the loop to add to the string.
Reply
#7

Guyz see this ↓

pawn Код:
new score[MAX_PLAYERS];
new scoreid[5] = { INVALID_PLAYER_ID, ... };

            new fstring[256], name[MAX_PLAYER_NAME];
            for(new i = 0; i < 5; ++i)
            {
                if(INVALID_PLAYER_ID != scoreid[i]) {
                    GetPlayerName(scoreid[i], name, sizeof(name));
                    format(fstring, sizeof fstring, "%s{FFFFFF}%d. {DE1868}%s (ID %d) : {3EA63A}%d\n", fstring, i+1, name, scoreid[i], score[i]);
                } else {
                    format(fstring, sizeof fstring, "%s{FFFFFF}%d. {DE1868}---\n", fstring, i+1);
                }
            }
            new indexLast = strlen(fstring) - 1;
            strdel(fstring, indexLast - 1, indexLast);
            for(new i=0;i<MAX_PLAYERS;++i)
            {
                if(IsPlayerConnected(i))
                {
                    ShowPlayerDialog(i,DIALOG_TOP,0,"Top 5",fstring,"OK","");
                }
            }
please fix this feature.
Reply
#8

revo, mp2, any one?
Reply
#9

Is anything written into scoreid anywhere in your script?
Because the code looks correctly.

Edit: for testing you could add "scoreid[0] = playerid;" in OnPlayerConnect to see if it would work. If yes, you forgot to add players into scoreid.
Reply
#10

NaS, Thank you bro. Your method works perfectly. but i have a little confusion in " scoreid[0] = playerid " the [0] is for id 0? and will it only count id 0?
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)