JuSTaR

[CS:GO] Hidon Anime

Jun 21st, 2019
404
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 4.82 KB | None | 0 0
  1. #include <ShopAPI>
  2. #include <sdktools>
  3.  
  4. public Plugin myinfo =
  5. {
  6.     name = "HidonAnime",
  7.     author = "JuSTaR",
  8.     description = "Hidonim Anime",
  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 = 140;
  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 Anime Series?";
  23. int SongsLoaded;
  24. int RandomSong_ID;
  25.  
  26. public OnPluginStart()
  27. {
  28.     RegConsoleCmd("say", LookForAnswer);
  29.     RegAdminCmd("start_hidon_anime", Start_Hidon_Anime, ADMFLAG_RCON);
  30.     RegAdminCmd("stop_hidon_anime", Stop_Hidon_Anime, ADMFLAG_RCON);
  31.  
  32.     RegConsoleCmd("pa", Play_Again);
  33.     RegConsoleCmd("play_again", Play_Again);
  34.     RegConsoleCmd("s", Stop_Music);
  35.     RegConsoleCmd("stop", Stop_Music);
  36.    
  37.     LoadSongsData();
  38. }
  39.  
  40. public Action Play_Again(int client, int arg)
  41. {
  42.     if (HudTimer != null)
  43.     {
  44.         char buffer[64];
  45.         Format(buffer, sizeof(buffer), "%s%s", "*", Song_Path[RandomSong_ID][5]);
  46.         EmitSoundToClient(client, buffer);
  47.     }
  48. }
  49.  
  50. public Action Stop_Music(int client, int arg)
  51. {
  52.     char buffer[64];
  53.     Format(buffer, sizeof(buffer), "%s%s", "*", Song_Path[RandomSong_ID][5]);
  54.     StopSound(client, SNDCHAN_AUTO, buffer);
  55. }
  56.  
  57. public Action Stop_Hidon_Anime(int client, int args)
  58. {
  59.     ResetHidonAnime();
  60. }
  61.  
  62. public OnMapStart()
  63. {
  64.     char buffer[64];
  65.  
  66.     for (int i = 0; i < SongsLoaded; i++) // loading count down sounds
  67.     {
  68.         Format(buffer, sizeof(buffer), "%s%s", "*", Song_Path[i][5]);
  69.         PrecacheSound(buffer);
  70.         AddFileToDownloadsTable(Song_Path[i]);
  71.     }
  72. }
  73.  
  74. public Action Start_Hidon_Anime(int client, int args)
  75. {
  76.     if (HudTimer != null)
  77.         ResetHidonAnime();
  78.  
  79.     RandomSong_ID = GetRandomInt(0, SongsLoaded-1);
  80.  
  81.     char buffer[64];
  82.     Format(buffer, sizeof(buffer), "%s%s", "*", Song_Path[RandomSong_ID][5]);
  83.  
  84.     EmitSoundToAll(buffer);
  85.    
  86.     HudTimer = CreateTimer(TimerTick, SetHud, _, TIMER_REPEAT);
  87. }
  88.  
  89. public Action SetHud(Handle:timer)
  90. {
  91.     SetHudTextParams(-1.0, 0.15, 1.0, GetRandomInt(0, 255), GetRandomInt(0, 255), GetRandomInt(0, 255), 255, 1, TimerTick, 0.0, 0.0);
  92.  
  93.     if (DisplayTime > 0)
  94.         ShowHud(DisplayMsg);
  95.     else
  96.     {
  97.         ResetHidonAnime();
  98.         PrintToChatAll("[ Anime Hidon ] The answer was %s. Nobody answered correctly.. what a nerds..", Song_Name[RandomSong_ID]);
  99.     }
  100.  
  101.     DisplayTime--;
  102. }
  103.  
  104. public void ShowHud(char msg[128])
  105. {
  106.     for(new i = 1; i <= MaxClients; i++) // display hud
  107.         if(IsClientInGame(i) && !IsFakeClient(i))
  108.             ShowHudText(i, -1, msg);
  109. }
  110.  
  111. public Action LookForAnswer(int client, int args)
  112. {
  113.     if (HudTimer != null)
  114.     {
  115.         char arg[64];
  116.         GetCmdArg(1, arg, sizeof(arg));
  117.  
  118.         if (StrEqual(arg, Song_Name[RandomSong_ID], false))
  119.         {
  120.             int first_color[4];
  121.             int second_color[4];
  122.  
  123.             for (int i = 0; i < 4; i++)
  124.             {
  125.                 first_color[i] = GetRandomInt(0, 255);
  126.                 second_color[i] = GetRandomInt(0, 255);
  127.             }
  128.  
  129.             SetHudTextParamsEx(-1.0, 0.15, 15.0, first_color, second_color, 2, 1.0, 0.3, 0.3);
  130.             Format(DisplayMsg, sizeof(DisplayMsg), "%s%N%s%d%s", "[ Anime Hidon ]\n", client, " has won ", PRIZE, " Points!");
  131.             ShowHud(DisplayMsg);
  132.  
  133.             PrintToChatAll("[ Anime Hidon ] %N has answered [ %s ], and won %d Points!", client, Song_Name[RandomSong_ID], PRIZE);
  134.  
  135.             Native_GivePoints(client, PRIZE);
  136.  
  137.             ResetHidonAnime();
  138.         }
  139.     }
  140. }
  141.  
  142. public void ResetHidonAnime()
  143. {
  144.     DisplayTime = 60;
  145.     strcopy(DisplayMsg, sizeof(DisplayMsg), "[ Nostalgia Hidon ]\nWhat Is The Name of This Anime Series?");
  146.  
  147.     if (HudTimer != null)
  148.     {
  149.         KillTimer(HudTimer);
  150.         HudTimer = null;
  151.     }
  152. }
  153.  
  154. public void LoadSongsData()
  155. {
  156.     new Handle:lines = CreateArray(256);
  157.     char word[64];
  158.     char line[128];
  159.    
  160.     ReadFromConfigFile(lines);
  161.  
  162.     SongsLoaded = GetArraySize(lines);
  163.  
  164.     if (SongsLoaded > 0) // if there are any Hidonim
  165.     {
  166.         for (int i = 0; i < SongsLoaded; i++) // for each Hidon configuration
  167.         {
  168.             GetArrayString(lines, i, line, sizeof(line)); // get Hidon configuration line
  169.  
  170.             int len; // uses to move BreakString crusor - to go to the next word
  171.  
  172.             len = BreakString(line[len], word, sizeof(line)); // get first word in line
  173.             Song_Path[i] = word;
  174.  
  175.             len += BreakString(line[len], word, sizeof(line)); // get second word in line
  176.             Song_Name[i] = word;
  177.         }
  178.     }
  179.     else
  180.         SetFailState("[ Anime Hidon ] No Anime songs were found.");
  181.  
  182.     lines = null;
  183. }
  184.  
  185. public void ReadFromConfigFile(Handle lines)
  186. {
  187.     char path[64] = "addons\\sourcemod\\configs\\Hidonim\\Anime_List.ini";
  188.  
  189.     if (!FileExists(path))
  190.         SetFailState("[ Anime Hidon ] ERROR: Unable to find Anime_List.ini - config file.");
  191.  
  192.     new Handle:file = OpenFile(path, "r");
  193.     char buffer[256];
  194.  
  195.     while (!IsEndOfFile(file) && ReadFileLine(file, buffer, sizeof(buffer)))
  196.         if (StrContains(buffer, "//") == -1)
  197.             PushArrayString(lines, buffer);
  198.  
  199.     CloseHandle(file);
  200. }
Advertisement
Add Comment
Please, Sign In to add comment