Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <a_samp>
- //Not Changeable
- #define INVALID_QUESTION -1
- //Changeables
- #define QUESTIONS 5 //Amount of questions
- #define MAX_QUESTIONS 5 //Amount of questions in a questionaire
- #define MAX_RIGHT_ANSWERS 2 //Max amount of correct answers assuming there's more than one (Only 1 answer will be used, they'll be chosen randomly)
- #define MAX_WRONG_ANSWERS 5 //Max amount of wrong anwers (There must be atleast 1 wrong answer, a max of 3 will be used)
- #define MAX_QUESTION_LENGTH 128 //Question Length
- #define MAX_ANSWER_LENGTH 128 //Answer Length
- #define POINT_CORRECT 10 //Amount of points a player gets if the answer is correct
- #define POINT_INCORRECT 15 //Amount of points a player loses if the answer is incorrect (I like it being better to not guess than be wrong)
- #define QUESTION_TIME 30000//Time in milliseconds for each question
- #define ERROR_COLOR 0xAAAAAAFF
- #define QUESTION_COLOR 0xFF9999FF
- #define GOTITRIGHT_COLOR 0x55FF55FF
- #define GOTITWRONG_COLOR 0xDD0000FF
- #define WINNER_COLOR 0x6666FFFF
- #define USE_DIALOG_ID 13337
- forward Trivia();
- new Questions[QUESTIONS][MAX_QUESTION_LENGTH] = {
- "Care este prescurtarea pt Romania Stunt Universe?", //Question 1
- "Care este comanda de cumparat un set de arme?", //Question 2
- "Al cui este serveru?", //Question 3
- "Ce sistem de admin foloseste RSU?", //Question 4
- "Cine a creat gm RSU" //Question 5
- };
- new RightAnswers[QUESTIONS][MAX_RIGHT_ANSWERS][MAX_ANSWER_LENGTH] = {
- {"RSU", ""}, //Question 1
- {"sarme ", ""}, //Question 2
- {"97fresh si ghost", ""}, //Question 3
- {"ladmin4v2", ""}, //Question 4
- {"97fresh si ghost", ""} //Question 5
- };
- new WrongAnswers[QUESTIONS][MAX_WRONG_ANSWERS][MAX_ANSWER_LENGTH] = {
- {"RSU", "ROSU", "RNS", "RBS", ""}, //Question 1
- {"arme", "sarme", "weapons", "giveweapon", ""}, //Question 2
- {"bunica", "97fresh", "97fresh si ghost", "Love", "Demon"}, //Question 3
- {"luxadmin", "ladmin4v2", "xadmin", "0admin", ""}, //Question 4
- {"Big Smoke", "just4fun", "CocaCola", "ALIENS", "97fresh si ghost"} //Question 5
- };
- new gQID; //The ID of the question
- new gQRemaining; //Amount of questions remaining
- new gQAsked[QUESTIONS]; //Wether or not a question has already been asked (no repeats)
- new gStartTime;
- new pAnswer[MAX_PLAYERS][QUESTIONS]; //1=correct, 2=incorrect, -0=not answered
- new pDialogOn[MAX_PLAYERS];//To make sure the player is using my dialog
- new pResponseTime[MAX_PLAYERS][QUESTIONS]; //Response time per question (average will be compared)
- PlayerTriviaDialog(playerid)
- {
- if(gQRemaining==INVALID_QUESTION)return SendClientMessage(playerid,ERROR_COLOR,"Trivia has ended or has not yet begun.");
- if(pAnswer[playerid][MAX_QUESTIONS-gQRemaining-1])return SendClientMessage(playerid,ERROR_COLOR,"You have already submitted your answer.");
- new AnswersList[1024];//Has to be long
- new answer;//the line of the list the correct answer is on
- new WAUsed[MAX_WRONG_ANSWERS];
- new WAAmount;
- new RAAmount;
- for(new p;p<MAX_WRONG_ANSWERS;p++)if(WrongAnswers[gQID][p][0])WAAmount++;
- for(new p;p<MAX_RIGHT_ANSWERS;p++)if(RightAnswers[gQID][p][0])RAAmount++;
- if(WAAmount<3)//Question has less than 3 wrong answers
- {
- answer=random(WAAmount+1);
- new spot;
- for(new o;o<WAAmount;o++)
- {
- if(o!=answer)
- {
- spot=random(WAAmount);
- while(WAUsed[spot]||!WrongAnswers[gQID][spot][0])spot=random(WAAmount);
- format(AnswersList,1024,"%s%s\n",AnswersList,WrongAnswers[gQID][spot]);
- WAUsed[spot]=1;
- }else{
- format(AnswersList,1024,"%s%s\n",AnswersList,RightAnswers[gQID][random(RAAmount)]);
- }
- }
- }else{//Question has atleast 3 wrong answers
- answer=random(4);
- new spot;
- for(new o;o<4;o++)
- {
- if(o!=answer)
- {
- spot=random(WAAmount);
- while(WAUsed[spot]||!WrongAnswers[gQID][spot][0])spot=random(WAAmount);
- format(AnswersList,1024,"%s%s\n",AnswersList,WrongAnswers[gQID][spot]);
- WAUsed[spot]=1;
- }else{
- format(AnswersList,1024,"%s%s\n",AnswersList,RightAnswers[gQID][random(RAAmount)]);
- }
- }
- }
- pDialogOn[playerid]=gQID;
- ShowPlayerDialog(playerid,USE_DIALOG_ID,DIALOG_STYLE_LIST,Questions[gQID],AnswersList,"Submit","Cancel");
- return 1;
- }
- public OnFilterScriptInit()
- {
- gQRemaining=INVALID_QUESTION;
- return 1;
- }
- public OnGameModeInit()
- {
- gQRemaining=INVALID_QUESTION;
- return 1;
- }
- public OnPlayerConnect(playerid)
- {
- pDialogOn[playerid]=0;
- for(new answer;answer<MAX_QUESTIONS;answer++)pAnswer[playerid][answer]=0;
- return 1;
- }
- public OnPlayerCommandText(playerid,cmdtext[])
- {
- if(!strcmp(cmdtext[1],"trivia",true))
- {
- if(!IsPlayerAdmin(playerid))return SendClientMessage(playerid,ERROR_COLOR,"Nu esti autorizat sa folosesti aceasta comanda.");
- if(gQRemaining!=INVALID_QUESTION)return SendClientMessage(playerid,ERROR_COLOR,"Trivia este deja pornit.");
- Trivia();
- return 1;
- }
- if(!strcmp(cmdtext[1],"answer",true))
- {
- if(gQRemaining==INVALID_QUESTION)return SendClientMessage(playerid,ERROR_COLOR,"Trivia nu este pornit.");
- if(pAnswer[playerid][MAX_QUESTIONS-gQRemaining-1])return SendClientMessage(playerid,ERROR_COLOR,"Deja ati raspuns.");
- PlayerTriviaDialog(playerid);
- return 1;
- }
- return 0;
- }
- public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
- {
- if(dialogid!=USE_DIALOG_ID)return 1;
- if(pDialogOn[playerid]==gQID)
- {
- if(!response)
- {
- pDialogOn[playerid]=0;
- return 1;
- }
- for(new o;o<MAX_RIGHT_ANSWERS;o++)
- {
- if(!RightAnswers[gQID][o][0])continue;
- if(!strcmp(RightAnswers[gQID][o],inputtext,true))pAnswer[playerid][MAX_QUESTIONS-gQRemaining-1]=1;
- }
- if(!pAnswer[playerid][MAX_QUESTIONS-gQRemaining-1])pAnswer[playerid][MAX_QUESTIONS-gQRemaining-1]=2;
- pResponseTime[playerid][MAX_QUESTIONS-gQRemaining-1]=GetTickCount()-gStartTime;
- pDialogOn[playerid]=0;
- }else if(gQID>0)
- {
- pDialogOn[playerid]=0;
- SendClientMessage(playerid,GOTITWRONG_COLOR,"Timpul sa scurs!");
- }
- return 1;
- }
- public Trivia()
- {
- new tmpstring[128];
- if(gQRemaining==INVALID_QUESTION)//Meaning a questionaire hasn't started yet
- {
- gQRemaining=MAX_QUESTIONS;
- format(tmpstring,128,"Trivia a început. % întrebari d, f% 0.01 secunde pentru fiecare întrebare",MAX_QUESTIONS,floatdiv(QUESTION_TIME,1000));
- SendClientMessageToAll(QUESTION_COLOR,tmpstring);
- format(tmpstring,128,"+% d puncte pentru corecta, -% d puncte pentru raspuns gresit",POINT_CORRECT,POINT_INCORRECT);
- SendClientMessageToAll(QUESTION_COLOR,tmpstring);
- SendClientMessageToAll(QUESTION_COLOR,"Foloseste /Answer daca crezi ca stii raspunsul! Acesta va incepe in 5 secunde.");
- for(new playerid;playerid<MAX_PLAYERS;playerid++)
- {
- for(new answer;answer<MAX_QUESTIONS;answer++)pAnswer[playerid][answer]=0;
- }
- SetTimer("Trivia",5000,0);
- return;
- }
- if( (gQRemaining!=INVALID_QUESTION) && (gQRemaining<MAX_QUESTIONS) )
- {
- for(new playerid;playerid<MAX_PLAYERS;playerid++)
- {
- if(!IsPlayerConnected(playerid))continue;
- if(!pAnswer[playerid][MAX_QUESTIONS-gQRemaining-1])continue;
- format(tmpstring,128,"Ai acesta% e% d puncte. Timp de reac?ie:% 0.2f secunde ",(pAnswer[playerid][MAX_QUESTIONS-gQRemaining-1]==1)?("right, +"):("wrong, -"),(pAnswer[playerid][MAX_QUESTIONS-gQRemaining-1]==1)?(POINT_CORRECT):(POINT_INCORRECT),floatdiv(pResponseTime[playerid][MAX_QUESTIONS-gQRemaining-1],1000));
- SendClientMessage(playerid,(pAnswer[playerid][MAX_QUESTIONS-gQRemaining-1]==1)?(GOTITRIGHT_COLOR):(GOTITWRONG_COLOR),tmpstring);
- }
- }
- if(gQRemaining==0)
- {
- //Trivia is over
- gQRemaining=INVALID_QUESTION;
- new pTried[MAX_PLAYERS];
- new HighestScore=(-1*POINT_INCORRECT)*MAX_QUESTIONS;//lowest score possible
- new tmpscore[MAX_PLAYERS];
- new tmpAvgRT[MAX_PLAYERS];
- new fastestrt=30000; //slowest possible response
- new someonetried;
- new winner[MAX_PLAYERS];
- for(new playerid;playerid<MAX_PLAYERS;playerid++)
- {
- if(!IsPlayerConnected(playerid))continue;
- for(new answer;answer<MAX_QUESTIONS;answer++)
- {
- tmpAvgRT[playerid]+=pResponseTime[playerid][answer];
- if(pAnswer[playerid][answer]>0)
- {
- pTried[playerid]++;
- someonetried=1;
- }
- if(pAnswer[playerid][answer]==1)tmpscore[playerid]+=POINT_CORRECT;
- if(pAnswer[playerid][answer]==2)tmpscore[playerid]-=POINT_INCORRECT;
- }
- tmpAvgRT[playerid]=tmpAvgRT[playerid]/pTried[playerid];
- if( (tmpscore[playerid]>HighestScore) && pTried[playerid] )HighestScore=tmpscore[playerid];
- }
- if(!someonetried)
- {
- SendClientMessageToAll(GOTITRIGHT_COLOR,"Nimeni nu a încercat sa raspunda la trivia!");
- return;
- }
- SendClientMessageToAll(GOTITRIGHT_COLOR,"Castigatorul este...");
- for(new playerid;playerid<MAX_PLAYERS;playerid++)
- {
- if(!IsPlayerConnected(playerid))continue;
- if( (tmpscore[playerid]==HighestScore) && pTried[playerid] )winner[playerid]=1;
- }
- for(new playerid;playerid<MAX_PLAYERS;playerid++)if( (tmpAvgRT[playerid]<fastestrt) && winner[playerid] )fastestrt=tmpAvgRT[playerid];
- format(tmpstring,128,"");
- for(new playerid;playerid<MAX_PLAYERS;playerid++)if( (tmpAvgRT[playerid]==fastestrt) && winner[playerid] )
- {
- if(tmpstring[0])
- {
- GetPlayerName(playerid,tmpstring,MAX_PLAYER_NAME);
- format(tmpstring,128,"dar si %s",tmpstring);
- }else{
- GetPlayerName(playerid,tmpstring,MAX_PLAYER_NAME);
- format(tmpstring,128,"%s -- Points %d, Avg. Time: %0.2f",tmpstring,HighestScore,floatdiv(tmpAvgRT[playerid],1000));
- }
- SendClientMessage(playerid,WINNER_COLOR,tmpstring);
- }
- SendClientMessageToAll(GOTITRIGHT_COLOR,"Felicitari!!");
- for(new playerid;playerid<MAX_PLAYERS;playerid++)if((tmpscore[playerid]!=HighestScore)&&pTried[playerid]){format(tmpstring,128,"You scored %d points",tmpscore[playerid]);SendClientMessage(playerid,GOTITWRONG_COLOR,tmpstring);}
- return;
- }
- gQRemaining--;
- gQID=random(QUESTIONS);
- while(gQAsked[gQID])gQID=random(QUESTIONS); //Looks dangerous, but it's not, it isn't as 'random' as you might think, but to keep you from worrying just reduce MAX_QUESTIONS so that there's always atleast 50% chance of hitting a question
- gQAsked[gQID]=1;
- format(tmpstring,128,"Intrebarea #%d: %s",MAX_QUESTIONS-gQRemaining,Questions[gQID]);
- gStartTime=GetTickCount();
- SendClientMessageToAll(QUESTION_COLOR,tmpstring);
- SetTimer("Trivia",QUESTION_TIME,0);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement