SA-MP Forums Archive
[Tutorial] How to create a simple RP quiz (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)
+---- Forum: Tutorials (https://sampforum.blast.hk/forumdisplay.php?fid=70)
+---- Thread: [Tutorial] How to create a simple RP quiz (Dialogs) (/showthread.php?tid=283920)

Pages: 1 2


How to create a simple RP quiz (Dialogs) - Jafet_Macario - 17.09.2011

How to create a simple RP quiz (Dialogs)


Introduction


In this tutorial I'll show you how to create a simple role play quiz with dialogs.


Step 1

Let's define some dialog id's at the top of the script:
pawn Code:
#define DIALOG_QUIZ 5550
#define DIALOG_QUIZ1 5551
#define DIALOG_QUIZ2 5552
#define DIALOG_QUIZ3 5553
#define DIALOG_QUIZ4 5554
Step 2

Let's declare a new variable, so if the player have 3 wrong answers, he will get kicked.
pawn Code:
new QuizAnswers[MAX_PLAYERS];
Step 3

So, if you have a registration/login system, add the next code after the player registers/login (or how you wish), or you can add it at one of your command, you decide when the role play quiz will start.
pawn Code:
ShowPlayerDialog(playerid,DIALOG_QUIZ,DIALOG_STYLE_LIST,"What does RP stands for?"," Real Pussy \n Role Play \n Real Money","Select","Leave Game");
// It will show him the first question from the quiz, he have to choose from those 3 answers
I'll just put it at OnPlayerConnect callback, so when he will connect to your server he will get the quiz.
pawn Code:
public OnPlayerConnect(playerid)
{
        SendClientMessage(playerid, -1,"You will have to pass through a quiz"); // Added -1 color as default.
        ShowPlayerDialog(playerid,DIALOG_QUIZ,DIALOG_STYLE_LIST,"What does RP stands for?"," Real Pussy \n Role Play \n Real Money","Select","Leave Game");
        QuizAnswers[playerid] = 0; // We set the player quiz answers to 0 when he connects.
        return 1;
}
Step 4

Let's scroll down to OnDialogResponse callback.
pawn Code:
public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
    if(dialogid == DIALOG_QUIZ) // If first dialog shows up
    {
        if(!response) return Kick(playerid); // If he click "Leave Game" he will be kicked.
        if(response) // If he click first button
        {
            if(listitem == 0) // If he choose first answer, wich is: Real Pussy
            {
                SendClientMessage(playerid, -1,"Wrong answer!"); // He will get a message that he answered wrong
                QuizAnswers[playerid] += 1; // His quiz answers will be increased with 1 point.
                ShowPlayerDialog(playerid,DIALOG_QUIZ1,DIALOG_STYLE_LIST,"It is LOL a frequently used word in role play server?"," Yes \n No, it's a NON-RP word \n LOL I like this word!","Select","Leave Game")
                // Second question will show up
            }
            if(listitem == 1) // If he choose 2nd answers, which is: Role Play (correct one)
            {
                SendClientMessage(playerid, -1,"That's the correct answer"); // He will get a message that he answered correct
                ShowPlayerDialog(playerid,DIALOG_QUIZ1,DIALOG_STYLE_LIST,"It is LOL a frequently used word in role play server?"," Yes \n No, it's a NON-RP word \n LOL I like this word!","Select","Leave Game")
                // Second question will show up
            }
            if(listitem == 2)
            {
                SendClientMessage(playerid, -1,"Wrong answer!"); // He will get a message that he answered wrong
                QuizAnswers[playerid] += 1; // His quiz answers will be increased with 1 point.
                ShowPlayerDialog(playerid,DIALOG_QUIZ1,DIALOG_STYLE_LIST,"It is LOL a frequently used word in role play server?"," Yes \n No, it's a NON-RP word \n LOL I like this word!","Select","Leave Game")
                // Second question will show up
            }
        }
    }
    if(dialogid == DIALOG_QUIZ1) // If second dialog shows up
    {
        if(!response) return Kick(playerid); // If he press second button he get kicked
        if(response) // If he press first button
        {
            if(listitem == 0) // If he choose first answer wich is: Yes
            {
                SendClientMessage(playerid, -1,"Wrong answer!"); // He will get a message that he answered wrong
                QuizAnswers[playerid] += 1; // His quiz answers will be increased with 1 point.
                ShowPlayerDialog(playerid, DIALOG_QUIZ2, DIALOG_STYLE_LIST,"Which /me is used correct?"," /me laughs \n /me rofl \n /me wtf","Select","Leave Game");
                // Next dialog will show up
            }
            if(listitem == 1) // If he choose first answer wich is: No, it's a NON-RP word (correct one)
            {
                SendClientMessage(playerid, -1,"That's the correct answer"); // He will get a message that he answered correct
                ShowPlayerDialog(playerid, DIALOG_QUIZ2, DIALOG_STYLE_LIST,"Which /me is used correct?"," /me laughs \n /me rofl \n /me wtf","Select","Leave Game");
                // Next dialog will show up
            }
            if(listitem == 2)
            {
                SendClientMessage(playerid, -1,"Wrong answer!"); // He will get a message that he answered wrong
                QuizAnswers[playerid] += 1; // His quiz answers will be increased with 1 point.
                ShowPlayerDialog(playerid, DIALOG_QUIZ2, DIALOG_STYLE_LIST,"Which /me is used correct?"," /me laughs \n /me rofl \n /me wtf","Select","Leave Game");
                // Next dialog will show up
            }
        }
    }
    if(dialogid == DIALOG_QUIZ2) // If 3rd dialog shows up
    {
        if(!response) return Kick(playerid); // If he click second button he get kicked
        if(response) // If he click first button
        {
            if(listitem == 0) // If he choose first answer wich is: /me laugs (correct one)
            {
                SendClientMessage(playerid, -1,"That's the correct answer");
                ShowPlayerDialog(playerid, DIALOG_QUIZ3, DIALOG_STYLE_LIST,"What IC stands for?"," Information Centre \n In Character \n I'm Cool","Select","Leave Game");
                // Next dialog will show up
            }
            if(listitem == 1)
            {
                SendClientMessage(playerid, -1,"Wrong answer!"); // He will get a message that he answered wrong
                QuizAnswers[playerid] += 1; // His quiz answers will be increased with 1 point.
                ShowPlayerDialog(playerid, DIALOG_QUIZ3, DIALOG_STYLE_LIST,"What IC stands for?"," Information Centre \n In Character \n I'm Cool","Select","Leave Game");
                // Next dialog will show up
            }
            if(listitem == 2)
            {
                SendClientMessage(playerid, -1,"Wrong answer!"); // He will get a message that he answered wrong
                QuizAnswers[playerid] += 1; // His quiz answers will be increased with 1 point.
                ShowPlayerDialog(playerid, DIALOG_QUIZ3, DIALOG_STYLE_LIST,"What IC stands for?"," Information Centre \n In Character \n I'm Cool","Select","Leave Game");
                // Next dialog will show up
            }
            if(QuizAnswers[playerid] >= 3) // If he reached 3 wrong answers
            {
                SendClientMessage(playerid, -1,"Sorry mate, you answered 3 times wrong.Maybe another time");
                Kick(playerid); // He will be kicked
            }
        }
    }
    if(dialogid == DIALOG_QUIZ3) // If 4rd dialog shows up
    {
        if(!response) return Kick(playerid); // If he click second button he get kicked
        if(response) // If he click first button
        {
            if(listitem == 0) // If he choose first answer wich is: Information Centre
            {
                SendClientMessage(playerid, -1,"Wrong answer!"); // He will get a message that he answered wrong
                QuizAnswers[playerid] += 1; // His quiz answers will be increased with 1 point.
                ShowPlayerDialog(playerid, DIALOG_QUIZ4, DIALOG_STYLE_LIST,"What OOC stands for?"," Out of Chat \n Out of Character \n Ow ow cool","Select","Leave Game");
                // Next dialog will show up
            }
            if(listitem == 1) // If he choose first answer wich is: In Character (correct one)
            {
                SendClientMessage(playerid, -1,"That's the correct answer!");
                ShowPlayerDialog(playerid, DIALOG_QUIZ4, DIALOG_STYLE_LIST,"What OOC stands for?"," Out of Chat \n Out of Character \n Ow ow cool","Select","Leave Game");
                // Next dialog will show up
            }
            if(listitem == 2) // If he choose first answer wich is: I'm Cool
            {
                SendClientMessage(playerid, -1,"Wrong answer!"); // He will get a message that he answered wrong
                QuizAnswers[playerid] += 1; // His quiz answers will be increased with 1 point.
                ShowPlayerDialog(playerid, DIALOG_QUIZ4, DIALOG_STYLE_LIST,"What OOC stands for?"," Out of Chat \n Out of Character \n Ow ow cool","Select","Leave Game");
                // Next dialog will show up
            }
            if(QuizAnswers[playerid] >= 3) // If he reached 3 wrong answers or more
            {
                SendClientMessage(playerid, -1,"Sorry mate, you answered 3 times wrong.Maybe another time");
                Kick(playerid); // He will be kicked
            }
        }
    }
    if(dialogid == DIALOG_QUIZ4)
    {
        if(!response) return Kick(playerid); // If he click second button he get kicked
        if(response) // If he click first button
        {
            if(listitem == 0) // If he choose first answers wich is: Out of Chat
            {
                SendClientMessage(playerid, -1,"Wrong answer!"); // He will get a message that he answered wrong
                QuizAnswers[playerid] += 1; // His quiz answers will be increased with 1 point.
            }
            if(listitem == 1) // If he choose second answers wich is: Out of Character (correct one)
            {
                SendClientMessage(playerid, -1,"That's the correct answer");
            }
            if(listitem == 2) // If he choose 3rd answer wich is: Ow ow cool
            {
                SendClientMessage(playerid, -1,"Wrong answer!"); // He will get a message that he answered wrong
                QuizAnswers[playerid] += 1; // His quiz answers will be increased with 1 point.
            }
            if(QuizAnswers[playerid] >= 3) // If he reached 3 wrong answers or more
            {
                SendClientMessage(playerid, -1,"Sorry mate, you answered 3 times wrong.Maybe another time");
                Kick(playerid); // He will be kicked
            }
            else // If he didn't have at least 3 wrong answers
            {
                SendClientMessage(playerid, -1,"Congratulations, you have passed the RP quiz!");
            }
            SpawnPlayer(playerid);
            // After the quiz is finish,the player will be spawned, you can change here.
        }
    }      
    return 1;
}
If you wish to switch:
pawn Code:
public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
    switch(dialogid)
    {
        case DIALOG_QUIZ: // If first dialog shows up
        {
            if(!response) return Kick(playerid); // If he click "Leave Game" he will be kicked.
            if(response) // If he click first button
            {
                switch(listitem) // We switch the available answers
                {
                    case 0:// If he choose first answer, wich is: Real Pussy
                    {
                        SendClientMessage(playerid, -1,"Wrong answer!"); // He will get a message that he answered wrong
                        QuizAnswers[playerid] += 1; // His quiz answers will be increased with 1 point.
                        ShowPlayerDialog(playerid,DIALOG_QUIZ1,DIALOG_STYLE_LIST,"It is LOL a frequently used word in role play server?"," Yes \n No, it's a NON-RP word \n LOL I like this word!","Select","Leave Game");
                        // Second question will show up
                    }
                    case 1: // If he choose 2nd answers, which is: Role Play (correct one)
                    {
                        SendClientMessage(playerid, -1,"That's the correct answer"); // He will get a message that he answered correct
                        ShowPlayerDialog(playerid,DIALOG_QUIZ1,DIALOG_STYLE_LIST,"It is LOL a frequently used word in role play server?"," Yes \n No, it's a NON-RP word \n LOL I like this word!","Select","Leave Game");
                        // Second question will show up
                    }
                    case 2:
                    {
                        SendClientMessage(playerid, -1,"Wrong answer!"); // He will get a message that he answered wrong
                        QuizAnswers[playerid] += 1; // His quiz answers will be increased with 1 point.
                        ShowPlayerDialog(playerid,DIALOG_QUIZ1,DIALOG_STYLE_LIST,"It is LOL a frequently used word in role play server?"," Yes \n No, it's a NON-RP word \n LOL I like this word!","Select","Leave Game");
                        // Second question will show up
                    }
                }
            }
        }
        case DIALOG_QUIZ1: // If second dialog shows up
        {
            if(!response) return Kick(playerid); // If he press second button he get kicked
            if(response) // If he press first button
            {
                switch(listitem) // We switch the available answers
                {
                    case 0: // If he choose first answer wich is: Yes
                    {
                        SendClientMessage(playerid, -1,"Wrong answer!"); // He will get a message that he answered wrong
                        QuizAnswers[playerid] += 1; // His quiz answers will be increased with 1 point.
                        ShowPlayerDialog(playerid, DIALOG_QUIZ2, DIALOG_STYLE_LIST,"Which /me is used correct?"," /me laughs \n /me rofl \n /me wtf","Select","Leave Game");
                        // Next dialog will show up
                    }
                    case 1: // If he choose first answer wich is: No, it's a NON-RP word (correct one)
                    {
                        SendClientMessage(playerid, -1,"That's the correct answer"); // He will get a message that he answered correct
                        ShowPlayerDialog(playerid, DIALOG_QUIZ2, DIALOG_STYLE_LIST,"Which /me is used correct?"," /me laughs \n /me rofl \n /me wtf","Select","Leave Game");
                        // Next dialog will show up
                    }
                    case 2:
                    {
                        SendClientMessage(playerid, -1,"Wrong answer!"); // He will get a message that he answered wrong
                        QuizAnswers[playerid] += 1; // His quiz answers will be increased with 1 point.
                        ShowPlayerDialog(playerid, DIALOG_QUIZ2, DIALOG_STYLE_LIST,"Which /me is used correct?"," /me laughs \n /me rofl \n /me wtf","Select","Leave Game");
                        // Next dialog will show up
                    }
                }
            }
        }
        case DIALOG_QUIZ2: // If 3rd dialog shows up
        {
            if(!response) return Kick(playerid); // If he click second button he get kicked
            if(response) // If he click first button
            {
                switch(listitem) // We switch the available answers
                {
                    case 0: // If he choose first answer wich is: /me laugs (correct one)
                    {
                        SendClientMessage(playerid, -1,"That's the correct answer");
                        ShowPlayerDialog(playerid, DIALOG_QUIZ3, DIALOG_STYLE_LIST,"What IC stands for?"," Information Centre \n In Character \n I'm Cool","Select","Leave Game");
                        // Next dialog will show up
                    }
                    case 1:
                    {
                        SendClientMessage(playerid, -1,"Wrong answer!"); // He will get a message that he answered wrong
                        QuizAnswers[playerid] += 1; // His quiz answers will be increased with 1 point.
                        ShowPlayerDialog(playerid, DIALOG_QUIZ3, DIALOG_STYLE_LIST,"What IC stands for?"," Information Centre \n In Character \n I'm Cool","Select","Leave Game");
                        // Next dialog will show up
                    }
                    case 2:
                    {
                        SendClientMessage(playerid, -1,"Wrong answer!"); // He will get a message that he answered wrong
                        QuizAnswers[playerid] += 1; // His quiz answers will be increased with 1 point.
                        ShowPlayerDialog(playerid, DIALOG_QUIZ3, DIALOG_STYLE_LIST,"What IC stands for?"," Information Centre \n In Character \n I'm Cool","Select","Leave Game");
                        // Next dialog will show up
                    }
                }
                if(QuizAnswers[playerid] >= 3) // If he reached 3 wrong answers
                {
                    SendClientMessage(playerid, -1,"Sorry mate, you answered 3 times wrong.Maybe another time");
                    Kick(playerid); // He will be kicked
                }
            }
        }
        case DIALOG_QUIZ3: // If 4rd dialog shows up
        {
            if(!response) return Kick(playerid); // If he click second button he get kicked
            if(response) // If he click first button
            {
                switch(listitem) // We switch the available answers
                {
                    case 0: // If he choose first answer wich is: Information Centre
                    {
                        SendClientMessage(playerid, -1,"Wrong answer!"); // He will get a message that he answered wrong
                        QuizAnswers[playerid] += 1; // His quiz answers will be increased with 1 point.
                        ShowPlayerDialog(playerid, DIALOG_QUIZ4, DIALOG_STYLE_LIST,"What OOC stands for?"," Out of Chat \n Out of Character \n Ow ow cool","Select","Leave Game");
                        // Next dialog will show up
                    }
                    case 1: // If he choose first answer wich is: In Character (correct one)
                    {
                        SendClientMessage(playerid, -1,"That's the correct answer!");
                        ShowPlayerDialog(playerid, DIALOG_QUIZ4, DIALOG_STYLE_LIST,"What OOC stands for?"," Out of Chat \n Out of Character \n Ow ow cool","Select","Leave Game");
                        // Next dialog will show up
                    }
                    case 2: // If he choose first answer wich is: I'm Cool
                    {
                        SendClientMessage(playerid, -1,"Wrong answer!"); // He will get a message that he answered wrong
                        QuizAnswers[playerid] += 1; // His quiz answers will be increased with 1 point.
                        ShowPlayerDialog(playerid, DIALOG_QUIZ4, DIALOG_STYLE_LIST,"What OOC stands for?"," Out of Chat \n Out of Character \n Ow ow cool","Select","Leave Game");
                        // Next dialog will show up
                    }
                }
                if(QuizAnswers[playerid] >= 3) // If he reached 3 wrong answers or more
                {
                    SendClientMessage(playerid, -1,"Sorry mate, you answered 3 times wrong.Maybe another time");
                    Kick(playerid); // He will be kicked
                }
            }
        }
        case DIALOG_QUIZ4: // If 5 dialog shows up
        {
            if(!response) return Kick(playerid); // If he click second button he get kicked
            if(response) // If he click first button
            {
                switch(listitem) // We switch the available answers
                {
                    case 0: // If he choose first answers wich is: Out of Chat
                    {
                        SendClientMessage(playerid, -1,"Wrong answer!"); // He will get a message that he answered wrong
                        QuizAnswers[playerid] += 1; // His quiz answers will be increased with 1 point.
                    }
                    case 1: // If he choose second answers wich is: Out of Character (correct one)
                    {
                        SendClientMessage(playerid, -1,"That's the correct answer");
                    }
                    case 2: // If he choose 3rd answer wich is: Ow ow cool
                    {
                        SendClientMessage(playerid, -1,"Wrong answer!"); // He will get a message that he answered wrong
                        QuizAnswers[playerid] += 1; // His quiz answers will be increased with 1 point.
                    }
                }
                if(QuizAnswers[playerid] >= 3) // If he reached 3 wrong answers or more
                {
                    SendClientMessage(playerid, -1,"Sorry mate, you answered 3 times wrong.Maybe another time");
                    Kick(playerid); // He will be kicked
                }
                else // If he didn't have at least 3 wrong answers
                {
                    SendClientMessage(playerid, -1,"Congratulations, you have passed the RP quiz!");
                    SpawnPlayer(playerid);
                    // After the quiz is finish,the player will be spawned, you can change here.
                }
            }
        }
    }
    return 1;
}
And now you can have a RP quiz on your server! Change the questions, add more, remove, do whatever you want.

End

If I missed anything, or you didn't understand something please reply.



Re: How to create a simple RP quiz (Dialogs) - GangsTa_ - 17.09.2011

Good job.


Re: How to create a simple RP quiz (Dialogs) - linuxthefish - 17.09.2011

"How to make your RP server look like 4000+ RP servers" would be a better title.


Re: How to create a simple RP quiz (Dialogs) - Kush - 17.09.2011

Quote:
Originally Posted by linuxthefish
View Post
"How to make your RP server look like 4000+ RP servers" would be a better title.
Agreed.


Re: How to create a simple RP quiz (Dialogs) - FireCat - 17.09.2011

Quote:
Originally Posted by linuxthefish
View Post
"How to make your RP server look like 4000+ RP servers" would be a better title.
Indeed.


Re: How to create a simple RP quiz (Dialogs) - =WoR=G4M3Ov3r - 17.09.2011

Quote:
Originally Posted by linuxthefish
View Post
"How to make your RP server look like 4000+ RP servers" would be a better title.
I see, if he wanted to make it unique, he'd make it for himself instead of having 500+ people doing the same thing.

I find this tutorial actually good, well done Jafet.


Re: How to create a simple RP quiz (Dialogs) - [MWR]Blood - 17.09.2011

Quote:
Originally Posted by linuxthefish
View Post
"How to make your RP server look like 4000+ RP servers" would be a better title.
The tutorial actually is good; he spent certainly not a little amount of time to do this and explain every line.
I am not familiar with features of the RP servers - I never join one or if I do, I leave after a maximum of 1 minute, so I can't say anything about that.
I like the tutorial though; good job.


Re: How to create a simple RP quiz (Dialogs) - Omer_Tabib - 17.09.2011

Nice tutorial but I think that quiz is in all the servers..
good for begginers


Re: How to create a simple RP quiz (Dialogs) - BetaLaxx - 17.09.2011

Quote:
Originally Posted by linuxthefish
View Post
"How to make your RP server look like 4000+ RP servers" would be a better title.
Agreed


Re: How to create a simple RP quiz (Dialogs) - =WoR=G4M3Ov3r - 17.09.2011

Quote:
Originally Posted by Omer_Tabib
View Post
Nice tutorial but I think that quiz is in all the servers..
good for begginers
You don't "think" you just read what linuxthefish said, and saw Kush and FireCat agreeing.


Quote:
Originally Posted by BetaLaxx
View Post
Agreed
May you stop saying agreed like all the others are ?, He tried to help you guys, I highly doubt you even know what this is about.


Re: How to create a simple RP quiz (Dialogs) - linuxthefish - 17.09.2011

Quote:
Originally Posted by linuxthefish
View Post
"How to make your RP server look like 4000+ RP servers" would be a better title.
Agreed


Re: How to create a simple RP quiz (Dialogs) - =WoR=G4M3Ov3r - 17.09.2011

Quote:
Originally Posted by linuxthefish
View Post
Agreed
Stop spamming the guy's thread, unless you have something useful to say -.-


Re: How to create a simple RP quiz (Dialogs) - linuxthefish - 17.09.2011

Quote:
Originally Posted by G4M3Ov3r
View Post
You don't "think" you just read what linuxthefish said, and saw Kush and FireCat agreeing.

May you stop saying agreed like all the others are ?, He tried to help you guys, I highly doubt you even know what this is about.
Stop spamming the guy's thread, unless you have something useful to say -.-


Re: How to create a simple RP quiz (Dialogs) - =WoR=G4M3Ov3r - 17.09.2011

Quote:
Originally Posted by linuxthefish
View Post
Stop spamming the guy's thread, unless you have something useful to say -.-
Go troll somewhere else, I hate arguing with Immature, and disrespectful people like you.


Re: How to create a simple RP quiz (Dialogs) - linuxthefish - 17.09.2011

Quote:
Originally Posted by G4M3Ov3r
View Post
Go troll somewhere else, I hate arguing with Immature, and disrespectful people like you.
Stop spamming the guy's thread, unless you have something useful to say -.-


Re: How to create a simple RP quiz (Dialogs) - Davz*|*Criss - 17.09.2011

Awesome tutorial Jafet i could get idea from it. Good job again.


Re: How to create a simple RP quiz (Dialogs) - seanny - 20.09.2011

ON TOPIC: I find this Tutorial Very Useful, I will use this tutorial on my server with you in the credits!

OFF TOPIC: About that "Agreed" crap, Your right, they are spamming the thread


Re: How to create a simple RP quiz (Dialogs) - =WoR=Varth - 20.09.2011

switch?


Re: How to create a simple RP quiz (Dialogs) - Jafet_Macario - 20.09.2011

My bad, done.


Re: How to create a simple RP quiz (Dialogs) - =WoR=Varth - 20.09.2011

Quote:
Originally Posted by Jafet_Macario
View Post
My bad, done.
What's done? I mean why didn't you use switch for listitem?