Wanted list wont work
#1

I have made a wanted list for my server and it wont work as I want it to, it doesn't loop through all the wanted players and list them;
pawn Код:
CMD:wanted(playerid, params[])
{
    if(pTeam[playerid] == 7) {
        for(new i = 0; i < MAX_PLAYERS; i++) {
            if(GetPlayerWantedLevel(i) > 0) {
                new string[128];
                format(string, sizeof(string), "{E60000}%s {FFFFFF}(Wanted Level: {E60000}%d{FFFFFF})\n", Name(i), GetPlayerWantedLevel(i));
                ShowPlayerDialog(playerid, DIALOG_WANTED, DIALOG_STYLE_LIST, "SASP - Wanted List", string, "Done", "");
            }
        }
    }
    else {
        SendClientMessage(playerid, COLOR_VIOLET, "INFO: {FFFFFF}You're not in the SASP.");
    }
    return 1;
}
It only returns one player who is wanted.
Reply
#2

pawn Код:
CMD:wanted(playerid, params[])
{
    if(pTeam[playerid] == 7)
    {
        for(new i = 0; i < MAX_PLAYERS; i++)
        {
            new string[400];//we will create a little big string coz 128 is too small, also we will make it outside loop because we don't
            // wait it to new emprty string is created MAX_PLAYER times
            if(GetPlayerWantedLevel(i) > 0)
            {
                format(string, sizeof(string), "%s{E60000}%s {FFFFFF}(Wanted Level: {E60000}%d{FFFFFF})\n", string,Name(i), GetPlayerWantedLevel(i)); //we add old string into new string
            }
        }
        ShowPlayerDialog(playerid, DIALOG_WANTED, DIALOG_STYLE_LIST, "SASP - Wanted List", string, "Done", ""); //we also show him dialog after loop is done. Your code would show him around
        //15 dialogs at same same so he would see only last one.
    }
    else
    {
        SendClientMessage(playerid, COLOR_VIOLET, "INFO: {FFFFFF}You're not in the SASP.");
    }
    return 1;
}
Follow comments in script.
Reply
#3

The problem is you're showing the dialog in the for loop, so of course its just going to show one player.. you need to form the string (the list of wanted players) inside the loop, then show the dialog outside of it.
Reply
#4

Try using strcat with a large string, and then showing the dialog after the loop.
Reply
#5

If you indented with a style that was actually readable, you'd realise your mistake. Just a tip.

pawn Код:
CMD:wanted(playerid, params[])
{
    if(pTeam[playerid] != 7) return SendClientMessage(playerid, COLOR_VIOLET, "INFO: {FFFFFF}You're not in the SASP.");
    new dstring[500]; // Work out what size you need
    for(new i = 0; i < MAX_PLAYERS; i++)
    {
        if(!GetPlayerWantedLevel(i)) continue;
        format(dstring, sizeof(dstring), "%s{E60000}%s {FFFFFF}(Wanted Level: {E60000}%d{FFFFFF})\n", dstring, Name(i), GetPlayerWantedLevel(i));
    }
    ShowPlayerDialog(playerid, DIALOG_WANTED, DIALOG_STYLE_LIST, "SASP - Wanted List", dstring, "Done", "");
    return 1;
}
Reply
#6

Try using strcat, it works well.
Reply
#7

Using strcat would be stupid, because he has to FORMAT the string. Why use format then strcat when only format is needed..?
Reply
#8

Formating it will only return 1 player( if there is one or more wanted players ), since when you format it replaces the old string, as far i know.

EDIT: maybe this can work?
pawn Код:
CMD:wanted(playerid, params[])
{
    if(pTeam[playerid] == 7)
    {
        for(new i = 0; i < MAX_PLAYERS; i++)
        {
            new szString[128], szResult[512];
            if(GetPlayerWantedLevel(i) > 0)
            {
                format( szString, 128, "%s{E60000}%s {FFFFFF}(Wanted Level: {E60000}%d{FFFFFF})\n", string,Name(i), GetPlayerWantedLevel(i));
                strcat( szResult, szString, 512 );
            }
        }
       
        ShowPlayerDialog(playerid, DIALOG_WANTED, DIALOG_STYLE_LIST, "SASP - Wanted List", szResult, "Done", "");
    }
    else
        return SendClientMessage(playerid, COLOR_VIOLET, "INFO: {FFFFFF}You're not in the SASP.");
    return 1;
}
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)