Raised This Month: $51 Target: $400
 12% 

Why are not the sound played?


  
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
Author Message
kratoss1812
Senior Member
Join Date: May 2018
Location: Romānia
Old 07-07-2019 , 10:32   Why are not the sound played?
Reply With Quote #1

I want to make a plugin that play a specific sound when a word it's triggered in chat.
Something similar with this

PHP Code:
#pragma semicolon 1

#define PLUGIN_AUTHOR "Teazze aka kRatoss"
#define PLUGIN_VERSION "1.00"

#include <sourcemod>
#include <vip_core>
#include <sdktools>
#include <clientprefs>

#pragma newdecls required

public Plugin myinfo 
{
    
name "Sank Sounds",
    
author PLUGIN_AUTHOR,
    
description "Provides in-game sanks.",
    
version PLUGIN_VERSION,
    
url ""
}

bool     g_Enabled false
        
HasSoundsEnab[MAXPLAYERS 1];

int     g_iSankCount[MAXPLAYERS 1], 
        
g_MaxSanksPerRound 15
        
g_SanksThisRound
        
g_MaxSanksPerClient 5,
        
Id;
        
static const 
char Feature[] = "Sanks";

char     g_sWord[999][1024];
char    g_sPath[999][1024];

Handle g_Cookie;

public 
void OnPluginStart()
{
    if(!
VIP_IsVIPLoaded()) VIP_OnVIPLoaded();
    
    
RegConsoleCmd("say"OnSay);
    
RegConsoleCmd("teamsay"OnSay);

    
HookEventEx("announce_phase_end"DisabPlugin);
    
HookEventEx("cs_intermission"DisabPlugin);
    
HookEventEx("cs_win_panel_match"DisabPlugin);
    
HookEventEx("start_halftime"DisabPlugin);

    
HookEventEx("round_start"EnabPlugin);    
    
    
RegConsoleCmd("sm_sank"SankMenu);
    
RegConsoleCmd("sm_sanks"SankMenu);    
    
RegConsoleCmd("sm_pulamea"SankMenu);
    
    
g_Cookie RegClientCookie("tz_sanks""Sanks prefs."CookieAccess_Private);    
}

public 
void VIP_OnVIPLoaded()
{
    
VIP_RegisterFeature(FeatureINT);
}

public 
Action SankMenu(int Clientint Args)
{
    
Menu menu = new Menu(Handler);
    
menu.SetTitle("Enable Sank Sounds?");
    
menu.AddItem("no""No");
    
menu.AddItem("yes""Yes");
    
menu.Display(ClientMENU_TIME_FOREVER);
}

public 
int Handler(Menu menuMenuAction actionint clientint param)
{
    if(
action == MenuAction_Select)
    {
        
char item[1024];
        
GetMenuItem(menuparamitemsizeof(item));
        
        if(
strcmp(item"no") == 0)
        {
            
SetClientCookie(clientg_Cookie"0");
            
PrintToChat(client"Sound Disabled");
        }
        if(
strcmp(item"yes") == 0)
        {
            
SetClientCookie(clientg_Cookie"1");            
            
PrintToChat(client"Sound Enable");
        }
    }
}

public 
void OnClientCookiesCached(int client)
{
    
char cookie[32];
    
GetClientCookie(clientg_Cookiecookiesizeof(cookie));
    
    if(
strcmp(cookie"0"))
        
HasSoundsEnab[client] = false;
    
    if(
strcmp(cookie"1"))
        
HasSoundsEnab[client] = true;
}

public 
Action DisabPlugin(Handle pHndl, const char[] Namebool bNoBCast)
{
    
g_Enabled false;
}

public 
Action EnabPlugin(Handle pHndl, const char[] Namebool bNoBCast)
{
    static 
int iId INVALID_ENT_REFERENCE;
    
    for (
iId 1iId <= MaxClientsiId++)
        
g_iSankCount[iId] = 0;
    
    
g_SanksThisRound 0;
    
g_Enabled true;
}

public 
void OnMapStart()
{
    
LoadSanks();
}

public 
Action OnSay(int Clientint Args)
{
    
char sArg[64];
    
GetCmdArgString(sArgsizeof(sArg));
    
    if (
sArg[0] == '"'/* Strip the ending quote, if there is one */
    
{
        
int  len strlen(sArg);
        if (
sArg[len-1] == '"'
            
sArg[len-1] = '\0';
    }
    
    static 
int Count;
    for (
Count 0Count sizeof(g_sWord[]); Count++)
    {
        if(
strcmp(sArgg_sWord[Count]) == 0)
        {
            if    (
VIP_IsClientFeatureUse(ClientFeature)     \
            && 
g_iSankCount[Client] < g_MaxSanksPerClient    \
            && 
g_SanksThisRound g_MaxSanksPerRound         \
            && 
g_Enabled == true                             \
            && 
HasSoundsEnab[Client] == true)
            {
                for (
int i 1<= MaxClientsi++)
                {
                    if (
IsValidClient(i) && HasSoundsEnab[i])
                    {
                        
ClientCommand(i"play %s"g_sPath[Count]);
                        
PrintToChatAll("[debug] A fost redat un sank cu Word Trigger-ul : %s si Path-ul : %s"g_sWord[Count], g_sPath[Count]);
                    }
                }
                
g_SanksThisRound++;
                
g_iSankCount[Client]++;
            }    
        }
    }
}

void LoadSanks()
{
    
KeyValues kv CreateKeyValues("Sanks");
    
    
char file[256], path[256], WordTrigger[256], SoundPath[256];
    
FormatEx(filesizeof(file), "configs/teaze_plugins/sanks.cfg");
    
BuildPath(Path_SMpathsizeof(path), file);
    
    if(!
FileExists(path))
        
SetFailState("Can not find config file ( %s )!"path);

    if(
FileExists(path))
        
kv.ImportFromFile(path);
        
    
Id 1;
        
    if(
kv.GotoFirstSubKey())
    {
        do
        {
            
kv.GetSectionName(WordTriggersizeof(WordTrigger));
            
kv.GetString("path"SoundPathsizeof(SoundPath));                
            
            
strcopy(g_sWord[Id], sizeof(g_sWord[]), WordTrigger);
            
strcopy(g_sPath[Id], sizeof(g_sPath[]), SoundPath);
            
PreCache(g_sPath[Id]);
            
Id++;    
        }
        while (
kv.GotoNextKey());
    }
    
    
kv.Rewind();
    
delete kv;
}

stock bool IsValidClient(int client)
{
    if (
client <= 0) return false;
    if (
client MaxClients) return false;
    if (!
IsClientConnected(client)) return false;
    return 
IsClientInGame(client);
}

void PreCache(const char[] path)
{
    
char buffer[256];
    
FormatEx(buffersizeof(buffer), "sound/%s"path);
    
    
AddFileToDownloadsTable(buffer);
    
AddToStringTable(FindStringTable("soundprecache"), path);

__________________

Last edited by kratoss1812; 07-07-2019 at 16:47. Reason: updated the code
kratoss1812 is offline
 



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 03:14.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode