Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <sourcemod>
- #include <sdkhooks>
- #include <sdktools>
- #include <clientprefs>
- #include <emitsoundany>
- #include <smlib>
- #pragma newdecls required
- // Variable to check if it is a CS:GO Server;
- EngineVersion Game_Engine;
- // Cookies Handles;
- Handle cookie_radiosoundsT = INVALID_HANDLE;
- Handle cookie_radiosoundsCT = INVALID_HANDLE;
- // Strings to store client's cookies;
- char g_RadioSoundT[MAXPLAYERS + 1];
- char g_RadioSoundCT[MAXPLAYERS + 1];
- // ConVar Variables
- ConVar g_RadioSound_CTSound;
- ConVar g_RadioSound_TSound;
- ConVar g_RadioSound_SpamTime;
- // Paht's Strings
- char Config_Path[PLATFORM_MAX_PATH];
- int last_radio_use[MAXPLAYERS + 1];
- int note[MAXPLAYERS + 1];
- public Plugin myinfo =
- {
- name = "[CS:GO] Radio Sounds Menu",
- author = "Hallucinogenic Troll",
- description = "A plugin which will play radio sounds for some players",
- version = "1.0",
- url = "www.sourcemod.net"
- }
- public void OnPluginStart()
- {
- Game_Engine = GetEngineVersion();
- if (Game_Engine != Engine_CSGO)
- {
- SetFailState("This plugin will work only in CSGO.");
- }
- RegConsoleCmd("coverme", RadioTrigger);
- RegConsoleCmd("holdpos", RadioTrigger);
- RegConsoleCmd("regroup", RadioTrigger);
- RegConsoleCmd("followme", RadioTrigger);
- RegConsoleCmd("takingfire", RadioTrigger);
- RegConsoleCmd("go", RadioTrigger);
- RegConsoleCmd("fallback", RadioTrigger);
- RegConsoleCmd("roger", RadioTrigger);
- RegConsoleCmd("enemyspot", RadioTrigger);
- RegConsoleCmd("needbackup", RadioTrigger);
- RegConsoleCmd("sectorclear", RadioTrigger);
- RegConsoleCmd("inposition", RadioTrigger);
- RegConsoleCmd("reportingin", RadioTrigger);
- RegConsoleCmd("negative", RadioTrigger);
- RegConsoleCmd("thanks", RadioTrigger);
- RegConsoleCmd("cheer", RadioTrigger);
- RegConsoleCmd("sticktog", RadioTrigger);
- RegConsoleCmd("compliment", RadioTrigger);
- RegConsoleCmd("takepoint", RadioTrigger);
- // Command to change the radio;
- RegAdminCmd("sm_cradio", Radio_Sounds_Menu, ADMFLAG_CUSTOM1);
- // ConVars
- g_RadioSound_CTSound = CreateConVar("sm_radiosound_ctsound", "sas", "Default CT Radio for new players", _);
- g_RadioSound_TSound = CreateConVar("sm_radiosound_tsound", "phoenix", "Default T Radio for new players", _);
- g_RadioSound_SpamTime = CreateConVar("sm_radiosound_spamtime", "5", "Time in seconds between every sound", _, true, 0.0, false);
- cookie_radiosoundsT = RegClientCookie("RadioSoundsCookieC", "Radio Sounds Cookie Terrorist", CookieAccess_Public);
- cookie_radiosoundsCT = RegClientCookie("RadioSoundsCookieT", "Radio Sounds Cookie Counter-Terrorist", CookieAccess_Public);
- // Config's Path
- BuildPath(Path_SM, Config_Path, PLATFORM_MAX_PATH, "configs/radio_sounds/sounds.cfg");
- AutoExecConfig(true, "csgo_radio");
- LoadTranslations("csgo_radio.phrases");
- }
- public void OnConfigsExecuted()
- {
- Precache();
- }
- void Precache()
- {
- KeyValues kv = CreateKeyValues("csgo_radiosounds");
- kv.ImportFromFile(Config_Path);
- if (!kv.GotoFirstSubKey())
- {
- return;
- }
- char sound[PLATFORM_MAX_PATH];
- do
- {
- kv.GetString("coverme", sound, sizeof(sound));
- PrecacheSoundAny(sound, true);
- kv.GetString("holdpos", sound, sizeof(sound));
- PrecacheSoundAny(sound, true);
- kv.GetString("regroup", sound, sizeof(sound));
- PrecacheSoundAny(sound, true);
- kv.GetString("followme", sound, sizeof(sound));
- PrecacheSoundAny(sound, true);
- kv.GetString("takingfire", sound, sizeof(sound));
- PrecacheSoundAny(sound, true);
- kv.GetString("go", sound, sizeof(sound));
- PrecacheSoundAny(sound, true);
- kv.GetString("fallback", sound, sizeof(sound));
- PrecacheSoundAny(sound, true);
- kv.GetString("roger", sound, sizeof(sound));
- PrecacheSoundAny(sound, true);
- kv.GetString("enemyspot", sound, sizeof(sound));
- PrecacheSoundAny(sound, true);
- kv.GetString("needbackup", sound, sizeof(sound));
- PrecacheSoundAny(sound, true);
- kv.GetString("sectorclear", sound, sizeof(sound));
- PrecacheSoundAny(sound, true);
- kv.GetString("inposition", sound, sizeof(sound));
- PrecacheSoundAny(sound, true);
- kv.GetString("reportingin", sound, sizeof(sound));
- PrecacheSoundAny(sound, true);
- kv.GetString("negative", sound, sizeof(sound));
- PrecacheSoundAny(sound, true);
- kv.GetString("thanks", sound, sizeof(sound));
- PrecacheSoundAny(sound, true);
- kv.GetString("cheer", sound, sizeof(sound));
- PrecacheSoundAny(sound, true);
- kv.GetString("sticktog", sound, sizeof(sound));
- PrecacheSoundAny(sound, true);
- kv.GetString("compliment", sound, sizeof(sound));
- PrecacheSoundAny(sound, true);
- kv.GetString("takepoint", sound, sizeof(sound));
- PrecacheSoundAny(sound, true);
- } while (kv.GotoNextKey());
- delete kv;
- }
- /*void DownloadCustomFile(char[] SoundPath)
- {
- char SoundPath_Download[PLATFORM_MAX_PATH];
- if(!FileExists(SoundPath, true))
- {
- Format(SoundPath_Download, PLATFORM_MAX_PATH, "sound/%s", SoundPath);
- AddFileToDownloadsTable(SoundPath_Download);
- }
- }*/
- public void OnClientPostAdminCheck(int client)
- {
- GetConVarString(g_RadioSound_TSound, g_RadioSoundT[client], 512);
- GetConVarString(g_RadioSound_CTSound, g_RadioSoundCT[client], 512);
- CreateTimer(1.0, Timer_CookieCheck, client, TIMER_FLAG_NO_MAPCHANGE);
- }
- public Action Timer_CookieCheck(Handle timer, int client)
- {
- if (IsClientInGame(client))
- {
- if (AreClientCookiesCached(client))
- {
- char cookiebufferT[512];
- char cookiebufferCT[512];
- GetClientCookie(client, cookie_radiosoundsT, cookiebufferT, sizeof(cookiebufferT));
- GetClientCookie(client, cookie_radiosoundsCT, cookiebufferCT, sizeof(cookiebufferCT));
- strcopy(g_RadioSoundT[client], 512, cookiebufferT);
- strcopy(g_RadioSoundCT[client], 512, cookiebufferCT);
- }
- }
- }
- public Action Radio_Sounds_Menu(int client, int args)
- {
- Menu menu = new Menu(Radio_Sound_Menu_Handler);
- menu.SetTitle("Escolhe uma equipa para os sons de Rádio");
- menu.AddItem("CT", "Contra-Terrorista");
- menu.AddItem("T", "Terrorista");
- menu.ExitButton = true;
- menu.Display(client, 0);
- return Plugin_Handled;
- }
- public int Radio_Sound_Menu_Handler(Menu menu, MenuAction action, int client, int choice)
- {
- if (action == MenuAction_Select)
- {
- char info[32];
- menu.GetItem(choice, info, sizeof(info));
- if(StrEqual(info, "T"))
- {
- Menu_RadioSounds_T(client, choice);
- }
- else if(StrEqual(info, "CT"))
- {
- Menu_RadioSounds_CT(client, choice);
- }
- }
- else if (action == MenuAction_End)
- {
- delete menu;
- }
- }
- public Action Menu_RadioSounds_CT(int client, int args)
- {
- Menu menu = new Menu(Radio_Sound_Menu_CT_Handler);
- menu.SetTitle("Escolhe um tipo de Contra-Terrorista para o som de rádio");
- KeyValues kv = CreateKeyValues("csgo_radiosounds");
- kv.ImportFromFile(Config_Path);
- if (!kv.GotoFirstSubKey())
- {
- return Plugin_Handled;
- }
- int team;
- char team_string[40];
- char ClassID[150];
- char name[150];
- char flags[40];
- char menu_phrase[150];
- do
- {
- kv.GetString("team", team_string, sizeof(team_string));
- team = StringToInt(team_string);
- if (team != 3)
- {
- continue;
- }
- kv.GetSectionName(ClassID, sizeof(ClassID));
- kv.GetString("flags", flags, sizeof(flags));
- kv.GetString("name", name, sizeof(name));
- if(StrEqual(flags, ""))
- {
- menu.AddItem(ClassID, name);
- }
- else
- {
- if(HasPlayerFlags(client, flags))
- {
- menu.AddItem(ClassID, name);
- }
- else
- {
- Format(menu_phrase, 150, "%s (VIP)", name);
- menu.AddItem(ClassID, name, ITEMDRAW_DISABLED);
- }
- }
- } while (kv.GotoNextKey());
- delete kv;
- menu.ExitButton = true;
- menu.Display(client, 0);
- return Plugin_Handled;
- }
- public int Radio_Sound_Menu_CT_Handler(Menu menu, MenuAction action, int client, int choice)
- {
- if (action == MenuAction_Select)
- {
- char info[512];
- menu.GetItem(choice, info, sizeof(info));
- SetClientCookie(client, cookie_radiosoundsCT, info);
- strcopy(g_RadioSoundCT[client], 512, info);
- }
- else if (action == MenuAction_End)
- {
- delete menu;
- }
- }
- public Action Menu_RadioSounds_T(int client, int args)
- {
- Menu menu = new Menu(Radio_Sound_Menu_T_Handler);
- menu.SetTitle("Escolhe um tipo de Terrorista para o som de rádio");
- KeyValues kv = CreateKeyValues("csgo_radiosounds");
- kv.ImportFromFile(Config_Path);
- if (!kv.GotoFirstSubKey())
- {
- return Plugin_Handled;
- }
- int team;
- char team_string[40];
- char ClassID[150];
- char name[150];
- char flags[40];
- char menu_phrase[150];
- do
- {
- kv.GetString("team", team_string, sizeof(team_string));
- team = StringToInt(team_string);
- if (team != 2)
- {
- continue;
- }
- kv.GetSectionName(ClassID, sizeof(ClassID));
- kv.GetString("flags", flags, sizeof(flags));
- kv.GetString("name", name, sizeof(name));
- if(StrEqual(flags, ""))
- {
- menu.AddItem(ClassID, name);
- }
- else
- {
- if(HasPlayerFlags(client, flags))
- {
- menu.AddItem(ClassID, name);
- }
- else
- {
- Format(menu_phrase, 150, "%s (VIP)", name);
- menu.AddItem(ClassID, name, ITEMDRAW_DISABLED);
- }
- }
- } while (kv.GotoNextKey());
- delete kv;
- menu.ExitButton = true;
- menu.Display(client, 0);
- return Plugin_Handled;
- }
- public int Radio_Sound_Menu_T_Handler(Menu menu, MenuAction action, int client, int choice)
- {
- if (action == MenuAction_Select)
- {
- char info[512];
- menu.GetItem(choice, info, sizeof(info));
- SetClientCookie(client, cookie_radiosoundsT, info);
- strcopy(g_RadioSoundT[client], 512, info);
- }
- else if (action == MenuAction_End)
- {
- delete menu;
- }
- }
- public void OnEntityCreated(int iEntity, const char[] classname)
- {
- if(StrEqual(classname, "hegrenade_projectile"))
- {
- SDKHook(iEntity, SDKHook_SpawnPost, OnEntitySpawned);
- }
- if(StrEqual(classname, "flashbang_projectile"))
- {
- SDKHook(iEntity, SDKHook_SpawnPost, OnEntitySpawned);
- }
- if(StrEqual(classname, "smokegrenade_projectile"))
- {
- SDKHook(iEntity, SDKHook_SpawnPost, OnEntitySpawned);
- }
- if(StrEqual(classname, "incgrenade_projectile"))
- {
- SDKHook(iEntity, SDKHook_SpawnPost, OnEntitySpawned);
- }
- if(StrEqual(classname, "molotov_projectile"))
- {
- SDKHook(iEntity, SDKHook_SpawnPost, OnEntitySpawned);
- }
- if(StrEqual(classname, "decoy_projectile"))
- {
- SDKHook(iEntity, SDKHook_SpawnPost, OnEntitySpawned);
- }
- }
- public void OnEntitySpawned(int ent)
- {
- CreateTimer(0.0, InitGrenade, ent, TIMER_FLAG_NO_MAPCHANGE);
- }
- public Action InitGrenade(Handle timer, int ent)
- {
- if(!IsValidEntity(ent))
- {
- return;
- }
- int client = GetEntDataEnt2(ent, FindSendPropInfo("CBaseGrenade", "m_hThrower"));
- char target_string[65];
- char soundpath[PLATFORM_MAX_PATH];
- char text[256];
- GetEdictClassname(ent, target_string, 65);
- CheckStringRadio(target_string, soundpath, client);
- Format(text, 256, "%T", target_string);
- EmitSoundToTeamAny(client, soundpath, text);
- }
- public Action RadioTrigger(int client , int args)
- {
- char target_string[65];
- GetCmdArg(0, target_string, sizeof(target_string));
- char soundpath[PLATFORM_MAX_PATH];
- char text[256];
- if(CheckRadioFlood(client))
- {
- return Plugin_Handled;
- }
- CheckStringRadio(target_string, soundpath, client);
- Format(text, 256, "%t", target_string);
- EmitSoundToTeamAny(client, soundpath, text);
- return Plugin_Handled;
- }
- bool CheckRadioFlood(int client)
- {
- if (last_radio_use[client] == -1)
- {
- last_radio_use[client] = GetTime();
- return false;
- }
- int time = GetTime() - last_radio_use[client];
- int block_time = GetConVarInt(g_RadioSound_SpamTime);
- if ( time >= block_time )
- {
- last_radio_use[client] = GetTime();
- return false;
- }
- int wait_time = block_time - time;
- if ( (note[client] != wait_time))
- {
- if (wait_time <= 1)
- {
- PrintToChat(client, "[\x04PT'Fun\x01] Tens de esperar \x0E1\x01 segundo para poderes utilizar os rádios!");
- }
- else
- {
- PrintToChat(client, "[\x04PT'Fun\x01] Tens de esperar \x0E%d\x01 segundos para poderes utilizar os rádios", wait_time);
- }
- }
- note[client] = wait_time;
- return true;
- }
- void CheckStringRadio(char [] target_string, char [] SoundPath, int client)
- {
- KeyValues kv = CreateKeyValues("csgo_radiosounds");
- kv.ImportFromFile(Config_Path);
- if (!kv.GotoFirstSubKey())
- {
- return;
- }
- int team;
- char team_string[40];
- char ClassID[150];
- do
- {
- kv.GetSectionName(ClassID, sizeof(ClassID));
- kv.GetString("team", team_string, sizeof(team_string));
- team = StringToInt(team_string);
- if(GetClientTeam(client) == team)
- {
- switch(team)
- {
- case 2:
- {
- if(StrEqual(ClassID, g_RadioSoundT[client], false))
- {
- kv.GetString(target_string, SoundPath, PLATFORM_MAX_PATH);
- return;
- }
- }
- case 3:
- {
- if(StrEqual(ClassID, g_RadioSoundCT[client], false))
- {
- kv.GetString(target_string, SoundPath, PLATFORM_MAX_PATH);
- return;
- }
- }
- }
- }
- }while(kv.GotoNextKey());
- delete kv;
- }
- stock bool IsValidClient(int client)
- {
- if(client >= 1 && client <= MaxClients && IsClientConnected(client) && IsClientInGame(client))
- {
- return true;
- }
- return false;
- }
- void EmitSoundToTeamAny(int client, char[] soundpath, char[] text)
- {
- for (int i = 0; i <= MaxClients; i++)
- {
- if(IsValidClient(i))
- {
- if(GetClientTeam(i) == GetClientTeam(client))
- {
- EmitSoundToClientAny(i, soundpath);
- PrintToChat(i, "\x0B%N\x01 (RÁDIO): \x0E%s\x01!", client, text);
- }
- }
- }
- }
- public bool HasPlayerFlags(int client, char flags[40])
- {
- if(StrContains(flags, "a") != -1)
- {
- if(Client_HasAdminFlags(client, ADMFLAG_RESERVATION))
- {
- return true;
- }
- }
- else if(StrContains(flags, "b") != -1)
- {
- if(Client_HasAdminFlags(client, ADMFLAG_GENERIC))
- {
- return true;
- }
- }
- else if(StrContains(flags, "c") != -1)
- {
- if(Client_HasAdminFlags(client, ADMFLAG_KICK))
- {
- return true;
- }
- }
- else if(StrContains(flags, "d") != -1)
- {
- if(Client_HasAdminFlags(client, ADMFLAG_BAN))
- {
- return true;
- }
- }
- else if(StrContains(flags, "e") != -1)
- {
- if(Client_HasAdminFlags(client, ADMFLAG_UNBAN))
- {
- return true;
- }
- }
- else if(StrContains(flags, "f") != -1)
- {
- if(Client_HasAdminFlags(client, ADMFLAG_SLAY))
- {
- return true;
- }
- }
- else if(StrContains(flags, "g") != -1)
- {
- if(Client_HasAdminFlags(client, ADMFLAG_CHANGEMAP))
- {
- return true;
- }
- }
- else if(StrContains(flags, "h") != -1)
- {
- if(Client_HasAdminFlags(client, 128))
- {
- return true;
- }
- }
- else if(StrContains(flags, "i") != -1)
- {
- if(Client_HasAdminFlags(client, ADMFLAG_CONFIG))
- {
- return true;
- }
- }
- else if(StrContains(flags, "j") != -1)
- {
- if(Client_HasAdminFlags(client, ADMFLAG_CHAT))
- {
- return true;
- }
- }
- else if(StrContains(flags, "k") != -1)
- {
- if(Client_HasAdminFlags(client, ADMFLAG_VOTE))
- {
- return true;
- }
- }
- else if(StrContains(flags, "l") != -1)
- {
- if(Client_HasAdminFlags(client, ADMFLAG_PASSWORD))
- {
- return true;
- }
- }
- else if(StrContains(flags, "m") != -1)
- {
- if(Client_HasAdminFlags(client, ADMFLAG_RCON))
- {
- return true;
- }
- }
- else if(StrContains(flags, "n") != -1)
- {
- if(Client_HasAdminFlags(client, ADMFLAG_CHEATS))
- {
- return true;
- }
- }
- else if(StrContains(flags, "z") != -1)
- {
- if(Client_HasAdminFlags(client, ADMFLAG_ROOT))
- {
- return true;
- }
- }
- else if(StrContains(flags, "o") != -1)
- {
- if(Client_HasAdminFlags(client, ADMFLAG_CUSTOM1))
- {
- return true;
- }
- }
- else if(StrContains(flags, "p") != -1)
- {
- if(Client_HasAdminFlags(client, ADMFLAG_CUSTOM2))
- {
- return true;
- }
- }
- else if(StrContains(flags, "q") != -1)
- {
- if(Client_HasAdminFlags(client, ADMFLAG_CUSTOM3))
- {
- return true;
- }
- }
- else if(StrContains(flags, "r") != -1)
- {
- if(Client_HasAdminFlags(client, ADMFLAG_CUSTOM4))
- {
- return true;
- }
- }
- else if(StrContains(flags, "s") != -1)
- {
- if(Client_HasAdminFlags(client, ADMFLAG_CUSTOM5))
- {
- return true;
- }
- }
- else if(StrContains(flags, "t") != -1)
- {
- if(Client_HasAdminFlags(client, ADMFLAG_CUSTOM6))
- {
- return true;
- }
- }
- return false;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement