Wanted level in dialog
#1

Hey guys,

I wanna know how to show all the names in a list (dialog in this case), like this:
Код:
Name 1 (wanted level)
Name 2 (wanted level)
Name 3 (wanted level)
Name 39393938272717119 (wanted level)
I dont really got a clue, but i made a little snippet, which should work, but wont show the names in the dialog (i think).
pawn Код:
COMMAND:checkwanted(playerid, params[])
{
    new dialog[256], name[24];
    for( new i = 0; i < MAX_PLAYERS; i ++ )
    {
        if( GetPlayerWantedLevel( i ) >= 2 )
        {
            GetPlayerName( i, name, 24);
            format( dialog, sizeof dialog, "%s (%i)", name, GetPlayerWantedLevel( i ) );
        }
    }
    ShowPlayerDialog( playerid, 1, DIALOG_STYLE_LIST, "Wanted levels", dialog, "Ok", "");
    return 1;
}
~Wesley
Reply
#2

You'll have to create a secondary string to strcat to the dialog. Otherwise the dialog string would be overwritten at every loop course.
Reply
#3

pawn Код:
COMMAND:checkwanted(playerid, params[])
{
    new dialog[256], string[40], name[24];
    format(dialog, sizeof(dialog), "");
    for( new i = 0; i < MAX_PLAYERS; i ++ )
    {
        if( GetPlayerWantedLevel( i ) >= 2 )
        {
            GetPlayerName( i, name, 24);
            format( string, sizeof (string), "%s (%i)", name, GetPlayerWantedLevel( i ) );
            format(dialog, sizeof(dialog), "%s\n%s", dialog, string);
        }
    }
    ShowPlayerDialog( playerid, 1, DIALOG_STYLE_LIST, "Wanted levels", dialog, "Ok", "");
    return 1;
}
Reply
#4

There's actually no need for a second string ! Waste of memory.
Something like this should do the trick (checks if a player has any wanted level):

pawn Код:
COMMAND:checkwanted(playerid, params[])
{
    new dialog[256], name[MAX_PLAYER_NAME];
   
    foreach(Player, i)
    {
        if(GetPlayerWantedLevel(i) > 0)
        {
            GetPlayerName(i, name, MAX_PLAYER_NAME);
            format(dialog, sizeof dialog, "%s%s (%i)", dialog, name, GetPlayerWantedLevel(i));
        }
    }
    ShowPlayerDialog(playerid, 1, DIALOG_STYLE_LIST, "Wanted levels", dialog, "Ok", "");
    return 1;
}
Reply
#5

Quote:
Originally Posted by Luнs Miki
Посмотреть сообщение
You'll have to create a secondary string to strcat to the dialog. Otherwise the dialog string would be overwritten at every loop course.
Thanks i will use this, good thinking PlayerInfo[Luнs Miki][pReputation]++;

I dont mind an extra variable which uses a little bit of memory.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)