[Tutorial] Dialog Creation
#1

Introduction & What We Need
Hey all here is a small tutorial on how to create a dialog (Those boxes where you can input information or select a list). Its my first tutorial so it may be a bit newbish, but when I started scripting I thought creating dialogs was the greatest challenge for me. For this tutorial I will be using ZCMD by Zeex for easy command processing.

Lets Get Started!
So down by the bottom of our script just like any other ZCMD command we will start it off using...

Код:
CMD:mydialogcommand(playerid, params[])
{

}
Now in our command we will add this

Код:
		ShowPlayerDialog(playerid, 1, DIALOG_STYLE_LIST, "Select a Location", "24/7\n Ammunation\n Crack Den", "Select", "Cancel");
Time to explain the ShowPlayerDialog! So obviously this function will work on playerid.
What 1 is its the ID for the dialog, don't repeat this number in any other ShowPlayerDialog which you will understand why later. We can also add names to them, which is complicating and just a pain, I prefer to use comments but if you choose to add names you have to have enumerators and defines..
Код:
enum
{
    DIALOG_NAME
}
 
#define DIALOG_NAME 1

// Then we could use the DialogID as DIALOG_NAME
This dialog is going to be a list dialog. The other types of dialogs are.. FOUND HERE.

Ok now we have our dialog type, we want to add a comment so the user knows what he is doing. For the list Dialog we can only add 1 comment, but for all the other types of dialog's we can have 2 as we don't need to define list items. Our comment is "Select A Location".

Now we are defining our list items. The \n will create a new line and start a new list item. Easy huh?

The final 2 parameters are what the buttons will say. The first button is our success button so we will name that select and the other is the opposite so we will name that cancel. Now we have our dialog command setup! But if we we're to test it, nothing would happen .
This is our code so far...

Код:
CMD:mydialogcommand(playerid, params[])
{
		ShowPlayerDialog(playerid, 1, DIALOG_STYLE_LIST, "Select a Location", "24/7\n Ammunation\n Crack Den", "Select", "Cancel");
}
To change what our dialog does we will now need to go to public OnDialogResponse section. So the first thing we need to do is make sure we are getting the select response so we will...
Код:
if(response){

}

else {
     SendClientMessage(playerid, YourColor, "You have cancelled");
}
So now we need to find out what dialog we're dealing with so lets use a switch and case system here. So we will add to the successful response.
Код:
if(response){
    switch(dialogid) //Switching to check for dialog id's
    {
      case 1: //This is our dialog ID for our List Item
      {
         switch(listitem) // We will now be looking at list items
         {
            case 0: // This is the first list item, the 24/7
            {

                  SendClientMessage(playerid, YourColor, "You have now teleported to the 24/7"); 
                  SetPlayerPos(playerid, -25.884498,-185.868988,1003.546875);
                  SetPlayerInterior(playerid, 17);

            }
            case 1: // This is the second list item, the Ammunation
            {

                  SendClientMessage(playerid, YourColor, "You have now teleported to the Ammunation"); 
                  SetPlayerPos(playerid, 286.148986,-40.644397,1001.515625);
                  SetPlayerInterior(playerid, 1);

            }
            case 2: // This is the final list item, the CrackDen
            {

                  SendClientMessage(playerid, YourColor, "You have now teleported to the Crack Den"); 
                  SetPlayerPos(playerid, 318.564971,1118.209960,1083.88281);
                  SetPlayerInterior(playerid, 5);

            }


         }
      }
    }
}
Conclusion
Congratulations, if you made it this far you now have a working dialog. Feel free to experiment with your creations. Sorry if I may have made a mistake, please post some constructive criticism as a reply. This is my first tutorial and I barely know that much about scripting. This is the final mish mash of all we have just scripted..
Код:
public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
if(response){
    switch(dialogid) //Switching to check for dialog id's
    {
      case 1: //This is our dialog ID for our List Item
      {
         switch(listitem) // We will now be looking at list items
         {
            case 0: // This is the first list item, the 24/7
            {

                  SendClientMessage(playerid, YourColor, "You have now teleported to the 24/7"); 
                  SetPlayerPos(playerid, -25.884498,-185.868988,1003.546875);
                  SetPlayerInterior(playerid, 17);

            }
            case 1: // This is the second list item, the Ammunation
            {

                  SendClientMessage(playerid, YourColor, "You have now teleported to the Ammunation"); 
                  SetPlayerPos(playerid, 286.148986,-40.644397,1001.515625);
                  SetPlayerInterior(playerid, 1);

            }
            case 2: // This is the final list item, the CrackDen
            {

                  SendClientMessage(playerid, YourColor, "You have now teleported to the Crack Den"); 
                  SetPlayerPos(playerid, 318.564971,1118.209960,1083.88281);
                  SetPlayerInterior(playerid, 5);

            }


         }
      }
    }
}

else {
     SendClientMessage(playerid, YourColor, "You have cancelled");
}
}

/ZCMD Commands

CMD:mydialogcommand(playerid, params[])
{
		ShowPlayerDialog(playerid, 1, DIALOG_STYLE_LIST, "Select a Location", "24/7\n Ammunation\n Crack Den", "Select", "Cancel");
}
Thank You, kay bye.
Reply


Messages In This Thread
Dialog Creation - by Dr. Dre - 21.09.2012, 06:11
Re: Dialog Creation - by Glint - 21.09.2012, 06:20
Re: Dialog Creation - by TaLhA XIV - 21.09.2012, 06:28
Re: Dialog Creation - by Dr. Dre - 21.09.2012, 13:06
Re: Dialog Creation - by superrobot48 - 08.05.2013, 09:59

Forum Jump:


Users browsing this thread: 1 Guest(s)