SA-MP Forums Archive
Question about dialogs - 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: Question about dialogs (/showthread.php?tid=605791)



Question about dialogs - barbarbar1 - 24.04.2016

Hey,
I am scripting furnitures system, and I would like to check what furniture did the player choose from a dialog. Since there are many furnitures, I am looking for a more effective way than doing like this:
pawn Код:
switch(listitem)
{

case 1:
{ }

case 2:
{ }
...
}
Is there any way to do it in another way than checking by case for each furniture? It's up to 15 options! I am looking for a more effective way.


Re: Question about dialogs - HuntingMan - 24.04.2016

ShowPlayerDialog(playerid, DIALOG_EX, DIALOG_STYLE_LIST, "Choose items ","1st\n2nd\n3rd\n4th","Ok","Cancel");

Quote:

if(dialogid == DIALOG_EX)
{
if(!response) return SendClientMessage(playerid,0x0498FBC8,"Selection Cancled");
if(response)
{
new string[300];
new msg[200];
if(listitem == 0)
{
//1stitem
return 1;
}
if(listitem == 1)
{
//2nd
return 1;
}
if(listitem == 2)
{
//3rd
return 1;
}
if(listitem == 3)
{
//4th
return 1;
}
}

and etc


Re: Question about dialogs - DTV - 24.04.2016

Quote:
Originally Posted by HuntingMan
Посмотреть сообщение
ShowPlayerDialog(playerid, DIALOG_EX, DIALOG_STYLE_LIST, "Choose items ","1st\n2nd\n3rd\n4th","Ok","Cancel");

pawn Код:
if(dialogid == DIALOG_EX)
{
if(!response) return SendClientMessage(playerid,0x0498FBC8,"Selection Cancled");
if(response)
{
new string[300];
new msg[200];
if(listitem == 0)
{
//1stitem
return 1;
}
if(listitem == 1)
{
//2nd
return 1;
}
if(listitem == 2)
{
//3rd
return 1;
}
if(listitem == 3)
{
//4th
return 1;
}
}
and etc
Doing it this way is less efficient than using cases. If you're looking for a way to shorten up the list, it depends on how it's coded. For example, if several of the options will lead to the same result, you can bundle it up as one with cases.

pawn Код:
switch(listitem)
{
    //Let's say listitem 0-3 will lead to the same result
    case 0..3:
    {
        //Whatever code you place in here will work for the first 3 options.
    }
}