Loop and dialog response - Printable Version
+- SA-MP Forums Archive (
https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (
https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (
https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Loop and dialog response (
/showthread.php?tid=663774)
Loop and dialog response -
PPC23 - 10.02.2019
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:
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?
Re: Loop and dialog response -
None1337 - 10.02.2019
Код:
if(listitem+1 == 4) new StadiumLocalID = listitem + 2;
else new StadiumLocalID = listitem + 1;
Re: Loop and dialog response -
Calisthenics - 10.02.2019
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.
Re: Loop and dialog response -
Pottus - 10.02.2019
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.
Re: Loop and dialog response -
Mugala - 10.02.2019
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