JuSTaR

[CS:GO] Hidon Nostalgia

Jun 21st, 2019
241
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 6.19 KB | None | 0 0
  1. #include <ShopAPI>
  2. #include <sdktools>
  3.  
  4. public Plugin myinfo =
  5. {
  6.     name = "HidoNostalgia",
  7.     author = "JuSTaR",
  8.     description = "Hidonim Nostalgia",
  9.     version = "1.0",
  10.     url = "https://www.fxp.co.il/"
  11. }
  12.  
  13. const int MAX_SONGS = 30; // what? not enough?
  14. const int PRIZE = 120;
  15.  
  16. Handle:HudTimer;
  17. float TimerTick = 1.0;
  18. int DisplayTime = 60;
  19.  
  20. char Song_Path[MAX_SONGS][128];
  21. char Song_Name[MAX_SONGS][64];
  22. char DisplayMsg[128] = "[ Nostalgia Hidon ]\nWhat Is The Name of This Nostalgic Series?";
  23. int SongsLoaded;
  24. int RandomSong_ID;
  25.  
  26. char SpecialChars[] = "yick";
  27. bool isSpecialCase;
  28.  
  29. public OnPluginStart()
  30. {
  31.     RegConsoleCmd("say", LookForAnswer);
  32.     RegAdminCmd("start_hidon_nostalgia", Start_Hidon_Nostalgia, ADMFLAG_RCON);
  33.     RegAdminCmd("stop_hidon_nostalgia", Stop_Hidon_Nostalgia, ADMFLAG_RCON);
  34.  
  35.     RegConsoleCmd("pa", Play_Again);
  36.     RegConsoleCmd("play_again", Play_Again);
  37.     RegConsoleCmd("s", Stop_Music);
  38.     RegConsoleCmd("stop", Stop_Music);
  39.  
  40.     LoadSongsData();
  41. }
  42.  
  43. public Action Play_Again(int client, int arg)
  44. {
  45.     if (HudTimer != null)
  46.     {
  47.         char buffer[64];
  48.         Format(buffer, sizeof(buffer), "%s%s", "*", Song_Path[RandomSong_ID][5]);
  49.         EmitSoundToClient(client, buffer);
  50.     }
  51. }
  52.  
  53. public Action Stop_Music(int client, int arg)
  54. {
  55.     char buffer[64];
  56.     Format(buffer, sizeof(buffer), "%s%s", "*", Song_Path[RandomSong_ID][5]);
  57.     StopSound(client, SNDCHAN_AUTO, buffer);
  58. }
  59.  
  60. public Action Stop_Hidon_Nostalgia(int client, int args)
  61. {
  62.     ResetHidonNostalgia();
  63. }
  64.  
  65. public OnMapStart()
  66. {
  67.     char buffer[64];
  68.  
  69.     for (int i = 0; i < SongsLoaded; i++) // loading count down sounds
  70.     {
  71.         Format(buffer, sizeof(buffer), "%s%s", "*", Song_Path[i][5]);
  72.         PrecacheSound(buffer);
  73.         AddFileToDownloadsTable(Song_Path[i]);
  74.     }
  75. }
  76.  
  77. public Action Start_Hidon_Nostalgia(int client, int args)
  78. {
  79.     if (HudTimer != null)
  80.         ResetHidonNostalgia();
  81.  
  82.     RandomSong_ID = GetRandomInt(0, SongsLoaded-1);
  83.  
  84.     char SpecialChar[1];
  85.  
  86.     for (int i = 0; i < strlen(SpecialChars); i++)
  87.     {
  88.         SpecialChar[0] = SpecialChars[i];
  89.  
  90.         if (StrContains(Song_Name[RandomSong_ID], SpecialChar, false) != -1)
  91.         {
  92.             isSpecialCase = true;
  93.             break;
  94.         }
  95.     }
  96.  
  97.     char buffer[64];
  98.     Format(buffer, sizeof(buffer), "%s%s", "*", Song_Path[RandomSong_ID][5]);
  99.  
  100.     EmitSoundToAll(buffer);
  101.    
  102.     HudTimer = CreateTimer(TimerTick, SetHud, _, TIMER_REPEAT);
  103. }
  104.  
  105. public Action SetHud(Handle:timer)
  106. {
  107.     SetHudTextParams(-1.0, 0.15, 1.0, GetRandomInt(0, 255), GetRandomInt(0, 255), GetRandomInt(0, 255), 255, 1, TimerTick, 0.0, 0.0);
  108.  
  109.     if (DisplayTime > 0)
  110.         ShowHud(DisplayMsg);
  111.     else
  112.     {
  113.         ResetHidonNostalgia();
  114.         PrintToChatAll("[ Nostalgia Hidon ] The answer was %s. Nobody answered correctly.. what a kids..", Song_Name[RandomSong_ID]);
  115.     }
  116.  
  117.     DisplayTime--;
  118. }
  119.  
  120. public void ShowHud(char msg[128])
  121. {
  122.     for(int i = 1; i <= MaxClients; i++) // display hud
  123.         if(IsClientInGame(i) && !IsFakeClient(i))
  124.             ShowHudText(i, -1, msg);
  125. }
  126.  
  127. public Action LookForAnswer(int client, int args)
  128. {
  129.     if (HudTimer != null)
  130.     {
  131.         char arg[64];
  132.         GetCmdArg(1, arg, sizeof(arg));
  133.         bool Winner;
  134.  
  135.         if (isSpecialCase) // if hidon question contains one if the chars: "y"/"i"/"c"/"k", then ignoring those chars
  136.         {
  137.             char fixed_arg[64];
  138.             char fixed_answer[64];
  139.  
  140.             strcopy(fixed_arg, sizeof(fixed_arg), arg);
  141.             strcopy(fixed_answer, sizeof(fixed_answer), Song_Name[RandomSong_ID]);
  142.  
  143.             for (int i = 0; i < strlen(SpecialChars); i++)
  144.             {
  145.                 char SpecialChar[1];
  146.                 SpecialChar[0] = SpecialChars[i];
  147.                 ReplaceString(fixed_arg, sizeof(fixed_arg), SpecialChar, "", false);
  148.                 ReplaceString(fixed_answer, sizeof(fixed_answer), SpecialChar, "", false);
  149.             }
  150.  
  151.             if (StrEqual(fixed_arg, fixed_answer, false) && strlen(arg) == strlen(Song_Name[RandomSong_ID]))
  152.                 Winner = true;
  153.         }
  154.  
  155.         if (StrEqual(arg, Song_Name[RandomSong_ID], false))
  156.             Winner = true;
  157.  
  158.         if (Winner)
  159.         {
  160.             int first_color[4];
  161.             int second_color[4];
  162.  
  163.             for (int i = 0; i < 4; i++)
  164.             {
  165.                 first_color[i] = GetRandomInt(0, 255);
  166.                 second_color[i] = GetRandomInt(0, 255);
  167.             }
  168.  
  169.             SetHudTextParamsEx(-1.0, 0.15, 15.0, first_color, second_color, 2, 1.0, 0.3, 0.3);
  170.             Format(DisplayMsg, sizeof(DisplayMsg), "%s%N%s%d%s", "[ Nostalgia Hidon ]\n", client, " has won ", PRIZE, " Points!");
  171.             ShowHud(DisplayMsg);
  172.  
  173.             PrintToChatAll("[ Nostalgia Hidon ] %N has answered [ %s ], and won %d Points!", client, Song_Name[RandomSong_ID], PRIZE);
  174.  
  175.             Native_GivePoints(client, PRIZE);
  176.  
  177.             ResetHidonNostalgia();
  178.         }
  179.     }
  180. }
  181.  
  182. public void ResetHidonNostalgia()
  183. {
  184.     DisplayTime = 60;
  185.     isSpecialCase = false;
  186.     strcopy(DisplayMsg, sizeof(DisplayMsg), "[ Nostalgia Hidon ]\nWhat Is The Name of This Nostalgic Series?");
  187.  
  188.     if (HudTimer != null)
  189.     {
  190.         KillTimer(HudTimer);
  191.         HudTimer = null;
  192.     }
  193. }
  194.  
  195. public CenterLine(char str[128], int len)
  196. {
  197.     Format(DisplayMsg, sizeof(DisplayMsg), "%s%s", "[ Nostalgia Hidon ]\n", DisplayMsg);
  198.  
  199.     for (int i = 0; i < len; i+=6)
  200.         Format(DisplayMsg, sizeof(DisplayMsg), "%s%s", "\t", str);
  201. }
  202.  
  203. public void LoadSongsData()
  204. {
  205.     new Handle:lines = CreateArray(256);
  206.     char word[64];
  207.     char line[128];
  208.    
  209.     ReadFromConfigFile(lines);
  210.  
  211.     SongsLoaded = GetArraySize(lines);
  212.  
  213.     if (SongsLoaded > 0) // if there are any Hidonim
  214.     {
  215.         for (int i = 0; i < SongsLoaded; i++) // for each Hidon configuration
  216.         {
  217.             GetArrayString(lines, i, line, sizeof(line)); // get Hidon configuration line
  218.  
  219.             int len; // uses to move BreakString crusor - to go to the next word
  220.  
  221.             len = BreakString(line[len], word, sizeof(line)); // get first word in line
  222.             Song_Path[i] = word;
  223.  
  224.             len += BreakString(line[len], word, sizeof(line)); // get second word in line
  225.             Song_Name[i] = word;
  226.         }
  227.     }
  228.     else
  229.         SetFailState("[ Nostalgia Hidon ] No Nostalgia songs were found.");
  230.  
  231.     lines = null;
  232. }
  233.  
  234. public void ReadFromConfigFile(Handle lines)
  235. {
  236.     char path[64] = "addons\\sourcemod\\configs\\Hidonim\\Nostalgia_List.ini";
  237.  
  238.     if (!FileExists(path))
  239.         SetFailState("[ Nostalgia Hidon ] ERROR: Unable to find Nostalgia_List.ini - config file.");
  240.  
  241.     new Handle:file = OpenFile(path, "r");
  242.     char buffer[256];
  243.  
  244.     while (!IsEndOfFile(file) && ReadFileLine(file, buffer, sizeof(buffer)))
  245.         if (StrContains(buffer, "//") == -1)
  246.             PushArrayString(lines, buffer);
  247.  
  248.     CloseHandle(file);
  249. }
Advertisement
Add Comment
Please, Sign In to add comment