20.05.2012, 14:51
Hello and welcome to my tutorial.
I am here to explain and give a tutorial about "Quiz Systems".
What I will be showing you today:
I will be making clear comments about what I am doing, so if you struggle you should be able to read them and then you should be good to continue. Although, if you have any problems, please don't hesitate to post on here!
Let's get started!
At the top of the script, make sure that you have got this included:
This here, will allow you the usage of the "Pawn" scripting for SA-MP. Without this, you will struggle to script anything.
Now that we have got that part done, we need to define a colour into the script!
We are going to be defining the colour, "White".
To do this, underneath where you have done the "#include" section, add the following piece of script:
This is defining the colour, so that when we use it in a SendClientMessage; it will work.
Example:
Second section:
(Player variables)
To do this, all we need to do is add "new WhatOurVariableIs[MAX_PLAYERS];", that would define it for the player's that are in the game.
So, to add ours we will need to add this to the top of the script:
If you try to compile when you have just added these; you are going to get 2 warnings. Not errors, but warnings because none of the "new's" have been used as of yet. Here is what the warning will look like:
Don't worry about these warnings though, because they will all be removed by you in time, along more of the script.
Under "OnPlayerConnect(playerid)", you will want to notify the script to clear all player variables, so then the player doesn't have any items such as a fishing rod or bait. More is explained below.
The reason for this is, to reset all player variables that we have just added.
Having: "OnQuiz[playerid] = 0;" will make it so the script can see that the player isn't on the quiz yet.
Having: "QuizSection[playerid] = 0;" will make it so the script can see that the player isn't on any section of the quiz.
Also, now if you tried to compile. You should have noticed that the warning codes have gone. This is because you have now used the variables in the script, so they aren't "Not being used".
The thing that I have show you above with OnPlayerConnect(playerid), you need to do the same for OnPlayerDisconnect(playerid, reason).
Now, on OnPlayerRequestClass(playerid, classid)
That will ensure the script that when a player disconnects, it will remove all of the variables that have been stored in the script, whilst the player has been connected.
Now that we have the defines, includes and player variables out of the way, we can crack on with the rest of the script!
Third section:
(Script functions)
This section of the tutorial, will show you the basics of OnPlayerText, also how to create the actual Quiz.
That comes to an end of my tutorial, thank you for reading and if you have got any questions, please post them here!
I know that there is a lot of writing, but it all will help newbie's in scripting. I hope that people will learn something from this because it will make me feel better :3.
Otherwise, good luck with your scripting!
- iGetty out.
I am here to explain and give a tutorial about "Quiz Systems".
What I will be showing you today:
- How to add a Quiz system when somebody joins, they have to complete the quiz to play.[/*]
I will be making clear comments about what I am doing, so if you struggle you should be able to read them and then you should be good to continue. Although, if you have any problems, please don't hesitate to post on here!
Let's get started!
At the top of the script, make sure that you have got this included:
pawn Code:
#include <a_samp>
Now that we have got that part done, we need to define a colour into the script!
We are going to be defining the colour, "White".
To do this, underneath where you have done the "#include" section, add the following piece of script:
pawn Code:
#define WHITE 0xFFFFFFFF
Example:
pawn Code:
SendClientMessage(playerid, WHITE, "This will show the colour in WHITE.");
(Player variables)
To do this, all we need to do is add "new WhatOurVariableIs[MAX_PLAYERS];", that would define it for the player's that are in the game.
So, to add ours we will need to add this to the top of the script:
pawn Code:
new OnQuiz[MAX_PLAYERS], QuizSection[MAX_PLAYERS];
Code:
warning 203: symbol is never used: "OnQuiz" warning 203: symbol is never used: "QuizSection"
Under "OnPlayerConnect(playerid)", you will want to notify the script to clear all player variables, so then the player doesn't have any items such as a fishing rod or bait. More is explained below.
pawn Code:
public OnPlayerConnect(playerid)
{
//You will want to add the following:
QuizSection[playerid] = -1;
OnQuiz[playerid] = -1;
TogglePlayerControllable(playerid, 0); //This sets the player to none controllable.
SendClientMessage(playerid, WHITE, "What does SA-MP mean?");
SendClientMessage(playerid, WHITE, "A. San Andreas Multi Player");
SendClientMessage(playerid, WHITE, "B. Slick Assed Moron Player");
SendClientMessage(playerid, WHITE, "C. Sausages And Mash Peas");//This sends the first quiz message
return 1;
}
Having: "OnQuiz[playerid] = 0;" will make it so the script can see that the player isn't on the quiz yet.
Having: "QuizSection[playerid] = 0;" will make it so the script can see that the player isn't on any section of the quiz.
Also, now if you tried to compile. You should have noticed that the warning codes have gone. This is because you have now used the variables in the script, so they aren't "Not being used".
The thing that I have show you above with OnPlayerConnect(playerid), you need to do the same for OnPlayerDisconnect(playerid, reason).
pawn Code:
public OnPlayerDisconnect(playerid, reason)
{
//You will want to add the following:
OnQuiz[playerid] = 0;
QuizSection[playerid] = 0;
return 1;
}
pawn Code:
public OnPlayerRequestClass(playerid, classid)
{
TogglePlayerSpectating(playerid, true); //This sets the player spectating, so he doesn't see the spawn button.
SetPlayerPos(playerid, 1544.7887,-1675.4630,13.5591); //This sets the player pos
SetPlayerCameraPos(playerid, 1541.5293,-1675.4012,13.5527); //This sets the camera pos
SetPlayerCameraLookAt(playerid, 1544.7887,-1675.4630,13.5591); //This sets the cameras looking at pos
return 1;
}
Now that we have the defines, includes and player variables out of the way, we can crack on with the rest of the script!
Third section:
(Script functions)
This section of the tutorial, will show you the basics of OnPlayerText, also how to create the actual Quiz.
pawn Code:
public OnPlayerText(playerid, text[])
{
if(OnQuiz[playerid] == 1) //This is checking if the player is on the quiz.
{
if(QuizSection[playerid] == 1) //This is checking if the player is on part 1.
{
if(!strcmp(text, "a", true)) //This is checking if the player typed A.
{
SendClientMessage(playerid, WHITE, " ");
SendClientMessage(playerid, WHITE, "Correct! Next:");
QuizSection[playerid] = 2; //This is setting the player to be on part 2.
SendClientMessage(playerid, WHITE, "What is the creator of SA-MP's name?");
SendClientMessage(playerid, WHITE, "A. Kalcor");
SendClientMessage(playerid, WHITE, "B. Dugi");
SendClientMessage(playerid, WHITE, "C. JaTochNietDan");
return 0;
}
else if(!strcmp(text, "b", true)) //This is checking the player typed B
{
SendClientMessage(playerid, WHITE, " ");
SendClientMessage(playerid, WHITE, "Wrong! You were kicked because you got it wrong.");
Kick(playerid);
return 0;
}
else if(!strcmp(text, "c", true)) //This is checking the player typed C
{
SendClientMessage(playerid, WHITE, " ");
SendClientMessage(playerid, WHITE, "Wrong! You were kicked because you got it wrong.");
Kick(playerid);
return 0;
}
else
{
SendClientMessage(playerid, WHITE, "Error: You can only use A, B or C."); //This is checking the player typed A B or C else it sends this
return 0;
}
}
if(QuizSection[playerid] == 2) //This is checking if the player is on section 2.
{
if(!strcmp(text, "a", true)) //This is checking the player typed A
{
SendClientMessage(playerid, WHITE, " ");
SendClientMessage(playerid, WHITE, "Correct! Next:");
QuizSection[playerid] = 3;
SendClientMessage(playerid, WHITE, "What is a Bullet?");
SendClientMessage(playerid, WHITE, "A. Car");
SendClientMessage(playerid, WHITE, "B. Truck");
SendClientMessage(playerid, WHITE, "C. Weapon");
return 0;
}
else if(!strcmp(text, "b", true)) //This is checking the player typed B
{
SendClientMessage(playerid, WHITE, " ");
SendClientMessage(playerid, WHITE, "Wrong! You were kicked because you got it wrong.");
Kick(playerid);
return 0;
}
else if(!strcmp(text, "c", true)) //This is checking the player typed C
{
SendClientMessage(playerid, WHITE, " ");
SendClientMessage(playerid, WHITE, "Wrong! You were kicked because you got it wrong.");
Kick(playerid);
return 0;
}
else
{
SendClientMessage(playerid, WHITE, " ");
SendClientMessage(playerid, WHITE, "Error: You can only use A, B or C."); //This is checking the player typed A B or C, else sends this message.
return 0;
}
}
if(QuizSection[playerid] == 3) //This is checking if the player is on section 3.
{
if(!strcmp(text, "a", true)) //This is checking the player typed A
{
SendClientMessage(playerid, WHITE, " ");
SendClientMessage(playerid, WHITE, "Correct! You can spawn!");
QuizSection[playerid] = 0;
OnQuiz[playerid] = 0;
TogglePlayerSpectating(playerid, false);//This is telling the script that the player isn't spectating anymore,
SetSpawnInfo(playerid, 0, 1, 123.4, 123.4, 123.4, 123.54, 0, 0, 0, 0, 0, 0); //This sets the players position, team and weapons.
SpawnPlayer(playerid); //This spawns the player
return 0;
}
else if(!strcmp(text, "b", true)) //This is checking the player typed B
{
SendClientMessage(playerid, WHITE, " ");
SendClientMessage(playerid, WHITE, "Wrong! You were kicked because you got it wrong.");
Kick(playerid);
return 0;
}
else if(!strcmp(text, "c", true)) //This is checking the player typed C
{
SendClientMessage(playerid, WHITE, " ");
SendClientMessage(playerid, WHITE, "Wrong! You were kicked because you got it wrong.");
Kick(playerid);
return 0;
}
else
{
SendClientMessage(playerid, WHITE, " ");
SendClientMessage(playerid, WHITE, "Error: You can only use A, B or C."); //This is checking the player typed A B or C, else sends this message.
return 0;
}
}
}
return 1;
}
I know that there is a lot of writing, but it all will help newbie's in scripting. I hope that people will learn something from this because it will make me feel better :3.
Otherwise, good luck with your scripting!
- iGetty out.