Advertisement
97fresh

trivia event

May 2nd, 2013
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.68 KB | None | 0 0
  1. #include <a_samp>
  2. //Not Changeable
  3. #define INVALID_QUESTION -1
  4.  
  5. //Changeables
  6. #define QUESTIONS 5 //Amount of questions
  7. #define MAX_QUESTIONS 5 //Amount of questions in a questionaire
  8. #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)
  9. #define MAX_WRONG_ANSWERS 5 //Max amount of wrong anwers (There must be atleast 1 wrong answer, a max of 3 will be used)
  10.  
  11. #define MAX_QUESTION_LENGTH 128 //Question Length
  12. #define MAX_ANSWER_LENGTH 128 //Answer Length
  13.  
  14. #define POINT_CORRECT 10 //Amount of points a player gets if the answer is correct
  15. #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)
  16. #define QUESTION_TIME 30000//Time in milliseconds for each question
  17.  
  18. #define ERROR_COLOR 0xAAAAAAFF
  19. #define QUESTION_COLOR 0xFF9999FF
  20. #define GOTITRIGHT_COLOR 0x55FF55FF
  21. #define GOTITWRONG_COLOR 0xDD0000FF
  22. #define WINNER_COLOR 0x6666FFFF
  23.  
  24. #define USE_DIALOG_ID 13337
  25.  
  26. forward Trivia();
  27.  
  28. new Questions[QUESTIONS][MAX_QUESTION_LENGTH] = {
  29. "Care este prescurtarea pt Romania Stunt Universe?", //Question 1
  30. "Care este comanda de cumparat un set de arme?", //Question 2
  31. "Al cui este serveru?", //Question 3
  32. "Ce sistem de admin foloseste RSU?", //Question 4
  33. "Cine a creat gm RSU" //Question 5
  34. };
  35. new RightAnswers[QUESTIONS][MAX_RIGHT_ANSWERS][MAX_ANSWER_LENGTH] = {
  36. {"RSU", ""}, //Question 1
  37. {"sarme ", ""}, //Question 2
  38. {"97fresh si ghost", ""}, //Question 3
  39. {"ladmin4v2", ""}, //Question 4
  40. {"97fresh si ghost", ""} //Question 5
  41. };
  42. new WrongAnswers[QUESTIONS][MAX_WRONG_ANSWERS][MAX_ANSWER_LENGTH] = {
  43. {"RSU", "ROSU", "RNS", "RBS", ""}, //Question 1
  44. {"arme", "sarme", "weapons", "giveweapon", ""}, //Question 2
  45. {"bunica", "97fresh", "97fresh si ghost", "Love", "Demon"}, //Question 3
  46. {"luxadmin", "ladmin4v2", "xadmin", "0admin", ""}, //Question 4
  47. {"Big Smoke", "just4fun", "CocaCola", "ALIENS", "97fresh si ghost"} //Question 5
  48. };
  49. new gQID; //The ID of the question
  50. new gQRemaining; //Amount of questions remaining
  51. new gQAsked[QUESTIONS]; //Wether or not a question has already been asked (no repeats)
  52. new gStartTime;
  53. new pAnswer[MAX_PLAYERS][QUESTIONS]; //1=correct, 2=incorrect, -0=not answered
  54. new pDialogOn[MAX_PLAYERS];//To make sure the player is using my dialog
  55. new pResponseTime[MAX_PLAYERS][QUESTIONS]; //Response time per question (average will be compared)
  56.  
  57. PlayerTriviaDialog(playerid)
  58. {
  59. if(gQRemaining==INVALID_QUESTION)return SendClientMessage(playerid,ERROR_COLOR,"Trivia has ended or has not yet begun.");
  60. if(pAnswer[playerid][MAX_QUESTIONS-gQRemaining-1])return SendClientMessage(playerid,ERROR_COLOR,"You have already submitted your answer.");
  61. new AnswersList[1024];//Has to be long
  62. new answer;//the line of the list the correct answer is on
  63. new WAUsed[MAX_WRONG_ANSWERS];
  64. new WAAmount;
  65. new RAAmount;
  66. for(new p;p<MAX_WRONG_ANSWERS;p++)if(WrongAnswers[gQID][p][0])WAAmount++;
  67. for(new p;p<MAX_RIGHT_ANSWERS;p++)if(RightAnswers[gQID][p][0])RAAmount++;
  68. if(WAAmount<3)//Question has less than 3 wrong answers
  69. {
  70. answer=random(WAAmount+1);
  71. new spot;
  72. for(new o;o<WAAmount;o++)
  73. {
  74. if(o!=answer)
  75. {
  76. spot=random(WAAmount);
  77. while(WAUsed[spot]||!WrongAnswers[gQID][spot][0])spot=random(WAAmount);
  78. format(AnswersList,1024,"%s%s\n",AnswersList,WrongAnswers[gQID][spot]);
  79. WAUsed[spot]=1;
  80. }else{
  81. format(AnswersList,1024,"%s%s\n",AnswersList,RightAnswers[gQID][random(RAAmount)]);
  82. }
  83. }
  84. }else{//Question has atleast 3 wrong answers
  85. answer=random(4);
  86. new spot;
  87. for(new o;o<4;o++)
  88. {
  89. if(o!=answer)
  90. {
  91. spot=random(WAAmount);
  92. while(WAUsed[spot]||!WrongAnswers[gQID][spot][0])spot=random(WAAmount);
  93. format(AnswersList,1024,"%s%s\n",AnswersList,WrongAnswers[gQID][spot]);
  94. WAUsed[spot]=1;
  95. }else{
  96. format(AnswersList,1024,"%s%s\n",AnswersList,RightAnswers[gQID][random(RAAmount)]);
  97. }
  98. }
  99. }
  100. pDialogOn[playerid]=gQID;
  101. ShowPlayerDialog(playerid,USE_DIALOG_ID,DIALOG_STYLE_LIST,Questions[gQID],AnswersList,"Submit","Cancel");
  102. return 1;
  103. }
  104.  
  105. public OnFilterScriptInit()
  106. {
  107. gQRemaining=INVALID_QUESTION;
  108. return 1;
  109. }
  110.  
  111. public OnGameModeInit()
  112. {
  113. gQRemaining=INVALID_QUESTION;
  114. return 1;
  115. }
  116.  
  117. public OnPlayerConnect(playerid)
  118. {
  119. pDialogOn[playerid]=0;
  120. for(new answer;answer<MAX_QUESTIONS;answer++)pAnswer[playerid][answer]=0;
  121. return 1;
  122. }
  123.  
  124. public OnPlayerCommandText(playerid,cmdtext[])
  125. {
  126. if(!strcmp(cmdtext[1],"trivia",true))
  127. {
  128. if(!IsPlayerAdmin(playerid))return SendClientMessage(playerid,ERROR_COLOR,"Nu esti autorizat sa folosesti aceasta comanda.");
  129. if(gQRemaining!=INVALID_QUESTION)return SendClientMessage(playerid,ERROR_COLOR,"Trivia este deja pornit.");
  130. Trivia();
  131. return 1;
  132. }
  133. if(!strcmp(cmdtext[1],"answer",true))
  134. {
  135. if(gQRemaining==INVALID_QUESTION)return SendClientMessage(playerid,ERROR_COLOR,"Trivia nu este pornit.");
  136. if(pAnswer[playerid][MAX_QUESTIONS-gQRemaining-1])return SendClientMessage(playerid,ERROR_COLOR,"Deja ati raspuns.");
  137. PlayerTriviaDialog(playerid);
  138. return 1;
  139. }
  140. return 0;
  141. }
  142.  
  143. public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
  144. {
  145. if(dialogid!=USE_DIALOG_ID)return 1;
  146. if(pDialogOn[playerid]==gQID)
  147. {
  148. if(!response)
  149. {
  150. pDialogOn[playerid]=0;
  151. return 1;
  152. }
  153. for(new o;o<MAX_RIGHT_ANSWERS;o++)
  154. {
  155. if(!RightAnswers[gQID][o][0])continue;
  156. if(!strcmp(RightAnswers[gQID][o],inputtext,true))pAnswer[playerid][MAX_QUESTIONS-gQRemaining-1]=1;
  157. }
  158. if(!pAnswer[playerid][MAX_QUESTIONS-gQRemaining-1])pAnswer[playerid][MAX_QUESTIONS-gQRemaining-1]=2;
  159. pResponseTime[playerid][MAX_QUESTIONS-gQRemaining-1]=GetTickCount()-gStartTime;
  160. pDialogOn[playerid]=0;
  161. }else if(gQID>0)
  162. {
  163. pDialogOn[playerid]=0;
  164. SendClientMessage(playerid,GOTITWRONG_COLOR,"Timpul sa scurs!");
  165. }
  166. return 1;
  167. }
  168.  
  169. public Trivia()
  170. {
  171. new tmpstring[128];
  172. if(gQRemaining==INVALID_QUESTION)//Meaning a questionaire hasn't started yet
  173. {
  174. gQRemaining=MAX_QUESTIONS;
  175. format(tmpstring,128,"Trivia a început. % întrebari d, f% 0.01 secunde pentru fiecare întrebare",MAX_QUESTIONS,floatdiv(QUESTION_TIME,1000));
  176. SendClientMessageToAll(QUESTION_COLOR,tmpstring);
  177. format(tmpstring,128,"+% d puncte pentru corecta, -% d puncte pentru raspuns gresit",POINT_CORRECT,POINT_INCORRECT);
  178. SendClientMessageToAll(QUESTION_COLOR,tmpstring);
  179. SendClientMessageToAll(QUESTION_COLOR,"Foloseste /Answer daca crezi ca stii raspunsul! Acesta va incepe in 5 secunde.");
  180. for(new playerid;playerid<MAX_PLAYERS;playerid++)
  181. {
  182. for(new answer;answer<MAX_QUESTIONS;answer++)pAnswer[playerid][answer]=0;
  183. }
  184. SetTimer("Trivia",5000,0);
  185. return;
  186. }
  187. if( (gQRemaining!=INVALID_QUESTION) && (gQRemaining<MAX_QUESTIONS) )
  188. {
  189. for(new playerid;playerid<MAX_PLAYERS;playerid++)
  190. {
  191. if(!IsPlayerConnected(playerid))continue;
  192. if(!pAnswer[playerid][MAX_QUESTIONS-gQRemaining-1])continue;
  193. 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));
  194. SendClientMessage(playerid,(pAnswer[playerid][MAX_QUESTIONS-gQRemaining-1]==1)?(GOTITRIGHT_COLOR):(GOTITWRONG_COLOR),tmpstring);
  195. }
  196. }
  197. if(gQRemaining==0)
  198. {
  199. //Trivia is over
  200. gQRemaining=INVALID_QUESTION;
  201. new pTried[MAX_PLAYERS];
  202. new HighestScore=(-1*POINT_INCORRECT)*MAX_QUESTIONS;//lowest score possible
  203. new tmpscore[MAX_PLAYERS];
  204. new tmpAvgRT[MAX_PLAYERS];
  205. new fastestrt=30000; //slowest possible response
  206. new someonetried;
  207. new winner[MAX_PLAYERS];
  208. for(new playerid;playerid<MAX_PLAYERS;playerid++)
  209. {
  210. if(!IsPlayerConnected(playerid))continue;
  211. for(new answer;answer<MAX_QUESTIONS;answer++)
  212. {
  213. tmpAvgRT[playerid]+=pResponseTime[playerid][answer];
  214. if(pAnswer[playerid][answer]>0)
  215. {
  216. pTried[playerid]++;
  217. someonetried=1;
  218. }
  219. if(pAnswer[playerid][answer]==1)tmpscore[playerid]+=POINT_CORRECT;
  220. if(pAnswer[playerid][answer]==2)tmpscore[playerid]-=POINT_INCORRECT;
  221. }
  222. tmpAvgRT[playerid]=tmpAvgRT[playerid]/pTried[playerid];
  223. if( (tmpscore[playerid]>HighestScore) && pTried[playerid] )HighestScore=tmpscore[playerid];
  224. }
  225. if(!someonetried)
  226. {
  227. SendClientMessageToAll(GOTITRIGHT_COLOR,"Nimeni nu a încercat sa raspunda la trivia!");
  228. return;
  229. }
  230. SendClientMessageToAll(GOTITRIGHT_COLOR,"Castigatorul este...");
  231. for(new playerid;playerid<MAX_PLAYERS;playerid++)
  232. {
  233. if(!IsPlayerConnected(playerid))continue;
  234. if( (tmpscore[playerid]==HighestScore) && pTried[playerid] )winner[playerid]=1;
  235. }
  236. for(new playerid;playerid<MAX_PLAYERS;playerid++)if( (tmpAvgRT[playerid]<fastestrt) && winner[playerid] )fastestrt=tmpAvgRT[playerid];
  237. format(tmpstring,128,"");
  238. for(new playerid;playerid<MAX_PLAYERS;playerid++)if( (tmpAvgRT[playerid]==fastestrt) && winner[playerid] )
  239. {
  240. if(tmpstring[0])
  241. {
  242. GetPlayerName(playerid,tmpstring,MAX_PLAYER_NAME);
  243. format(tmpstring,128,"dar si %s",tmpstring);
  244. }else{
  245. GetPlayerName(playerid,tmpstring,MAX_PLAYER_NAME);
  246. format(tmpstring,128,"%s -- Points %d, Avg. Time: %0.2f",tmpstring,HighestScore,floatdiv(tmpAvgRT[playerid],1000));
  247. }
  248. SendClientMessage(playerid,WINNER_COLOR,tmpstring);
  249. }
  250. SendClientMessageToAll(GOTITRIGHT_COLOR,"Felicitari!!");
  251. 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);}
  252. return;
  253. }
  254. gQRemaining--;
  255. gQID=random(QUESTIONS);
  256. 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
  257. gQAsked[gQID]=1;
  258. format(tmpstring,128,"Intrebarea #%d: %s",MAX_QUESTIONS-gQRemaining,Questions[gQID]);
  259. gStartTime=GetTickCount();
  260. SendClientMessageToAll(QUESTION_COLOR,tmpstring);
  261. SetTimer("Trivia",QUESTION_TIME,0);
  262. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement