Loop and dialog response
#1

So..
I'm having stadiums IDs 1, 2, 3 and 5. ID 4 is missing but that's ok.

pawn Код:
CMD:stadiums(playerid, params[])
{
    new StadiumList[500];
    for (new StadiumID = 1; StadiumID < MAX_STADIUMS; StadiumID++)
    {
        if (AStadium[StadiumID][PickupID] != 0) format(StadiumList, sizeof(StadiumList), "%s%s stadium\n", StadiumList, AStadium[StadiumID][StadiumLocation]);
    }
    ShowPlayerDialog(playerid, 1, DIALOG_STYLE_LIST, "List:", StadiumList, "OK", "Cancel");
    return 1;
}

OnDialogResponse(..
{
    new String[128];
    if (!response) return 1;
    new StadiumLocalID = listitem + 1;
    format(String, sizeof(String), "You're next to %s stadium", AStadium[StadiumLocalID][StadiumLocation]);
    SendClientMessage(playerid, -1, String);
    return 1;
}
When I enter /stadiums it shows a dialog type listitem with all existing stadiums, like:
Код:
ID 1
ID 2
ID 3
ID 5
When I click on IDs 1, 2 and 3 it's shows the correct stadium ID, but when I choose 5 it returns ID 4 which doesn't exist.
Код:
new StadiumLocalID = listitem + 1;
Does anyone have any idea how to make it?
Reply
#2

Код:
if(listitem+1 == 4) new StadiumLocalID = listitem + 2;
else new StadiumLocalID = listitem + 1;
Reply
#3

Apply the same logic in dialog response.
pawn Код:
new counter;

for (new StadiumID = 1; StadiumID < MAX_STADIUMS; StadiumID++)
{
    if (AStadium[StadiumID][PickupID] != 0)
    {
        if (counter++ == listitem)
        {
            format(String, sizeof(String), "You're next to %s stadium", AStadium[StadiumID][StadiumLocation]);
            SendClientMessage(..);

            break;
        }
    }
}
For your information, array indexes start from 0.
Reply
#4

Quote:
Originally Posted by None1337
Посмотреть сообщение
Код:
if(listitem+1 == 4) new StadiumLocalID = listitem + 2;
else new StadiumLocalID = listitem + 1;
That is fucking stupid to do. You could just use sscanf() to get the id from the list text.
Reply
#5

This is a bad examples but I think that problem is here
PHP код:
if (AStadium[StadiumID][PickupID] != 0
probably pickup is not created or PickupID is 0.
change it with -1 like this:
AStadium[StadiumID][PickupID] != -1
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)