HLMOD.HU Forrás Megtekintés - www.hlmod.hu
  1. #include <amxmodx>
  2. #include <colorchat>
  3.  
  4. new const PLUGIN[] = "Funny Sounds";
  5. new const VERSION[] = "1.0";
  6. new const AUTHOR[] = "mforce";
  7.  
  8.  
  9. new const PREFIX[] = "Funny Sounds";
  10.  
  11. #define ACCESS_FLAG ADMIN_KICK // - Type // before # if you want it for all players.
  12. #define TIME_BETWEEN_SOUNDS 30 // - in seconds
  13.  
  14.  
  15. new Trie:musiclist
  16. new g_iTimeExpired[33], bool:g_iSwitchOff[33];
  17.  
  18. public plugin_init() {
  19. register_plugin(PLUGIN, VERSION, AUTHOR);
  20. register_dictionary("funny_sounds.txt");
  21.  
  22. register_clcmd("say", "sayhandler");
  23. register_clcmd("say_team", "sayhandler");
  24. register_clcmd("say /sounds", "sound_switchoff");
  25. set_task(300.0, "toswitchoff", 0, .flags="b")
  26. }
  27.  
  28. public toswitchoff() {
  29. ColorChat(0, NORMAL, "^4[%s]^1 %L ^3/sounds", PREFIX, LANG_SERVER, "TO_SWTICH_OFF");
  30. }
  31.  
  32. public plugin_precache() {
  33. musiclist = TrieCreate()
  34.  
  35. new sBuffer[256], sFile[64], sData[2][32], pFile;
  36.  
  37. get_localinfo("amxx_configsdir", sFile, charsmax(sFile));
  38. format(sFile, charsmax(sFile), "%s/funny_sounds.ini", sFile);
  39.  
  40. pFile = fopen(sFile, "rt");
  41.  
  42. if(pFile) {
  43. while(!feof(pFile)) {
  44. fgets(pFile, sBuffer, charsmax(sBuffer));
  45. trim(sBuffer);
  46. if(sBuffer[0] == ';') continue;
  47.  
  48. parse(sBuffer, sData[0], charsmax(sData[]), sData[1], charsmax(sData[]));
  49.  
  50. if((containi(sData[1], ".mp3") != -1 || containi(sData[1], ".wav") != -1) && !TrieKeyExists(musiclist, sData[0])) {
  51. precache_sound(sData[1])
  52. TrieSetString(musiclist, sData[0], sData[1]);
  53. }
  54. }
  55. fclose(pFile);
  56. }
  57. else write_file(sFile, ";^"anything^" ^"any_dir/anything.mp3^"^n");
  58. }
  59.  
  60. public sayhandler(id) {
  61. #if defined ACCESS_FLAG
  62. if(~get_user_flags(id) & ACCESS_FLAG) return;
  63. #endif
  64.  
  65. new message[190]; read_args(message, charsmax(message));
  66. remove_quotes(message);
  67.  
  68. if(TrieKeyExists(musiclist, message)) {
  69. new usrtime = get_user_time(id);
  70.  
  71. if(usrtime >= g_iTimeExpired[id]) {
  72. new szSound[64];
  73. TrieGetString(musiclist, message, szSound, charsmax(szSound));
  74. playsound(szSound);
  75. g_iTimeExpired[id] = (usrtime + TIME_BETWEEN_SOUNDS);
  76. }
  77. else
  78. ColorChat(id, NORMAL, "^4[%s]^1 %L", PREFIX, LANG_SERVER, "YOU_HAVE_TO_WAIT" , (g_iTimeExpired[id] - usrtime));
  79. }
  80. }
  81.  
  82. playsound(const szSound[]) {
  83. new makesound[256];
  84. if(containi(szSound, ".mp3") != -1)
  85. formatex(makesound, charsmax(makesound), "mp3 play ^"sound/%s^"", szSound);
  86. else
  87. formatex(makesound, charsmax(makesound), "spk ^"%s^"", szSound);
  88.  
  89.  
  90. new players[32], num, tempid;
  91. get_players(players, num, "c");
  92. for(new i; i<num; i++) {
  93. tempid = players[i];
  94. if(!g_iSwitchOff[tempid])
  95. client_cmd(tempid, "%s", makesound);
  96. }
  97. }
  98.  
  99. public sound_switchoff(id) {
  100. switch(g_iSwitchOff[id]) {
  101. case false: {
  102. g_iSwitchOff[id] = true;
  103. client_cmd(id, "setinfo _funnysoundsoff 1");
  104. ColorChat(id, NORMAL, "^4[%s]^3 %L", PREFIX, LANG_SERVER, "SOUNDS_SWITCHED_OFF");
  105. }
  106. case true: {
  107. g_iSwitchOff[id] = false;
  108. client_cmd(id, "setinfo _funnysoundsoff 0");
  109. ColorChat(id, NORMAL, "^4[%s]^3 %L", PREFIX, LANG_SERVER, "SOUNDS_SWITCHED_ON");
  110. }
  111. }
  112. }
  113.  
  114. public client_putinserver(id) {
  115. if(is_user_sounds_off(id))
  116. g_iSwitchOff[id] = true;
  117. }
  118.  
  119. public client_disconnect(id) {
  120. g_iTimeExpired[id] = 0;
  121. g_iSwitchOff[id] = false;
  122. }
  123.  
  124. public plugin_end() {
  125. TrieDestroy(musiclist);
  126. }
  127.  
  128. stock bool:is_user_sounds_off(id) {
  129. new switcher[8];
  130. get_user_info(id, "_funnysoundsoff", switcher, charsmax(switcher));
  131. if(equal(switcher, "1")) return true;
  132. return false;
  133. }