[Tutorial] How to make dynamic dialog-based tutorial system
#1

Introduction
In this tutorial, I will show you how to make dynamic dialog-based tutorial system.









What is it?

It's a message box dialog, which title and content updates dynamically through the usage of arrays. It consists of two buttons which is Next and Previous.











Why it's needed?

It's needed for time consuming and code optimization.















So, let's get started now. Please note that I'll be explaining most of the things in comments if I haven't did on normal text. First of all, put this on top of your script(usually the place where you write the constants).

pawn Код:
#define DIALOG_TUTORIALS (5) // Yes, only 1 dialog. Also make sure the dialog id(which is 5 in this case) is unique.
As you can see that I've wrote only 1 dialog because it will be updated dynamically. Now, go to the place where you declare your variables and put this under your variables.

pawn Код:
enum tInfo // Creating an enumerator for the array to differentiate between the title(title of the dialog) and the content(the content of the dialog).
{
    title[64], // Title - 64 Characters MAX
    content[256] // Content - 256 Characters MAX
}

new tData[][tInfo] = // Creating a 2-D array for our dialog. The first cell is the number of tutorials, the second is the title & content which has been declared earlier on the enumerator.
{
    // {title[], content[]} -- The first parameter is the title of the dialog. The second is the main content. Also make sure not to put comma not the last one.
    {"Job", "This is a job which is very unique than any other job ;)"},
    {"Skills", "Sometimes skills matter when quality does not there"},
    {"Manager", "Loren Ipsum is sometimes a good text generator but me is very good."}
};

new tutorialindex[MAX_PLAYERS]; //It will control the number of tutorial that should shown the player.
As I mentioned earlier, that the comments will explain you everything you need to know. Now, what we are going to do is to show the dialog. So, put this anywhere you like which will show the tutorials dialog to the player.

pawn Код:
tutorialindex[playerid] = 0; // Resetting the variable which controls the tutorial index.
ShowPlayerDialog(playerid, DIALOG_TUTORIALS, DIALOG_STYLE_MSGBOX, tData[0][title], tData[0][content], "Previous", "Next"); // Show the dialog of the first tutorial with 2 buttons in message box style.
The tutorialindex variable is used to determine which tutorial to be shown to the player with the help of player addressing. Now go to the OnDialogResponse callback and inside the block put this code.

pawn Код:
switch(dialogid) // Switching the dialogid
    {
        case DIALOG_TUTORIALS: // If DIALOG_TUTORIALS(which is our dialog) got responded
        {
            if(response) // If previous button has been clicked
            {
                if(tutorialindex[playerid] > 0) tutorialindex[playerid]--; // This checks if the tutorial index is greater than 0 then it will decrement the tutorial index because when previous button has been click, we want player to see the pervious tutorial.
                else tutorialindex[playerid] = 0; // If it's less than 0 then we will set the tutorial index to 0 because the value cannot be negative as it starts from 0.
                ShowPlayerDialog(playerid, DIALOG_TUTORIALS, DIALOG_STYLE_MSGBOX, tData[tutorialindex[playerid]][title], tData[tutorialindex[playerid]][content], "Previous", "Next"); // Then he will be shown the dialog with the previous tutorial as you can see on the index.
            }
            else // If next button has been clicked
            {
                if(tutorialindex[playerid] >= (sizeof(tData))-1) //This checks to see if the tutorial index is greater or equals to the maxmium number of tutorials which means that the player has finished watching all the tutorials.
                {
                    //After player finish the tutorial, the code here will run.
                }
                else //If he is not yet finish the tutorial
                {
                    tutorialindex[playerid]++; // Increase their tutorial index.
                    ShowPlayerDialog(playerid, DIALOG_TUTORIALS, DIALOG_STYLE_MSGBOX, tData[tutorialindex[playerid]][title], tData[tutorialindex[playerid]][content], "Previous", "Next"); // Then he will be shown the dialog with the next tutorial as you can see on the index.
                }
            }
        }
    }

If you have any question, please post below so I can help you.
Reply
#2

Nice tut
why there is so much space u given ? i mean [enter]'s ?
nvm good for wanna be RP server's owners
Reply
#3

Thanks, great guide.
Sincerely, Viktor.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)