RP Test
#1

I have been wondering if it is possible to script an RP test, with random questions & answers
by throughout selecting them on an array instead of a messy code.

I have seen this on a server where in they managed to scramble up the questions and answer to prevent the answers getting leaked out or shared out if it has the same RP test for everyone.

E.G.

The question is What does RP stands for?

1. Roleplay, portraying/acting as a real life person etc.
2. Wrong Answers #1
3. Wrong Answers #2

If the same question appears on the scramble up, The appearance would appear different like.

1. Wrong Answers #1
2. The answer
3. Wrong Answers #2

Is it possible?
Reply
#2

Yes, but if you wanted to do that I don't think you can make it into an array.
Reply
#3

Well is there any way i can do it without using a messy code?
Reply
#4

I suppose you could have an array:

pawn Код:
new PlayerTestQuestion[MAX_PLAYERS];

enum Test {
    tQuestion[128],
    tAnswer1[128],
    tAnswer2[128],
    tAnswer3[128],
    tCorrectAns
}

new TestVar[][Test] =
{
     {"Question", "Answer1", "Answer2", "Answer3", 2} // Ans 2 = correct answer.
}


// Under a player function.
PlayerTestQuestion[playerid] = random(sizeof(Test));

new
      rand = random(2);

switch(rand)
{
     case 0:format(string, sizeof(string), "%s\n%s\n%s", TestVar[PlayerTestQuestion[playerid]][tAnswer1], TestVar[PlayerTestQuestion[playerid]][tAnswer2], TestVar[PlayerTestQuestion[playerid]][tAnswer3]);
     case 1:format(string, sizeof(string), "%s\n%s\n%s", TestVar[PlayerTestQuestion[playerid]][tAnswer3], TestVar[PlayerTestQuestion[playerid]][tAnswer2], TestVar[PlayerTestQuestion[playerid]][tAnswer1]);
     case 2:format(string, sizeof(string), "%s\n%s\n%s", TestVar[PlayerTestQuestion[playerid]][tAnswer1], TestVar[PlayerTestQuestion[playerid]][tAnswer3], TestVar[PlayerTestQuestion[playerid]][tAnswer2]);
}
ShowPlayerDialog(playerid, DIALOG_TEST, DIALOG_STYLE_LIST, TestVar[PlayerTestQuestion[playerid]][tQuestion], string, "Select", "Close");

// On Dialog Response

case DIALOG_TEST:
{
      if(response)
      {
           new
              getans = 0;

           if(!strcmp(TestVar[PlayerTestQuestion[playerid]][tAnswer1], inputtext)) getans = 1;
           if(!strcmp(TestVar[PlayerTestQuestion[playerid]][tAnswer2], inputtext)) getans = 2;
           if(!strcmp(TestVar[PlayerTestQuestion[playerid]][tAnswer3], inputtext)) getans = 3;
 
           if(TestVar[PlayerTestQuestion[playerid]][tCorrectAns] == getans)
           {
              // Correct
           }
           else
           {
              // Incorrect
           }
      }
}
This took a while to write. I hope this helps you.
Reply
#5

Thank you so much, I will be basing this code

I will be creditting you, Cheers mate! *reped*
Reply
#6

Someone had an inquery how to prevent the same question showing more than once:

Код:
#define MAX_QUESTIONS 7

new PlayerTestQuestionsAns[MAX_PLAYERS]; // Checks how many questions have been answered already.
new PlayerTestQuestionsGot[MAX_PLAYERS][MAX_QUESTIONS]; // The reference of questions answered.

// Under on player connect
PlayerTestQuestion[playerid] = -1; // From the previous code as shown above.
PlayerTestQuestionsAns[playerid] = 0;

for(new i; i < MAX_QUESTIONS; i++)
     PlayerTestQuestionsGot[playerid][i] = -1;

// Code shown above, The stuff you need to add is highlighted in bold.
PlayerTestQuestion[playerid] = random(sizeof(Test));

new 
      rand = random(2);

PlayerQuizCheck: while(PlayerTestQuestionsGot[playerid][x] == PlayerTestQuestion[playerid])
{
     if(x > MAX_QUESTIONS)
       break;

     PlayerTestQuestions[playerid] = random(sizeof(Test));
     goto PlayerQuizCheck;
     break;
}
else
{
     if(x > MAX_QUESTIONS || x > PlayerTestQuestionsAns[playerid])
       break;

     x++;
} 
PlayerTestQuestionsAns[playerid]++;
PlayerTextQuestionsGot[playerid][PlayerTestQuestionsAns[playerid]] = PlayerTestQuestions[playerid];
//etc.
I haven't tested this code, but it should work.
Reply


Forum Jump:


Users browsing this thread: 3 Guest(s)