Guest User

Untitled

a guest
Aug 14th, 2013
213
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <a_samp>
  2. /* This filterscript is made by Smokey. You can use it if you respect the following conditions:
  3. - You do not remove this text.
  4. - You do not remove the credits.
  5. Credits: Smokey - For the filterscript
  6.          Y_Less - For minrand function
  7.          - WhoEver Made the strtok function
  8. */
  9. #define COLOR_RED 0xFF0000AA
  10. #define COLOR_GREY 0xAFAFAFAA
  11. public OnFilterScriptInit()
  12. {
  13. SetTimer("MathContestRandom", 5*60000, 1);
  14. printf("Smokey's Math Contest Filterscript Loaded.");
  15. }
  16. new math1;
  17. new math2;
  18. new math3;
  19. new mathanswer;
  20. new IsMath;
  21. forward MathContestMinus();
  22. public MathContestMinus()
  23. {
  24. new string[128];
  25. math1 = minrand(100, 300);
  26. math2 = minrand(50, 99);
  27. math3 = random(50);
  28. mathanswer = math1 - math2 - math3;
  29. format(string, sizeof(string), "{66CCCC}SERVER:{FFFFFF} The first one who answers (solve) this {FF002B}%d-%d-%d{F2C80C} wins $2,500", math1, math2, math3);
  30. SendClientMessageToAll(0x66CCCCCC, string);
  31. IsMath = 1;
  32. SetTimer("MathContestEnd", 2*60000, 0);
  33. return 1;
  34. }
  35. forward MathContestPlus();
  36. public MathContestPlus()
  37. {
  38. new string[128];
  39. math1 = minrand(100, 260);
  40. if(math1 >= 200)
  41. {
  42. math2 = minrand(30, 50);
  43. }
  44. else if(math1 < 200)
  45. {
  46. math2 = minrand(50, 99);
  47. }
  48. math3 = random(50);
  49. mathanswer = math1 + math2 + math3;
  50. format(string, sizeof(string), "SERVER:{FFFFFF} The first one who answers (solve) this {FF3333}%d+%d+%d{FFCC00} wins $2,500", math1, math2, math3);
  51. SendClientMessageToAll(0x66CCCCCC, string);
  52. IsMath = 1;
  53. SetTimer("MathContestEnd", 2*60000, 0);
  54. return 1;
  55. }
  56. stock minrand(min, max)
  57. {
  58.     return random(max - min) + min;
  59. }
  60. forward MathContestEnd();
  61. public MathContestEnd()
  62. {
  63. if(IsMath == 1)
  64. {
  65. new string[128];
  66. format(string, sizeof(string), "SERVER: {FFFFFF}No one won the Math Contest the answer is {FF3333}'%d'", mathanswer);
  67. SendClientMessageToAll(0x66CCCCCC, string);
  68. IsMath = 0;
  69. math1 = 0;
  70. math2 = 0;
  71. math3 = 0;
  72. mathanswer = 0;
  73. }
  74. return 1;
  75. }
  76. forward MathContestRandom();
  77. public MathContestRandom()
  78. {
  79.   new randomvar = 0;
  80.   new rand = random(2);
  81.   randomvar = rand;
  82.   if(randomvar == 0)
  83.   {
  84.   MathContestMinus();
  85.   }
  86.   if(randomvar == 1)
  87.   {
  88.   MathContestPlus();
  89.   }
  90.   return 1;
  91. }
  92. public OnPlayerText(playerid, text[])
  93. {
  94.     new pnamee[MAX_PLAYER_NAME];
  95.     new tmp[128];//era 256
  96.     new string[155];//era 256
  97.     if(IsMath == 1)
  98.   {
  99.           new idx;
  100.           tmp = strtok(text, idx);
  101.           new result = strval(tmp);
  102.           if(mathanswer == result)
  103.           {
  104.             GivePlayerMoney(playerid, 2500);
  105.             GetPlayerName(playerid, pnamee, MAX_PLAYER_NAME);
  106.             format(string, sizeof(string), "SERVER: {FF002B}%s(%d){FFFFFF} won the {F2C80C}Math Contest{FFFFFF}, He/She won the {F2C80C}$2500{FFFFFF} [ Answer: %d ]",pnamee, playerid, mathanswer);
  107.             SendClientMessageToAll(0x66CCCCCC, string);
  108.             IsMath = 0;
  109.             mathanswer = 0;
  110.             math1 = 0;
  111.             math2 = 0;
  112.             math3 = 0;
  113.            }
  114.    }
  115.     return 1;
  116. }
  117. public OnPlayerCommandText(playerid, cmdtext[])
  118. {
  119.     new string[128];
  120.     new cmd[128];
  121.     new idx;
  122.     cmd = strtok(cmdtext, idx);
  123.     //---------------------------------------------------------------------------------------------------------------------------------------
  124.     if(strcmp(cmd, "/startmath", true) == 0)
  125.     {
  126.     if(IsPlayerConnected(playerid))
  127.     {
  128.     if(IsPlayerAdmin(playerid))
  129.     {
  130.     MathContestRandom();
  131.     }
  132.     else
  133.     {
  134.     SendClientMessage(playerid, COLOR_RED, "<> You are not authorized to use this command!");
  135.     }
  136.     }
  137.     return 1;
  138.     }
  139.     if(strcmp(cmd, "/mathanswer", true) == 0)
  140.     {
  141.     if(IsPlayerConnected(playerid))
  142.     {
  143.     if(IsPlayerAdmin(playerid))
  144.     {
  145.     format(string, sizeof(string), "math answer: %d", mathanswer);
  146.     SendClientMessage(playerid, COLOR_GREY, string);
  147.     }
  148.     else
  149.     {
  150.     SendClientMessage(playerid, COLOR_GREY, "<> You are not authorized to use this command!");
  151.     }
  152.     }
  153.     return 1;
  154.     }
  155.     return 0;
  156. }
  157. strtok(const string[], &index)
  158. {
  159.     new length = strlen(string);
  160.     while ((index < length) && (string[index] <= ' '))
  161.     {
  162.         index++;
  163.     }
  164.  
  165.     new offset = index;
  166.     new result[20];
  167.     while ((index < length) && (string[index] > ' ') && ((index - offset) < (sizeof(result) - 1)))
  168.     {
  169.         result[index - offset] = string[index];
  170.         index++;
  171.     }
  172.     result[index - offset] = EOS;
  173.     return result;
  174. }
Advertisement
Add Comment
Please, Sign In to add comment