Advertisement
Guest User

Abner Res

a guest
Mar 1st, 2017
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.59 KB | None | 0 0
  1. #include <sourcemod>
  2. #include <sdktools>
  3. #include <colors>
  4. #include <clientprefs>
  5. #include <cstrike>
  6.  
  7. #pragma newdecls required // 2015 rules
  8. #pragma semicolon 1
  9. #define PLUGIN_VERSION "3.4"
  10.  
  11. //MapSounds Stuff
  12. int g_iSoundEnts[2048];
  13. int g_iNumSounds;
  14.  
  15. //Cvars
  16. Handle g_hCTPath;
  17. Handle g_hTRPath;
  18. Handle g_hPlayType;
  19. Handle g_AbNeRCookie;
  20. Handle g_hStop;
  21. Handle g_PlayPrint;
  22. Handle g_roundDrawPlay;
  23. Handle g_ClientSettings; //Adicionado na versão v3.4 para definir se o jogador pode ou não escolher se quer ouvir os sons.
  24.  
  25. bool SoundsTRSucess = false;
  26. bool SoundsCTSucess = false;
  27. bool SamePath = false;
  28. bool CSGO;
  29. //Sounds Arrays
  30. ArrayList ctSound;
  31. ArrayList trSound;
  32.  
  33. public Plugin myinfo =
  34. {
  35. name = "[CS:GO/CSS] AbNeR Round End Sounds Simple",
  36. author = "AbNeR_CSS",
  37. description = "Play cool musics when round ends!",
  38. version = PLUGIN_VERSION,
  39. url = "http://www.tecnohardclan.com/forum/"
  40. }
  41.  
  42. public void OnPluginStart()
  43. {
  44. //Cvars
  45. CreateConVar("abner_res_version", PLUGIN_VERSION, "Plugin version", FCVAR_NOTIFY|FCVAR_REPLICATED);
  46. g_hTRPath = CreateConVar("res_tr_path", "misc/tecnohard", "Path off tr sounds in /cstrike/sound");
  47. g_hCTPath = CreateConVar("res_ct_path", "misc/tecnohard", "Path off ct sounds in /cstrike/sound");
  48. g_hPlayType = CreateConVar("res_play_type", "1", "1 - Random, 2- Play in queue");
  49. g_hStop = CreateConVar("res_stop_map_music", "1", "Stop map musics");
  50. g_PlayPrint = CreateConVar("res_print_to_chat_mp3_name", "1", "Print mp3 name in chat (Suggested by m22b)");
  51. g_roundDrawPlay = CreateConVar("res_rounddraw_play", "0", "0 - Don´t play sounds, 1 - Play TR sounds, 2 - Play CT sounds.");
  52. g_ClientSettings = CreateConVar("res_client_preferences", "1", "Enable/Disable client preferences");
  53.  
  54. //ClientPrefs
  55. g_AbNeRCookie = RegClientCookie("AbNeR Round End Sounds", "", CookieAccess_Private);
  56. SetCookieMenuItem(SoundCookieHandler, 0, "AbNeR Round End Sounds");
  57.  
  58. LoadTranslations("common.phrases");
  59. LoadTranslations("abner_res.phrases");
  60. AutoExecConfig(true, "abner_res");
  61.  
  62. RegAdminCmd("res_refresh", CommandLoad, ADMFLAG_SLAY);
  63. RegConsoleCmd("res", abnermenu);
  64.  
  65. HookConVarChange(g_hTRPath, PathChange);
  66. HookConVarChange(g_hCTPath, PathChange);
  67. HookConVarChange(g_hPlayType, PathChange);
  68.  
  69. char theFolder[40];
  70. GetGameFolderName(theFolder, sizeof(theFolder));
  71. CSGO = StrEqual(theFolder, ("csgo"));
  72. HookEvent("round_start", Event_RoundStart, EventHookMode_PostNoCopy);
  73. HookEvent("round_end", Event_RoundEnd);
  74.  
  75. ctSound = new ArrayList(512);
  76. trSound = new ArrayList(512);
  77. }
  78.  
  79. stock bool IsValidClient(int client)
  80. {
  81. if(client <= 0 ) return false;
  82. if(client > MaxClients) return false;
  83. if(!IsClientConnected(client)) return false;
  84. return IsClientInGame(client);
  85. }
  86.  
  87. public void StopMapMusic()
  88. {
  89. char sSound[PLATFORM_MAX_PATH];
  90. int entity = INVALID_ENT_REFERENCE;
  91. for(int i=1;i<=MaxClients;i++){
  92. if(!IsClientInGame(i)){ continue; }
  93. for (int u=0; u<g_iNumSounds; u++){
  94. entity = EntRefToEntIndex(g_iSoundEnts[u]);
  95. if (entity != INVALID_ENT_REFERENCE){
  96. GetEntPropString(entity, Prop_Data, "m_iszSound", sSound, sizeof(sSound));
  97. Client_StopSound(i, entity, SNDCHAN_STATIC, sSound);
  98. }
  99. }
  100. }
  101. }
  102.  
  103. stock void Client_StopSound(int client, int entity, int channel, const char[] name)
  104. {
  105. EmitSoundToClient(client, name, entity, channel, SNDLEVEL_NONE, SND_STOP, 0.0, SNDPITCH_NORMAL, _, _, _, true);
  106. }
  107.  
  108. public void Event_RoundEnd(Handle event, const char[] name, bool dontBroadcast)
  109. {
  110. int winner = GetEventInt(event, "winner");
  111. if(winner != 2 && winner != 3) //Validação para round draw
  112. {
  113. if(GetConVarInt(g_roundDrawPlay) == 1) winner = CS_TEAM_T;
  114. else if(GetConVarInt(g_roundDrawPlay) == 2) winner = CS_TEAM_CT;
  115. }
  116.  
  117. if((winner == CS_TEAM_CT && SamePath) || winner == CS_TEAM_T)
  118. {
  119. if(SoundsTRSucess)
  120. {
  121. PlaySoundTR();
  122. }
  123. else
  124. {
  125. if(!SamePath)
  126. {
  127. PrintToServer("[ElementalGamingPT] TR_SOUNDS ERROR: Sounds not loaded.");
  128. CPrintToChatAll("{green}[ElementalGamingPT] {default}TR_SOUNDS ERROR: Sounds not loaded.");
  129. }
  130. else
  131. {
  132. PrintToServer("[ElementalGamingPT] SOUNDS ERROR: Sounds not loaded.");
  133. CPrintToChatAll("{green}[ElementalGamingPT] {default}SOUNDS ERROR: Sounds not loaded.");
  134. }
  135. return;
  136. }
  137. }
  138. else if(winner == CS_TEAM_CT)
  139. {
  140. if(SoundsCTSucess)
  141. {
  142. PlaySoundCT();
  143. }
  144. else
  145. {
  146. PrintToServer("[ElementalGamingPT] CT_SOUNDS ERROR: Sounds not loaded.");
  147. CPrintToChatAll("{green}[ElementalGamingPT] {default}CT_SOUNDS ERROR: Sounds not loaded.");
  148. return;
  149. }
  150. }
  151.  
  152. if(GetConVarInt(g_hStop) == 1)
  153. StopMapMusic();
  154. }
  155.  
  156. public void Event_RoundStart(Handle event, const char[] name, bool dontBroadcast)
  157. {
  158. if(GetConVarInt(g_hStop) == 1)
  159. {
  160. // Ents are recreated every round.
  161. g_iNumSounds = 0;
  162.  
  163. // Find all ambient sounds played by the map.
  164. char sSound[PLATFORM_MAX_PATH];
  165. int entity = INVALID_ENT_REFERENCE;
  166.  
  167. while ((entity = FindEntityByClassname(entity, "ambient_generic")) != INVALID_ENT_REFERENCE)
  168. {
  169. GetEntPropString(entity, Prop_Data, "m_iszSound", sSound, sizeof(sSound));
  170.  
  171. int len = strlen(sSound);
  172. if (len > 4 && (StrEqual(sSound[len-3], "mp3") || StrEqual(sSound[len-3], "wav")))
  173. {
  174. g_iSoundEnts[g_iNumSounds++] = EntIndexToEntRef(entity);
  175. }
  176. }
  177. }
  178. }
  179.  
  180. public void SoundCookieHandler(int client, CookieMenuAction action, any info, char[] buffer, int maxlen)
  181. {
  182. abnermenu(client, 0);
  183. }
  184.  
  185. public void OnClientPutInServer(int client)
  186. {
  187. if(GetConVarInt(g_ClientSettings) == 1)
  188. {
  189. CreateTimer(3.0, msg, client);
  190. }
  191. }
  192.  
  193. public Action msg(Handle timer, any client)
  194. {
  195. if(IsValidClient(client))
  196. {
  197. CPrintToChat(client, "{default}{green}[ElementalGamingPT] {default}%t", "JoinMsg");
  198. }
  199. }
  200.  
  201. public Action abnermenu(int client, int args)
  202. {
  203. if(GetConVarInt(g_ClientSettings) != 1)
  204. {
  205. return Plugin_Handled;
  206. }
  207.  
  208. int cookievalue = GetIntCookie(client, g_AbNeRCookie);
  209. Handle g_AbNeRMenu = CreateMenu(AbNeRMenuHandler);
  210. SetMenuTitle(g_AbNeRMenu, "Round End Sounds by AbNeR_CSS");
  211. char Item[128];
  212. if(cookievalue == 0)
  213. {
  214. Format(Item, sizeof(Item), "%t %t", "RES_ON", "Selected");
  215. AddMenuItem(g_AbNeRMenu, "ON", Item);
  216. Format(Item, sizeof(Item), "%t", "RES_OFF");
  217. AddMenuItem(g_AbNeRMenu, "OFF", Item);
  218. }
  219. else
  220. {
  221. Format(Item, sizeof(Item), "%t", "RES_ON");
  222. AddMenuItem(g_AbNeRMenu, "ON", Item);
  223. Format(Item, sizeof(Item), "%t %t", "RES_OFF", "Selected");
  224. AddMenuItem(g_AbNeRMenu, "OFF", Item);
  225. }
  226. SetMenuExitBackButton(g_AbNeRMenu, true);
  227. SetMenuExitButton(g_AbNeRMenu, true);
  228. DisplayMenu(g_AbNeRMenu, client, 30);
  229. return Plugin_Continue;
  230. }
  231.  
  232. public int AbNeRMenuHandler(Handle menu, MenuAction action, int param1, int param2)
  233. {
  234. Handle g_AbNeRMenu = CreateMenu(AbNeRMenuHandler);
  235. if (action == MenuAction_DrawItem)
  236. {
  237. return ITEMDRAW_DEFAULT;
  238. }
  239. else if(param2 == MenuCancel_ExitBack)
  240. {
  241. ShowCookieMenu(param1);
  242. }
  243. else if (action == MenuAction_Select)
  244. {
  245. switch (param2)
  246. {
  247. case 0:
  248. {
  249. SetClientCookie(param1, g_AbNeRCookie, "0");
  250. abnermenu(param1, 0);
  251. }
  252. case 1:
  253. {
  254. SetClientCookie(param1, g_AbNeRCookie, "1");
  255. abnermenu(param1, 0);
  256. }
  257. }
  258. CloseHandle(g_AbNeRMenu);
  259. }
  260. return 0;
  261. }
  262.  
  263. public void PathChange(Handle cvar, const char[] oldVal, const char[] newVal)
  264. {
  265. RefreshSounds(0);
  266. }
  267.  
  268. public void OnConfigsExecuted()
  269. {
  270. RefreshSounds(0);
  271. }
  272.  
  273. void RefreshSounds(int client)
  274. {
  275. char soundpath[PLATFORM_MAX_PATH];
  276. char soundpath2[PLATFORM_MAX_PATH];
  277. GetConVarString(g_hTRPath, soundpath, sizeof(soundpath));
  278. GetConVarString(g_hCTPath, soundpath2, sizeof(soundpath2));
  279. SamePath = StrEqual(soundpath, soundpath2);
  280. int size;
  281. if(SamePath)
  282. {
  283. size = LoadSoundsTR();
  284. SoundsTRSucess = (size > 0);
  285. if(SoundsTRSucess)
  286. {
  287. ReplyToCommand(client, "[ElementalGamingPT] SOUNDS: %d sounds loaded.", size);
  288. }
  289. else
  290. {
  291. ReplyToCommand(client, "[ElementalGamingPT] INVALID SOUND PATH.");
  292. }
  293. }
  294. else
  295. {
  296. size = LoadSoundsTR();
  297. SoundsTRSucess = (size > 0);
  298. if(SoundsTRSucess)
  299. {
  300. ReplyToCommand(client, "[AbNeR RES] TR_SOUNDS: %d sounds loaded.", size);
  301. }
  302. else
  303. {
  304. ReplyToCommand(client, "[AbNeR RES] INVALID TR SOUND PATH.");
  305. }
  306.  
  307. size = LoadSoundsCT();
  308. SoundsCTSucess = (size > 0);
  309. if(SoundsCTSucess)
  310. {
  311. ReplyToCommand(client, "[AbNeR RES] CT_SOUNDS: %d sounds loaded.", size);
  312. }
  313. else
  314. {
  315. ReplyToCommand(client, "[AbNeR RES] INVALID CT SOUND PATH.");
  316. }
  317. }
  318. }
  319.  
  320. int LoadSoundsCT()
  321. {
  322. ctSound.Clear();
  323. char name[128];
  324. char soundname[512];
  325. char soundpath[PLATFORM_MAX_PATH];
  326. char soundpath2[PLATFORM_MAX_PATH];
  327. GetConVarString(g_hCTPath, soundpath, sizeof(soundpath));
  328. Format(soundpath2, sizeof(soundpath2), "sound/%s/", soundpath);
  329. Handle pluginsdir = OpenDirectory(soundpath2);
  330. if(pluginsdir != INVALID_HANDLE)
  331. {
  332. while(ReadDirEntry(pluginsdir,name,sizeof(name)))
  333. {
  334. int namelen = strlen(name) - 4;
  335. if(StrContains(name,".mp3",false) == namelen)
  336. {
  337. Format(soundname, sizeof(soundname), "sound/%s/%s", soundpath, name);
  338. AddFileToDownloadsTable(soundname);
  339. Format(soundname, sizeof(soundname), "%s/%s", soundpath, name);
  340. ctSound.PushString(soundname);
  341. }
  342. }
  343. }
  344. return ctSound.Length;
  345. }
  346.  
  347. int LoadSoundsTR()
  348. {
  349. trSound.Clear();
  350. char name[128];
  351. char soundname[512];
  352. char soundpath[PLATFORM_MAX_PATH];
  353. char soundpath2[PLATFORM_MAX_PATH];
  354. GetConVarString(g_hTRPath, soundpath, sizeof(soundpath));
  355. Format(soundpath2, sizeof(soundpath2), "sound/%s/", soundpath);
  356. Handle pluginsdir = OpenDirectory(soundpath2);
  357. if(pluginsdir != INVALID_HANDLE)
  358. {
  359. while(ReadDirEntry(pluginsdir,name,sizeof(name)))
  360. {
  361. int namelen = strlen(name) - 4;
  362. if(StrContains(name,".mp3",false) == namelen)
  363. {
  364. Format(soundname, sizeof(soundname), "sound/%s/%s", soundpath, name);
  365. AddFileToDownloadsTable(soundname);
  366. Format(soundname, sizeof(soundname), "%s/%s", soundpath, name);
  367. trSound.PushString(soundname);
  368. }
  369. }
  370. }
  371. return trSound.Length;
  372. }
  373.  
  374. void PlaySoundCT()
  375. {
  376. int soundToPlay = 0;
  377. if(GetConVarInt(g_hPlayType) == 1)
  378. {
  379. soundToPlay = GetRandomInt(0, ctSound.Length-1);
  380. }
  381.  
  382. char szSound[128];
  383. ctSound.GetString(soundToPlay, szSound, sizeof(szSound));
  384. ctSound.Erase(soundToPlay);
  385. PlayMusicAll(szSound);
  386. if(ctSound.Length == 0)
  387. LoadSoundsCT();
  388. }
  389.  
  390. void PlaySoundTR()
  391. {
  392. int soundToPlay = 0;
  393. if(GetConVarInt(g_hPlayType) == 1)
  394. {
  395. soundToPlay = GetRandomInt(0, trSound.Length-1);
  396. }
  397.  
  398. char szSound[128];
  399. trSound.GetString(soundToPlay, szSound, sizeof(szSound));
  400. trSound.Erase(soundToPlay);
  401. PlayMusicAll(szSound);
  402. if(trSound.Length == 0)
  403. LoadSoundsTR();
  404. }
  405.  
  406. void PlayMusicAll(char[] szSound)
  407. {
  408. for (int i = 1; i <= MaxClients; i++)
  409. {
  410. if(IsValidClient(i) && (GetConVarInt(g_ClientSettings) == 0 || GetIntCookie(i, g_AbNeRCookie) == 0)) //Adicionado versão v3.4
  411. {
  412. if(CSGO)
  413. {
  414. ClientCommand(i, "playgamesound Music.StopAllMusic");
  415. ClientCommand(i, "play *%s", szSound);
  416. }
  417. else
  418. {
  419. ClientCommand(i, "play %s", szSound);
  420. }
  421. }
  422. }
  423.  
  424. if(GetConVarInt(g_PlayPrint) == 1)
  425. {
  426. CPrintToChatAll("{green}[ElementalGamingPT] {default}%t", "mp3 print", szSound);
  427. }
  428. }
  429.  
  430. public Action CommandLoad(int client, int args)
  431. {
  432. RefreshSounds(client);
  433. return Plugin_Handled;
  434. }
  435.  
  436. int GetIntCookie(int client, Handle handle)
  437. {
  438. char sCookieValue[11];
  439. GetClientCookie(client, handle, sCookieValue, sizeof(sCookieValue));
  440. return StringToInt(sCookieValue);
  441. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement