Advertisement
Guest User

Untitled

a guest
May 9th, 2011
1,130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 14.80 KB | None | 0 0
  1. #if defined x
  2.  
  3. |===========================================|
  4. | Reaction Tests by Zh3r0 |
  5. |-------------------------------------------|
  6. | Creation date: May, 06, 2011 |
  7. | |
  8. | Type in console !start to start a test |
  9. | |
  10. | Please keep the credits! |
  11. |===========================================|
  12.  
  13. #endif
  14.  
  15. #include <a_samp>
  16.  
  17. #define INTERVAL \
  18. (3 * 60 * 1_000)
  19.  
  20. #define MAX_RANDOM \
  21. 15
  22.  
  23. #define MAX_MESSAGES \
  24. 25
  25.  
  26. #define MAX_QUESTION \
  27. 30
  28.  
  29. #define QUIZ_WINNERS \
  30. "Quiz Winners.txt"
  31.  
  32. #define MATH_WINNERS \
  33. "Math Winners.txt"
  34.  
  35. #define REACTION_WINNERS \
  36. "Reaction Winners.txt"
  37.  
  38. #define MSG_WINNERS \
  39. "Message Winners.txt"
  40.  
  41. new bTest, bMoney, bScore, bString[2][256], bool:Won, Winner[MAX_PLAYER_NAME], mString[30], Timer,
  42. iMessages[MAX_MESSAGES][129], mCount = 0;
  43.  
  44. new Question[MAX_QUESTION][256],
  45. Option[4][MAX_QUESTION][30],
  46. Answer[2],
  47. CountQ = 0,
  48. Q,
  49. bool:Lost[MAX_PLAYERS],
  50. ReactionTime;
  51.  
  52. CreateQuiz(q[], o1[], o2[], o3[], answer[])
  53. {
  54.  
  55. memcpy(Question[CountQ], q, .numbytes = 256 );
  56. memcpy(Option[0][CountQ], o1, .numbytes = 100 );
  57. memcpy(Option[1][CountQ], o2, .numbytes = 100 );
  58. memcpy(Option[2][CountQ], o3, .numbytes = 100 );
  59. memcpy(Option[3][CountQ], answer, .numbytes = 100 );
  60. ++CountQ;
  61. }
  62. AddNewMessage(msg[])
  63. {
  64.  
  65. memcpy(iMessages[mCount], msg, 0, 129, 129),
  66. mCount++;
  67.  
  68. if(mCount >= MAX_MESSAGES){
  69. print("WARNING!! YOU EXCEEDED THE LIMIT OF "#MAX_MESSAGES" MESSAGES!\n\n\n");}
  70. }
  71.  
  72. public OnFilterScriptInit()
  73. {
  74. ReactionTime = 0;
  75. //Question Option1 Option2 Option3 Answer
  76. CreateQuiz("Who is the president of the United States?","Bin Laden", "Putin", "Ceausescu", "Barack Obama");
  77. CreateQuiz("Another question here?", "Option1", "Option2", "Option3", "Answer!");
  78. CreateQuiz("Is this a question??", "NOPE!!", "WTF?", "Hell no.", "INDEED IT IS!!");
  79. CreateQuiz("Who killed Bin Laden", "Obama", "The beaver", "Nobody", "NAVY SEAL");
  80.  
  81. AddNewMessage("This server rocks!!!");
  82. AddNewMessage("We love to entertain you");
  83. AddNewMessage("3v3RY0n3 l1k32 l337!!");
  84. AddNewMessage("7hIz 73X7 iZ h4Rd 70 wRi73!" );
  85. AddNewMessage("|-|4><0.-3.-2 |\\/||_|57 |)13");
  86. AddNewMessage("HeloHeloHeloHeloOOPS");
  87.  
  88.  
  89. printf("\n\n\
  90. |===========================================|\n\
  91. | Reaction Tests by Zh3r0 |\n\
  92. |-------------------------------------------|\n\
  93. | Creation date: May, 06, 2011 |\n\
  94. | |\n\
  95. | Type in console !help to more info |");
  96.  
  97. printf("\
  98. | Loaded %d messages |\n\
  99. | Loaded %d questions |\n\
  100. | |\n\
  101. | Please keep the credits! |\n\
  102. |===========================================|", mCount, CountQ);
  103.  
  104. Timer = SetTimerEx(#StartReaction, INTERVAL, 1, "dd", random(3), random(2));
  105. return 1;
  106. }
  107. public OnPlayerConnect(playerid)
  108. {
  109. Lost[playerid] = false;
  110. SendClientMessage(playerid, ~1, "This server uses {CFF55F}Reaction Tests{FFFFFF} by {CFF55F}Zh3r0{FFFFFF}! Wait for them to appear!");
  111. return 1;
  112. }
  113. public OnRconCommand(cmd[])
  114. {
  115. if(!strcmp(cmd, "!help", .length = 5))
  116. {
  117. print("\n\n\
  118. |===========================================|\n\
  119. | Reaction Tests by Zh3r0 |\n\
  120. |-------------------------------------------|\n\
  121. | Type /start in-game logged as admin |\n\
  122. | to initiate a reaction test! |\n\
  123. | Type in console !showmsgs to list the |\n\
  124. | messages created. |\n\
  125. |===========================================|\n\n\n");
  126. return 1;
  127. }
  128. if(!strcmp(cmd, "!showmsgs", .length = 9))
  129. {
  130. print("\n\n\nDisplaying created messages:\n-----------------------\n");
  131. for( new m; m < mCount; m++)
  132. {
  133. print(iMessages[m]);
  134. }
  135. }
  136. return 1;
  137. }
  138. public OnPlayerCommandText(playerid, cmdtext[])
  139. {
  140. if(!strcmp(cmdtext, "/an", true, 3))
  141. {
  142. if(bTest != 4)
  143. return SendClientMessage(playerid, ~1, "There is no quiz game going on!");
  144.  
  145. if(Lost[playerid])
  146. return SendClientMessage(playerid, ~1, "You cannot answer anymore!");
  147.  
  148. if((cmdtext[3] != ' ') || (cmdtext[4] == EOS))
  149. return SendClientMessage(playerid, ~1, "USAGE: /an {C3C3C3}<option> (a,b,c,d)");
  150.  
  151. if(!strcmp(cmdtext[4], Answer, true, 1) && strlen(cmdtext[4]))
  152. {
  153. EndReaction(playerid, "answered correctly");
  154. new Str[256],File:F = fopen(QUIZ_WINNERS, io_append);
  155. if(F)
  156. {
  157. format(Str, sizeof(Str), "%s\r\n----------------------------------\r\n\
  158. Question: %s\r\n\
  159. Answer: %s) %s\r\n\
  160. Winner: %s\r\n\
  161. Took: %d ms\r\n\
  162. ----------------------------------\r\n\r\n",
  163. Date(),
  164. Question[Q],
  165. Answer,
  166. Option[3][Q],
  167. Name(playerid),
  168. ReactionTime);
  169. fwrite(F, Str);
  170. fclose(F);
  171. }
  172. Lost[playerid] = false;
  173. }
  174. else
  175. {
  176. Lost[playerid] = true;
  177. SendClientMessage(playerid, ~1, "The answer was incorrect!");
  178. }
  179. return 1;
  180. }
  181.  
  182. if(!strcmp(cmdtext, "/start", true, 6))
  183. {
  184. if(IsPlayerAdmin(playerid))
  185. {
  186. if((cmdtext[6] != ' ') || (cmdtext[7] == EOS))
  187. return SendClientMessage(playerid, ~1, "USAGE: /start{C3C3C3} math/message [!text]/reaction/quiz/random");
  188.  
  189.  
  190. if(!strcmp(cmdtext[7], "math"))
  191. {
  192. StartReaction(0, 0);
  193. SendClientMessage(playerid, ~1, "You started the {CFF55F}Math Reaction Test");
  194. }
  195. else if(!strcmp(cmdtext[7], "message", true, 7))
  196. {
  197. if(cmdtext[14] == ' ' || cmdtext[15 || 14] != EOS)
  198. StartReaction(1, 0, cmdtext[15]);
  199.  
  200.  
  201. else if( cmdtext[15] >= EOS )
  202. StartReaction(1);
  203.  
  204.  
  205. SendClientMessage(playerid, ~1, "You started the {CFF55F}Message Reaction Test");
  206. }
  207. else if(!strcmp(cmdtext[7], "reaction"))
  208. {
  209. StartReaction(1, 1);
  210. SendClientMessage(playerid, ~1, "You started the {CFF55F}Reaction Test");
  211. }
  212. else if(!strcmp(cmdtext[7], "quiz"))
  213. {
  214. StartReaction(2);
  215. SendClientMessage(playerid, ~1, "You started the {CFF55F}Quiz Test");
  216. }
  217. else if(!strcmp(cmdtext[7], "random"))
  218. {
  219. StartReaction(random(3), random(2));
  220. }
  221. else return SendClientMessage(playerid, ~1, "USAGE: {C3C3C3}/start math/message [!text]/reaction/quiz/random");
  222.  
  223. }else return 0;
  224. return 1;
  225. }
  226. return 0;
  227. }
  228.  
  229. StartReaction( R1 = 3, R2 = 2, text[] = "?????")
  230. {
  231.  
  232. KillTimer(Timer);
  233. if(!Won){
  234. switch(bTest)
  235. {
  236. case (1): format(bString[1], 256, "Nobody was smart enough to calculate {CFF55F}%s{FFFFFF}. The answer was {CFF55F}%s{FFFFFF}.", mString, bString[0]);
  237. case (2): format(bString[1], 256, "Nobody wrote {CFF55F}%s{FFFFFF} in time!", bString[0]);
  238. case (3): format(bString[1], 256, "Nobody was fast enough to write {CFF55F}%s{FFFFFF} in time!", bString[0]);
  239. case (4): format(bString[1], 256, "Nobody answered to the Quiz question! Answer {A9FF40}%s){FFFFFF} %s", Answer, Option[3][Q]);
  240. }
  241. if(strlen(bString[1]))SendClientMessageToAll(~1, bString[1]);
  242. }
  243. bString[0][0] = EOS;
  244. bString[1][0] = EOS;
  245. Winner[0] = EOS;
  246. mString[0] = EOS;
  247.  
  248. bMoney = RandomEx(.Min = 9000, .Max = 7000),
  249. bScore = RandomEx(.Min = 96, .Max = 120);
  250.  
  251. if(!R1)
  252. {
  253. new
  254. N[4];
  255.  
  256. for(new n = 0; n != 4; n++) {N[n] = 15 + random(50);}
  257. switch(random(6))
  258. {
  259. case (0): format(mString, sizeof(mString), "%d+%d-%d-%d",N[0],N[1],N[2],N[3]),
  260. format(bString[0], 256, "%d", N[0] + N[1] - N[2] - N[3]);
  261.  
  262. case (1): format(mString, sizeof(mString), "%d-%d+%d-%d",N[0]+40,N[1],N[2],N[3]),
  263. format(bString[0], 256, "%d", N[0]+40 - N[1] + N[2] - N[3]);
  264.  
  265. case (2): format(mString, sizeof(mString), "%d-%d+%d+%d",N[0]+40,N[1],N[2],N[3]),
  266. format(bString[0], 256, "%d", N[0]+40 - N[1] + N[2] + N[3]);
  267.  
  268. case (3): format(mString, sizeof(mString), "%d+%d+%d+%d",N[0],N[1],N[2],N[3]),
  269. format(bString[0], 256, "%d", N[0] + N[1] + N[2] + N[3]);
  270.  
  271. case (4): format(mString, sizeof(mString), "%d-%d-%d-%d",N[0]+40,N[1],N[2],N[3]),
  272. format(bString[0], 256, "%d", N[0]+40 + N[1] + N[2] + N[3]);
  273.  
  274. case (5): format(mString, sizeof(mString), "%d+%d+%d*%d",N[0],N[1],N[2],N[3]),
  275. format(bString[0], 256, "%d", N[0] + N[1] + N[2] * N[3]);
  276. }
  277. format(bString[1], 256, "First to calculate {CFF55F}%s {FFFFFF}receives {D7FFB8}$%i {FFFFFF}and {D7FFB8}%i{FFFFFF} score.",mString, bMoney, bScore );
  278. SendClientMessageToAll(~1, bString[1] );
  279. bTest = 1;
  280. }
  281. if(R1 == 1)
  282. {
  283. switch(R2)
  284. {
  285. case (0):
  286. {
  287. if(!strcmp(text, "?????"))
  288. memcpy(bString[0], iMessages[random(mCount)], 0, 256, 256);
  289. else memcpy(bString[0], text, 0, 256, 256);
  290.  
  291. bTest = 2;
  292. }
  293.  
  294. case (1):
  295. {
  296. bString[0][0] = EOS;
  297. for( new c; c < MAX_RANDOM; ++c)
  298. {
  299. bString[0][c] = random(2) ? ( '0' + random(9) ) : ( random(2) ? ( 'a' + random(26) ) : ( 'A' + random(26) ) );
  300. }
  301. bTest = 3;
  302. }
  303. }
  304. format(bString[1], 256, "First to write {CFF55F}%s {FFFFFF}receives {D7FFB8}$%i {FFFFFF}and {D7FFB8}%i{FFFFFF} score.",bString[0], bMoney, bScore );
  305. SendClientMessageToAll(~1, bString[1] );
  306. }
  307. if(R1 == 2)
  308. {
  309.  
  310. Q = random(CountQ);
  311. bTest = 4;
  312. SendClientMessageToAll(~1, "-------------------------------------");
  313. format(bString[1], 256, "QUESTION:{FFFFFF} %s", Question[Q]);
  314. SendClientMessageToAll(0xFF0000FF, bString[1]);
  315. switch(random(4))
  316. {
  317.  
  318. case 0:
  319. format(bString[1], 256, "a) {FFFFFF}%s {A9FF40}b) {FFFFFF}%s {A9FF40}c) {FFFFFF}%s {A9FF40}d) {FFFFFF}%s", Option[3][Q],Option[1][Q],Option[2][Q],Option[0][Q]),
  320. Answer[0] = 'a';
  321.  
  322. case 1:
  323. format(bString[1], 256, "a) {FFFFFF}%s {A9FF40}b) {FFFFFF}%s {A9FF40}c) {FFFFFF}%s {A9FF40}d) {FFFFFF}%s", Option[2][Q],Option[3][Q],Option[1][Q],Option[0][Q]),
  324. Answer[0] = 'b';
  325.  
  326. case 2:
  327. format(bString[1], 256, "a) {FFFFFF}%s {A9FF40}b) {FFFFFF}%s {A9FF40}c) {FFFFFF}%s {A9FF40}d) {FFFFFF}%s", Option[2][Q],Option[0][Q],Option[3][Q],Option[1][Q]),
  328. Answer[0] = 'c';
  329.  
  330. case 3:
  331. format(bString[1], 256, "a) {FFFFFF}%s {A9FF40}b) {FFFFFF}%s {A9FF40}c) {FFFFFF}%s {A9FF40}d) {FFFFFF}%s", Option[2][Q],Option[0][Q],Option[1][Q],Option[3][Q]),
  332. Answer[0] = 'd';
  333.  
  334. }
  335. SendClientMessageToAll(0xA9FF40FF, bString[1]);
  336. SendClientMessageToAll(~1, "-------------------------------------");
  337. SendClientMessageToAll(~1, "Use {FFFFFF}/an {C3C3C3}<option>{FFFFFF} to answer!" );
  338. }
  339. Timer = SetTimerEx(#StartReaction, INTERVAL, 1, "dd", random(3), random(2));
  340. ReactionTime = GetTickCount();
  341. }
  342. EndReaction(playerid, action[])
  343. {
  344. GivePlayerMoney(playerid, bMoney);
  345. SetPlayerScore(playerid, GetPlayerScore(playerid) + bScore);
  346.  
  347. if(bTest != 4)
  348. format(bString[1], 256, "Player {58CC00}%s{FFFFFF} %s {58CC00}%s{FFFFFF} first and won {D7FFB8}$%i {FFFFFF}and {D7FFB8}%i{FFFFFF} score.", Name(playerid), action, bString[0], bMoney, bScore);
  349. else if(bTest == 4)
  350. format(bString[1], 256, "Player {58CC00}%s{FFFFFF} %s{FFFFFF}. Answer was {A9FF40}%s) {FFFFFF}%s{FFFFFF}", Name(playerid), action, Answer, Option[3][Q]);
  351.  
  352. for( new i = 0; i != MAX_PLAYERS; ++i){
  353. if(IsPlayerConnected(i)){
  354. if(i != playerid){
  355. SendClientMessage(i, ~1, bString[1] );
  356. }
  357. Lost[i] = false;
  358. }
  359. }
  360.  
  361. format(bString[1], 256, "You were the first one to write the answer, you won {D7FFB8}$%i {FFFFFF}and {D7FFB8}%i{FFFFFF} score.", bMoney, bScore);
  362. SendClientMessage(playerid, ~1, bString[1]);
  363.  
  364. ReactionTime = (GetTickCount() - ReactionTime);
  365. format(bString[1], 256, "You answered in {58CC00}%d{FFFFFF} milliseconds ({58CC00}%d seconds{FFFFFF})",ReactionTime, floatround(ReactionTime * 0.001) );
  366. SendClientMessage(playerid, ~1, bString[1]);
  367.  
  368. bTest = 0;
  369. Won = true;
  370. Winner = Name(playerid);
  371.  
  372. }
  373. public OnPlayerText(playerid, text[])
  374. {
  375. if(bTest){
  376. if(strlen(bString[0])){
  377. if(!strcmp(text, bString[0], false)){
  378. new Str[256];
  379. switch(bTest)
  380. {
  381. case (1):
  382. {
  383. EndReaction(playerid, "calculated");
  384. new File:F = fopen(MATH_WINNERS, io_append);
  385. if(F)
  386. {
  387. format(Str, sizeof(Str), "%s\r\n----------------------------------\r\n\
  388. Calculation: %s\r\n\
  389. Answer: %s\r\n\
  390. Winner: %s\r\n\
  391. Took: %d ms\r\n\
  392. ----------------------------------\r\n\r\n",
  393. Date(),
  394. mString,
  395. bString[0],
  396. Name(playerid),
  397. ReactionTime);
  398. fwrite(F, Str);
  399. fclose(F);
  400. }
  401. }
  402.  
  403. case (2):
  404. {
  405. EndReaction(playerid, "wrote");
  406. new File:F = fopen(MSG_WINNERS, io_append);
  407. if(F)
  408. {
  409. format(Str, sizeof(Str), "%s\r\n----------------------------------\r\n\
  410. Message: %s\r\n\
  411. Winner: %s\r\n\
  412. Took: %d ms\r\n\
  413. ----------------------------------\r\n\r\n",
  414. Date(),
  415. bString[0],
  416. Name(playerid),
  417. ReactionTime);
  418. fwrite(F, Str);
  419. fclose(F);
  420. }
  421. }
  422. case (3):
  423. {
  424. EndReaction(playerid, "was faster at writing");
  425. new File:F = fopen(REACTION_WINNERS, io_append);
  426. if(F)
  427. {
  428. format(Str, sizeof(Str), "%s\r\n----------------------------------\r\n\
  429. Reaction: %s\r\n\
  430. Winner: %s\r\n\
  431. Took: %d ms\r\n\
  432. ----------------------------------\r\n\r\n",
  433. Date(),
  434. bString[0],
  435. Name(playerid),
  436. ReactionTime);
  437. fwrite(F, Str);
  438. fclose(F);
  439. }
  440. }
  441. }
  442. return 0;
  443. }
  444. }
  445. }
  446. else
  447. {
  448. if(strlen(bString[0]))
  449. {
  450. if(!strcmp(text, bString[0], false) && Won){
  451.  
  452. if(!strcmp(Winner, Name(playerid), false)) bString[1] = "You already answered!";
  453. else format(bString[1], 256, "Too late! {58CC00}%s{FFFFFF} answered first!", Winner );
  454.  
  455. SendClientMessage(playerid, ~1, bString[1]);
  456. return 0;
  457. }
  458. }
  459. }
  460.  
  461. return 1;
  462. }
  463.  
  464. Name(i){
  465. new n[24];
  466. GetPlayerName(i,n,24);
  467. return n;
  468. }
  469. stock
  470. RandomEx( Min, Max ){
  471. new Random;
  472. Random = Min + random( Max );
  473. return Random;
  474. }
  475. Date(){
  476. new dStr[30], D[6];
  477. getdate(D[0], D[1], D[2]);
  478. gettime(D[3], D[4], D[5]);
  479. format(dStr, 30, "%d/%d/%d at %d:%d:%d",D[2], D[1], D[0], D[3], D[4], D[5]);
  480. return dStr;
  481. }
  482. #undef INTERVAL
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement