Advertisement
Guest User

CSGO Radio Plugin

a guest
Jul 24th, 2017
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 16.13 KB | None | 0 0
  1. #include <sourcemod>
  2. #include <sdkhooks>
  3. #include <sdktools>
  4. #include <clientprefs>
  5. #include <emitsoundany>
  6. #include <smlib>
  7.  
  8. #pragma newdecls required
  9.  
  10. // Variable to check if it is a CS:GO Server;
  11. EngineVersion Game_Engine;
  12.  
  13. // Cookies Handles;
  14. Handle cookie_radiosoundsT = INVALID_HANDLE;
  15. Handle cookie_radiosoundsCT = INVALID_HANDLE;
  16.  
  17. // Strings to store client's cookies;
  18. char g_RadioSoundT[MAXPLAYERS + 1];
  19. char g_RadioSoundCT[MAXPLAYERS + 1];
  20.  
  21. // ConVar Variables
  22. ConVar g_RadioSound_CTSound;
  23. ConVar g_RadioSound_TSound;
  24. ConVar g_RadioSound_SpamTime;
  25.  
  26. // Paht's Strings
  27. char Config_Path[PLATFORM_MAX_PATH];
  28.  
  29. int last_radio_use[MAXPLAYERS + 1];
  30. int note[MAXPLAYERS + 1];
  31.  
  32. public Plugin myinfo =
  33. {
  34. name = "[CS:GO] Radio Sounds Menu",
  35. author = "Hallucinogenic Troll",
  36. description = "A plugin which will play radio sounds for some players",
  37. version = "1.0",
  38. url = "www.sourcemod.net"
  39. }
  40. public void OnPluginStart()
  41. {
  42. Game_Engine = GetEngineVersion();
  43. if (Game_Engine != Engine_CSGO)
  44. {
  45. SetFailState("This plugin will work only in CSGO.");
  46. }
  47.  
  48. RegConsoleCmd("coverme", RadioTrigger);
  49. RegConsoleCmd("holdpos", RadioTrigger);
  50. RegConsoleCmd("regroup", RadioTrigger);
  51. RegConsoleCmd("followme", RadioTrigger);
  52. RegConsoleCmd("takingfire", RadioTrigger);
  53. RegConsoleCmd("go", RadioTrigger);
  54. RegConsoleCmd("fallback", RadioTrigger);
  55. RegConsoleCmd("roger", RadioTrigger);
  56. RegConsoleCmd("enemyspot", RadioTrigger);
  57. RegConsoleCmd("needbackup", RadioTrigger);
  58. RegConsoleCmd("sectorclear", RadioTrigger);
  59. RegConsoleCmd("inposition", RadioTrigger);
  60. RegConsoleCmd("reportingin", RadioTrigger);
  61. RegConsoleCmd("negative", RadioTrigger);
  62. RegConsoleCmd("thanks", RadioTrigger);
  63. RegConsoleCmd("cheer", RadioTrigger);
  64. RegConsoleCmd("sticktog", RadioTrigger);
  65. RegConsoleCmd("compliment", RadioTrigger);
  66. RegConsoleCmd("takepoint", RadioTrigger);
  67.  
  68. // Command to change the radio;
  69. RegAdminCmd("sm_cradio", Radio_Sounds_Menu, ADMFLAG_CUSTOM1);
  70.  
  71. // ConVars
  72. g_RadioSound_CTSound = CreateConVar("sm_radiosound_ctsound", "sas", "Default CT Radio for new players", _);
  73. g_RadioSound_TSound = CreateConVar("sm_radiosound_tsound", "phoenix", "Default T Radio for new players", _);
  74. g_RadioSound_SpamTime = CreateConVar("sm_radiosound_spamtime", "5", "Time in seconds between every sound", _, true, 0.0, false);
  75.  
  76. cookie_radiosoundsT = RegClientCookie("RadioSoundsCookieC", "Radio Sounds Cookie Terrorist", CookieAccess_Public);
  77. cookie_radiosoundsCT = RegClientCookie("RadioSoundsCookieT", "Radio Sounds Cookie Counter-Terrorist", CookieAccess_Public);
  78.  
  79. // Config's Path
  80. BuildPath(Path_SM, Config_Path, PLATFORM_MAX_PATH, "configs/radio_sounds/sounds.cfg");
  81.  
  82. AutoExecConfig(true, "csgo_radio");
  83.  
  84. LoadTranslations("csgo_radio.phrases");
  85. }
  86.  
  87. public void OnConfigsExecuted()
  88. {
  89. Precache();
  90. }
  91.  
  92. void Precache()
  93. {
  94. KeyValues kv = CreateKeyValues("csgo_radiosounds");
  95.  
  96. kv.ImportFromFile(Config_Path);
  97.  
  98. if (!kv.GotoFirstSubKey())
  99. {
  100. return;
  101. }
  102.  
  103. char sound[PLATFORM_MAX_PATH];
  104. do
  105. {
  106. kv.GetString("coverme", sound, sizeof(sound));
  107. PrecacheSoundAny(sound, true);
  108. kv.GetString("holdpos", sound, sizeof(sound));
  109. PrecacheSoundAny(sound, true);
  110. kv.GetString("regroup", sound, sizeof(sound));
  111. PrecacheSoundAny(sound, true);
  112. kv.GetString("followme", sound, sizeof(sound));
  113. PrecacheSoundAny(sound, true);
  114. kv.GetString("takingfire", sound, sizeof(sound));
  115. PrecacheSoundAny(sound, true);
  116. kv.GetString("go", sound, sizeof(sound));
  117. PrecacheSoundAny(sound, true);
  118. kv.GetString("fallback", sound, sizeof(sound));
  119. PrecacheSoundAny(sound, true);
  120. kv.GetString("roger", sound, sizeof(sound));
  121. PrecacheSoundAny(sound, true);
  122. kv.GetString("enemyspot", sound, sizeof(sound));
  123. PrecacheSoundAny(sound, true);
  124. kv.GetString("needbackup", sound, sizeof(sound));
  125. PrecacheSoundAny(sound, true);
  126. kv.GetString("sectorclear", sound, sizeof(sound));
  127. PrecacheSoundAny(sound, true);
  128. kv.GetString("inposition", sound, sizeof(sound));
  129. PrecacheSoundAny(sound, true);
  130. kv.GetString("reportingin", sound, sizeof(sound));
  131. PrecacheSoundAny(sound, true);
  132. kv.GetString("negative", sound, sizeof(sound));
  133. PrecacheSoundAny(sound, true);
  134. kv.GetString("thanks", sound, sizeof(sound));
  135. PrecacheSoundAny(sound, true);
  136. kv.GetString("cheer", sound, sizeof(sound));
  137. PrecacheSoundAny(sound, true);
  138. kv.GetString("sticktog", sound, sizeof(sound));
  139. PrecacheSoundAny(sound, true);
  140. kv.GetString("compliment", sound, sizeof(sound));
  141. PrecacheSoundAny(sound, true);
  142. kv.GetString("takepoint", sound, sizeof(sound));
  143. PrecacheSoundAny(sound, true);
  144. } while (kv.GotoNextKey());
  145.  
  146. delete kv;
  147. }
  148.  
  149. /*void DownloadCustomFile(char[] SoundPath)
  150. {
  151. char SoundPath_Download[PLATFORM_MAX_PATH];
  152. if(!FileExists(SoundPath, true))
  153. {
  154. Format(SoundPath_Download, PLATFORM_MAX_PATH, "sound/%s", SoundPath);
  155. AddFileToDownloadsTable(SoundPath_Download);
  156. }
  157. }*/
  158.  
  159. public void OnClientPostAdminCheck(int client)
  160. {
  161. GetConVarString(g_RadioSound_TSound, g_RadioSoundT[client], 512);
  162. GetConVarString(g_RadioSound_CTSound, g_RadioSoundCT[client], 512);
  163. CreateTimer(1.0, Timer_CookieCheck, client, TIMER_FLAG_NO_MAPCHANGE);
  164. }
  165.  
  166. public Action Timer_CookieCheck(Handle timer, int client)
  167. {
  168. if (IsClientInGame(client))
  169. {
  170. if (AreClientCookiesCached(client))
  171. {
  172. char cookiebufferT[512];
  173. char cookiebufferCT[512];
  174. GetClientCookie(client, cookie_radiosoundsT, cookiebufferT, sizeof(cookiebufferT));
  175. GetClientCookie(client, cookie_radiosoundsCT, cookiebufferCT, sizeof(cookiebufferCT));
  176.  
  177. strcopy(g_RadioSoundT[client], 512, cookiebufferT);
  178. strcopy(g_RadioSoundCT[client], 512, cookiebufferCT);
  179. }
  180. }
  181. }
  182.  
  183. public Action Radio_Sounds_Menu(int client, int args)
  184. {
  185. Menu menu = new Menu(Radio_Sound_Menu_Handler);
  186.  
  187. menu.SetTitle("Escolhe uma equipa para os sons de Rádio");
  188. menu.AddItem("CT", "Contra-Terrorista");
  189. menu.AddItem("T", "Terrorista");
  190. menu.ExitButton = true;
  191. menu.Display(client, 0);
  192.  
  193. return Plugin_Handled;
  194. }
  195.  
  196. public int Radio_Sound_Menu_Handler(Menu menu, MenuAction action, int client, int choice)
  197. {
  198. if (action == MenuAction_Select)
  199. {
  200. char info[32];
  201. menu.GetItem(choice, info, sizeof(info));
  202. if(StrEqual(info, "T"))
  203. {
  204. Menu_RadioSounds_T(client, choice);
  205. }
  206. else if(StrEqual(info, "CT"))
  207. {
  208. Menu_RadioSounds_CT(client, choice);
  209. }
  210. }
  211. else if (action == MenuAction_End)
  212. {
  213. delete menu;
  214. }
  215. }
  216.  
  217. public Action Menu_RadioSounds_CT(int client, int args)
  218. {
  219. Menu menu = new Menu(Radio_Sound_Menu_CT_Handler);
  220. menu.SetTitle("Escolhe um tipo de Contra-Terrorista para o som de rádio");
  221. KeyValues kv = CreateKeyValues("csgo_radiosounds");
  222.  
  223. kv.ImportFromFile(Config_Path);
  224.  
  225. if (!kv.GotoFirstSubKey())
  226. {
  227. return Plugin_Handled;
  228. }
  229.  
  230. int team;
  231. char team_string[40];
  232. char ClassID[150];
  233. char name[150];
  234. char flags[40];
  235. char menu_phrase[150];
  236.  
  237. do
  238. {
  239. kv.GetString("team", team_string, sizeof(team_string));
  240.  
  241. team = StringToInt(team_string);
  242. if (team != 3)
  243. {
  244. continue;
  245. }
  246.  
  247.  
  248.  
  249. kv.GetSectionName(ClassID, sizeof(ClassID));
  250. kv.GetString("flags", flags, sizeof(flags));
  251. kv.GetString("name", name, sizeof(name));
  252.  
  253. if(StrEqual(flags, ""))
  254. {
  255. menu.AddItem(ClassID, name);
  256. }
  257. else
  258. {
  259. if(HasPlayerFlags(client, flags))
  260. {
  261. menu.AddItem(ClassID, name);
  262. }
  263. else
  264. {
  265. Format(menu_phrase, 150, "%s (VIP)", name);
  266. menu.AddItem(ClassID, name, ITEMDRAW_DISABLED);
  267. }
  268. }
  269. } while (kv.GotoNextKey());
  270.  
  271. delete kv;
  272. menu.ExitButton = true;
  273. menu.Display(client, 0);
  274. return Plugin_Handled;
  275. }
  276.  
  277.  
  278.  
  279. public int Radio_Sound_Menu_CT_Handler(Menu menu, MenuAction action, int client, int choice)
  280. {
  281. if (action == MenuAction_Select)
  282. {
  283. char info[512];
  284. menu.GetItem(choice, info, sizeof(info));
  285. SetClientCookie(client, cookie_radiosoundsCT, info);
  286. strcopy(g_RadioSoundCT[client], 512, info);
  287. }
  288. else if (action == MenuAction_End)
  289. {
  290. delete menu;
  291. }
  292. }
  293.  
  294. public Action Menu_RadioSounds_T(int client, int args)
  295. {
  296. Menu menu = new Menu(Radio_Sound_Menu_T_Handler);
  297. menu.SetTitle("Escolhe um tipo de Terrorista para o som de rádio");
  298. KeyValues kv = CreateKeyValues("csgo_radiosounds");
  299.  
  300. kv.ImportFromFile(Config_Path);
  301.  
  302. if (!kv.GotoFirstSubKey())
  303. {
  304. return Plugin_Handled;
  305. }
  306.  
  307. int team;
  308. char team_string[40];
  309. char ClassID[150];
  310. char name[150];
  311. char flags[40];
  312. char menu_phrase[150];
  313.  
  314. do
  315. {
  316. kv.GetString("team", team_string, sizeof(team_string));
  317.  
  318. team = StringToInt(team_string);
  319.  
  320. if (team != 2)
  321. {
  322. continue;
  323. }
  324.  
  325. kv.GetSectionName(ClassID, sizeof(ClassID));
  326. kv.GetString("flags", flags, sizeof(flags));
  327. kv.GetString("name", name, sizeof(name));
  328. if(StrEqual(flags, ""))
  329. {
  330. menu.AddItem(ClassID, name);
  331. }
  332. else
  333. {
  334. if(HasPlayerFlags(client, flags))
  335. {
  336. menu.AddItem(ClassID, name);
  337. }
  338. else
  339. {
  340. Format(menu_phrase, 150, "%s (VIP)", name);
  341. menu.AddItem(ClassID, name, ITEMDRAW_DISABLED);
  342. }
  343. }
  344. } while (kv.GotoNextKey());
  345.  
  346. delete kv;
  347. menu.ExitButton = true;
  348. menu.Display(client, 0);
  349. return Plugin_Handled;
  350. }
  351.  
  352.  
  353. public int Radio_Sound_Menu_T_Handler(Menu menu, MenuAction action, int client, int choice)
  354. {
  355. if (action == MenuAction_Select)
  356. {
  357. char info[512];
  358. menu.GetItem(choice, info, sizeof(info));
  359.  
  360. SetClientCookie(client, cookie_radiosoundsT, info);
  361. strcopy(g_RadioSoundT[client], 512, info);
  362. }
  363. else if (action == MenuAction_End)
  364. {
  365. delete menu;
  366. }
  367. }
  368.  
  369. public void OnEntityCreated(int iEntity, const char[] classname)
  370. {
  371. if(StrEqual(classname, "hegrenade_projectile"))
  372. {
  373. SDKHook(iEntity, SDKHook_SpawnPost, OnEntitySpawned);
  374. }
  375. if(StrEqual(classname, "flashbang_projectile"))
  376. {
  377. SDKHook(iEntity, SDKHook_SpawnPost, OnEntitySpawned);
  378. }
  379. if(StrEqual(classname, "smokegrenade_projectile"))
  380. {
  381. SDKHook(iEntity, SDKHook_SpawnPost, OnEntitySpawned);
  382. }
  383. if(StrEqual(classname, "incgrenade_projectile"))
  384. {
  385. SDKHook(iEntity, SDKHook_SpawnPost, OnEntitySpawned);
  386. }
  387. if(StrEqual(classname, "molotov_projectile"))
  388. {
  389. SDKHook(iEntity, SDKHook_SpawnPost, OnEntitySpawned);
  390. }
  391. if(StrEqual(classname, "decoy_projectile"))
  392. {
  393. SDKHook(iEntity, SDKHook_SpawnPost, OnEntitySpawned);
  394. }
  395. }
  396.  
  397. public void OnEntitySpawned(int ent)
  398. {
  399. CreateTimer(0.0, InitGrenade, ent, TIMER_FLAG_NO_MAPCHANGE);
  400. }
  401.  
  402. public Action InitGrenade(Handle timer, int ent)
  403. {
  404. if(!IsValidEntity(ent))
  405. {
  406. return;
  407. }
  408.  
  409. int client = GetEntDataEnt2(ent, FindSendPropInfo("CBaseGrenade", "m_hThrower"));
  410.  
  411. char target_string[65];
  412. char soundpath[PLATFORM_MAX_PATH];
  413. char text[256];
  414. GetEdictClassname(ent, target_string, 65);
  415.  
  416. CheckStringRadio(target_string, soundpath, client);
  417.  
  418. Format(text, 256, "%T", target_string);
  419.  
  420. EmitSoundToTeamAny(client, soundpath, text);
  421. }
  422.  
  423. public Action RadioTrigger(int client , int args)
  424. {
  425. char target_string[65];
  426. GetCmdArg(0, target_string, sizeof(target_string));
  427. char soundpath[PLATFORM_MAX_PATH];
  428. char text[256];
  429.  
  430. if(CheckRadioFlood(client))
  431. {
  432. return Plugin_Handled;
  433. }
  434.  
  435. CheckStringRadio(target_string, soundpath, client);
  436.  
  437. Format(text, 256, "%t", target_string);
  438.  
  439. EmitSoundToTeamAny(client, soundpath, text);
  440.  
  441. return Plugin_Handled;
  442. }
  443.  
  444. bool CheckRadioFlood(int client)
  445. {
  446. if (last_radio_use[client] == -1)
  447. {
  448. last_radio_use[client] = GetTime();
  449. return false;
  450. }
  451.  
  452. int time = GetTime() - last_radio_use[client];
  453. int block_time = GetConVarInt(g_RadioSound_SpamTime);
  454. if ( time >= block_time )
  455. {
  456. last_radio_use[client] = GetTime();
  457. return false;
  458. }
  459.  
  460. int wait_time = block_time - time;
  461.  
  462. if ( (note[client] != wait_time))
  463. {
  464. if (wait_time <= 1)
  465. {
  466. PrintToChat(client, "[\x04PT'Fun\x01] Tens de esperar \x0E1\x01 segundo para poderes utilizar os rádios!");
  467. }
  468. else
  469. {
  470. PrintToChat(client, "[\x04PT'Fun\x01] Tens de esperar \x0E%d\x01 segundos para poderes utilizar os rádios", wait_time);
  471. }
  472. }
  473.  
  474. note[client] = wait_time;
  475.  
  476. return true;
  477. }
  478.  
  479. void CheckStringRadio(char [] target_string, char [] SoundPath, int client)
  480. {
  481. KeyValues kv = CreateKeyValues("csgo_radiosounds");
  482.  
  483. kv.ImportFromFile(Config_Path);
  484.  
  485. if (!kv.GotoFirstSubKey())
  486. {
  487. return;
  488. }
  489.  
  490. int team;
  491. char team_string[40];
  492. char ClassID[150];
  493.  
  494. do
  495. {
  496. kv.GetSectionName(ClassID, sizeof(ClassID));
  497. kv.GetString("team", team_string, sizeof(team_string));
  498. team = StringToInt(team_string);
  499.  
  500. if(GetClientTeam(client) == team)
  501. {
  502. switch(team)
  503. {
  504. case 2:
  505. {
  506. if(StrEqual(ClassID, g_RadioSoundT[client], false))
  507. {
  508. kv.GetString(target_string, SoundPath, PLATFORM_MAX_PATH);
  509. return;
  510. }
  511. }
  512. case 3:
  513. {
  514. if(StrEqual(ClassID, g_RadioSoundCT[client], false))
  515. {
  516. kv.GetString(target_string, SoundPath, PLATFORM_MAX_PATH);
  517. return;
  518. }
  519. }
  520. }
  521. }
  522. }while(kv.GotoNextKey());
  523.  
  524. delete kv;
  525. }
  526.  
  527. stock bool IsValidClient(int client)
  528. {
  529. if(client >= 1 && client <= MaxClients && IsClientConnected(client) && IsClientInGame(client))
  530. {
  531. return true;
  532. }
  533. return false;
  534. }
  535.  
  536. void EmitSoundToTeamAny(int client, char[] soundpath, char[] text)
  537. {
  538. for (int i = 0; i <= MaxClients; i++)
  539. {
  540. if(IsValidClient(i))
  541. {
  542. if(GetClientTeam(i) == GetClientTeam(client))
  543. {
  544. EmitSoundToClientAny(i, soundpath);
  545. PrintToChat(i, "\x0B%N\x01 (RÁDIO): \x0E%s\x01!", client, text);
  546. }
  547. }
  548. }
  549. }
  550.  
  551. public bool HasPlayerFlags(int client, char flags[40])
  552. {
  553. if(StrContains(flags, "a") != -1)
  554. {
  555. if(Client_HasAdminFlags(client, ADMFLAG_RESERVATION))
  556. {
  557. return true;
  558. }
  559. }
  560. else if(StrContains(flags, "b") != -1)
  561. {
  562. if(Client_HasAdminFlags(client, ADMFLAG_GENERIC))
  563. {
  564. return true;
  565. }
  566. }
  567. else if(StrContains(flags, "c") != -1)
  568. {
  569. if(Client_HasAdminFlags(client, ADMFLAG_KICK))
  570. {
  571. return true;
  572. }
  573. }
  574. else if(StrContains(flags, "d") != -1)
  575. {
  576. if(Client_HasAdminFlags(client, ADMFLAG_BAN))
  577. {
  578. return true;
  579. }
  580. }
  581. else if(StrContains(flags, "e") != -1)
  582. {
  583. if(Client_HasAdminFlags(client, ADMFLAG_UNBAN))
  584. {
  585. return true;
  586. }
  587. }
  588. else if(StrContains(flags, "f") != -1)
  589. {
  590. if(Client_HasAdminFlags(client, ADMFLAG_SLAY))
  591. {
  592. return true;
  593. }
  594. }
  595. else if(StrContains(flags, "g") != -1)
  596. {
  597. if(Client_HasAdminFlags(client, ADMFLAG_CHANGEMAP))
  598. {
  599. return true;
  600. }
  601. }
  602. else if(StrContains(flags, "h") != -1)
  603. {
  604. if(Client_HasAdminFlags(client, 128))
  605. {
  606. return true;
  607. }
  608. }
  609. else if(StrContains(flags, "i") != -1)
  610. {
  611. if(Client_HasAdminFlags(client, ADMFLAG_CONFIG))
  612. {
  613. return true;
  614. }
  615. }
  616. else if(StrContains(flags, "j") != -1)
  617. {
  618. if(Client_HasAdminFlags(client, ADMFLAG_CHAT))
  619. {
  620. return true;
  621. }
  622. }
  623. else if(StrContains(flags, "k") != -1)
  624. {
  625. if(Client_HasAdminFlags(client, ADMFLAG_VOTE))
  626. {
  627. return true;
  628. }
  629. }
  630. else if(StrContains(flags, "l") != -1)
  631. {
  632. if(Client_HasAdminFlags(client, ADMFLAG_PASSWORD))
  633. {
  634. return true;
  635. }
  636. }
  637. else if(StrContains(flags, "m") != -1)
  638. {
  639. if(Client_HasAdminFlags(client, ADMFLAG_RCON))
  640. {
  641. return true;
  642. }
  643. }
  644. else if(StrContains(flags, "n") != -1)
  645. {
  646. if(Client_HasAdminFlags(client, ADMFLAG_CHEATS))
  647. {
  648. return true;
  649. }
  650. }
  651. else if(StrContains(flags, "z") != -1)
  652. {
  653. if(Client_HasAdminFlags(client, ADMFLAG_ROOT))
  654. {
  655. return true;
  656. }
  657. }
  658. else if(StrContains(flags, "o") != -1)
  659. {
  660. if(Client_HasAdminFlags(client, ADMFLAG_CUSTOM1))
  661. {
  662. return true;
  663. }
  664. }
  665. else if(StrContains(flags, "p") != -1)
  666. {
  667. if(Client_HasAdminFlags(client, ADMFLAG_CUSTOM2))
  668. {
  669. return true;
  670. }
  671. }
  672. else if(StrContains(flags, "q") != -1)
  673. {
  674. if(Client_HasAdminFlags(client, ADMFLAG_CUSTOM3))
  675. {
  676. return true;
  677. }
  678. }
  679. else if(StrContains(flags, "r") != -1)
  680. {
  681. if(Client_HasAdminFlags(client, ADMFLAG_CUSTOM4))
  682. {
  683. return true;
  684. }
  685. }
  686. else if(StrContains(flags, "s") != -1)
  687. {
  688. if(Client_HasAdminFlags(client, ADMFLAG_CUSTOM5))
  689. {
  690. return true;
  691. }
  692. }
  693. else if(StrContains(flags, "t") != -1)
  694. {
  695. if(Client_HasAdminFlags(client, ADMFLAG_CUSTOM6))
  696. {
  697. return true;
  698. }
  699. }
  700.  
  701. return false;
  702. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement