JuSTaR

[CS:GO] Hidon Math

Jun 21st, 2019
240
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 2.62 KB | None | 0 0
  1. #include <ShopAPI>
  2. #include <sdktools>
  3.  
  4. public Plugin myinfo =
  5. {
  6.     name = "HidonMath",
  7.     author = "JuSTaR",
  8.     description = "Hidonim Math",
  9.     version = "1.0",
  10.     url = "https://www.fxp.co.il/"
  11. }
  12.  
  13. const int MAX_NUMBER = 999;
  14. const int MIN_NUMBER = 100;
  15. const int PRIZE = 100;
  16.  
  17. Handle:HudTimer;
  18.  
  19. int DisplayTime = 60;
  20. float TimerTick = 1.0;
  21. char DisplayMsg[64];
  22. char Answer[8];
  23.  
  24. public OnPluginStart()
  25. {
  26.     RegConsoleCmd("say", LookForAnswer);
  27.     RegAdminCmd("start_hidon_math", Start_Hidon_Math, ADMFLAG_RCON);
  28.     RegAdminCmd("stop_hidon_math", Stop_Hidon_Math, ADMFLAG_RCON);
  29. }
  30.  
  31. public Action Stop_Hidon_Math(int client, int args)
  32. {
  33.     Reset_Hidon_Math();
  34. }
  35.  
  36. public Action Start_Hidon_Math(int client, int args)
  37. {
  38.     if (HudTimer != null)
  39.         Reset_Hidon_Math();
  40.  
  41.     int num1 =  GetRandomInt(MIN_NUMBER, MAX_NUMBER);
  42.     int num2 =  GetRandomInt(MIN_NUMBER, MAX_NUMBER);
  43.  
  44.     Format(DisplayMsg, sizeof(DisplayMsg), "%s%d%s%d%s", "[ Math Hidon ]\nHow much is: ", num1, " + ", num2, "?");
  45.  
  46.     IntToString(num1 + num2, Answer, sizeof(Answer));
  47.  
  48.     HudTimer = CreateTimer(TimerTick, SetHud, _, TIMER_REPEAT);
  49.     PrintToChatAll("[ Math Hidon ] How much is: %d + %d?", num1, num2);
  50. }
  51.  
  52. public Action SetHud(Handle:timer)
  53. {
  54.     SetHudTextParams(-1.0, 0.15, 1.0, GetRandomInt(0, 255), GetRandomInt(0, 255), GetRandomInt(0, 255), 255, 1, TimerTick, 0.0, 0.0);
  55.  
  56.     if (DisplayTime > 0)
  57.         ShowHud(DisplayMsg);
  58.     else
  59.     {
  60.         Reset_Hidon_Math();
  61.         PrintToChatAll("[ Math Hidon ] The answer was %s. Nobody answered correctly.. what a shame..", Answer);
  62.     }
  63.  
  64.     DisplayTime--;
  65. }
  66.  
  67. public void ShowHud(char msg[64])
  68. {
  69.     for(new i = 1; i <= MaxClients; i++) // display hud
  70.         if(IsClientInGame(i) && !IsFakeClient(i))
  71.             ShowHudText(i, -1, msg);
  72. }
  73.  
  74. public void Reset_Hidon_Math()
  75. {
  76.     if (HudTimer != null)
  77.     {
  78.         KillTimer(HudTimer);
  79.         HudTimer = null;
  80.     }
  81.  
  82.     DisplayTime = 60;
  83. }
  84.  
  85. public Action LookForAnswer(int client, int args)
  86. {
  87.     if (HudTimer != null)
  88.     {
  89.         char arg[64];
  90.         GetCmdArg(1, arg, sizeof(arg));
  91.  
  92.         if (StrEqual(arg, Answer, false))
  93.         {
  94.             int first_color[4];
  95.             int second_color[4];
  96.  
  97.             for (int i = 0; i < 4; i++)
  98.             {
  99.                 first_color[i] = GetRandomInt(0, 255);
  100.                 second_color[i] = GetRandomInt(0, 255);
  101.             }
  102.  
  103.             Reset_Hidon_Math();
  104.  
  105.             SetHudTextParamsEx(-1.0, 0.15, 15.0, first_color, second_color, 2, 1.0, 0.3, 0.3);
  106.             Format(DisplayMsg, sizeof(DisplayMsg), "%s%N%s%d%s", "[ Math Hidon ]\n", client, " has won ", PRIZE, " Points!");
  107.             ShowHud(DisplayMsg);
  108.  
  109.             PrintToChatAll("[ Math Hidon ] %N has answered [ %s ], and won %d Points!", client, Answer, PRIZE);
  110.  
  111.             Native_GivePoints(client, PRIZE);
  112.         }
  113.     }
  114.  
  115.     return;
  116. }
Advertisement
Add Comment
Please, Sign In to add comment