Senior Member
Join Date: Jul 2012
Location: Israel 3>
|
01-10-2018
, 11:38
Re: [CSGO] taunts command
|
#5
|
Haven't tested it, I've attached the compiled plugin and config in the zip.
PHP Code:
#pragma semicolon 1
#define DEBUG
#define PLUGIN_AUTHOR "nhnkl159" #define PLUGIN_VERSION "1.0"
#include <sourcemod> #include <sdktools> #include <colors> #include <emitsoundany>
char gS_Config[PLATFORM_MAX_PATH]; Handle gH_kv;
int gI_TauntsUsed[MAXPLAYERS + 1];
ConVar gC_AllowedTeam; ConVar gC_MaxTimes;
public Plugin myinfo = { name = "[CS:GO / ANY ?] Taunts", author = PLUGIN_AUTHOR, description = "Allow player to play some sounds to the world.", version = PLUGIN_VERSION, url = "keepomod.com" };
public void OnPluginStart() { CreateConVar("sm_taunts_version", PLUGIN_VERSION, "plugin info", FCVAR_SPONLY | FCVAR_REPLICATED | FCVAR_NOTIFY | FCVAR_DONTRECORD); gC_AllowedTeam = CreateConVar("sm_taunts_team", "2", "Only team that can use taunts command (0 = Both)"); gC_MaxTimes = CreateConVar("sm_taunts_maxtimes", "4", "Max times that player can use this command per round."); RegConsoleCmd("sm_taunts", CMD_Taunts, "Command for player to open the taunts menu."); RegAdminCmd("sm_reloadtaunts", CMD_Reload, ADMFLAG_BAN, "Command for admins to reload the taunts menu."); HookEvent("round_start", Event_RoundStart); RefreshSounds(); AutoExecConfig(true, "sm_taunts"); }
public void OnMapStart() { DownloadAndPre(); }
public void OnClientConnected(int client) { gI_TauntsUsed[client] = 0; }
public void Event_RoundStart(Event e, const char[] name, bool dontBroadcast) { for (int i = 0; i <= MaxClients; i++) { if(IsValidClient(i)) { gI_TauntsUsed[i] = 0; } } }
public Action CMD_Reload(int client, int args) { RefreshSounds(); CPrintToChat(client, "\x05You have reloaded the ini files."); return Plugin_Handled; }
public Action CMD_Taunts(int client, int args) { if (!IsValidClient(client)) { return Plugin_Handled; } if (gI_TauntsUsed[client] >= gC_MaxTimes.IntValue) { CPrintToChat(client, "\x05You have already used your maximum amount of taunts (%d/%d).", gI_TauntsUsed[client], gC_MaxTimes.IntValue); return Plugin_Handled; } if (GetClientTeam(client) != gC_AllowedTeam.IntValue && gC_AllowedTeam.IntValue != 0) { CPrintToChat(client, "\x05You are not allowed to use this command (Team Blocked)."); return Plugin_Handled; } char MenuTitle[128]; FormatEx(MenuTitle, 128, "Taunts Menu\nTaunts Left : %d", gC_MaxTimes.IntValue - gI_TauntsUsed[client]); char FileName[256], SoundFile[256], SoundFile2[256]; Menu menu = new Menu(TauntsMenuHandler); menu.SetTitle(MenuTitle); if (KvGotoFirstSubKey(gH_kv)) { do { KvGetString(gH_kv, "file", SoundFile, 256); Format(SoundFile2, 256, "sound/%s", SoundFile); if (!FileExists(SoundFile2) && !FileExists(SoundFile2, true))continue; KvGetSectionName(gH_kv, FileName, 256); menu.AddItem(SoundFile, FileName); } while (KvGotoNextKey(gH_kv)); } KvRewind(gH_kv); menu.Display(client, MENU_TIME_FOREVER); return Plugin_Handled; }
public int TauntsMenuHandler(Menu menu, MenuAction action, int client, int param2) { switch (action) { case MenuAction_Select: { if (GetClientTeam(client) != gC_AllowedTeam.IntValue && gC_AllowedTeam.IntValue != 0) { CPrintToChat(client, "\x05You are not allowed to use this command (Team Blocked)."); return; } char paramitem[256]; GetMenuItem(menu, param2, paramitem, sizeof(paramitem)); float origin[3]; GetClientAbsOrigin(client, origin); EmitAmbientSoundAny(paramitem, origin); CPrintToChat(client, "\x05Playing : %s.", paramitem); gI_TauntsUsed[client]++; KvRewind(gH_kv); } case MenuAction_Cancel: { if (param2 == MenuCancel_ExitBack) { delete menu; } } } }
stock bool IsValidClient(int client, bool alive = false, bool bots = false) { if (client > 0 && client <= MaxClients && IsClientInGame(client) && (alive == false || IsPlayerAlive(client)) && (bots == false && !IsFakeClient(client))) { return true; } return false; }
void RefreshSounds() { BuildPath(Path_SM, gS_Config, PLATFORM_MAX_PATH, "configs/taunts/sounds.ini"); if (gH_kv != INVALID_HANDLE)CloseHandle(gH_kv); gH_kv = CreateKeyValues("Taunts"); FileToKeyValues(gH_kv, gS_Config); }
void DownloadAndPre() { char gS_Temp[256]; if (KvGotoFirstSubKey(gH_kv)) { do { KvGetString(gH_kv, "file", gS_Temp, 256); PrecacheSoundAny(gS_Temp); char gS_Temp2[256]; Format(gS_Temp2, 256, "sound/%s", gS_Temp); AddFileToDownloadsTable(gS_Temp2); } while (KvGotoNextKey(gH_kv)); } KvRewind(gH_kv); }
__________________
Last edited by nhnkl159; 01-10-2018 at 11:40.
|
|