Raised This Month: $32 Target: $400
 8% 

Solved EmitSoundToClient based on whether or not a client has a bool set to true?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
404UserNotFound
BANNED
Join Date: Dec 2011
Old 05-28-2016 , 01:26   EmitSoundToClient based on whether or not a client has a bool set to true?
Reply With Quote #1

Using clientprefs to store a cookie to determine whether or not a player can hear "say sounds". Racking my brain trying to figure out the proper way to have EmitSoundToClient only play to clients who have the global bool g_bCanHearSounds[] set to true.

This is probably the simplest bloody thing to do, but admittedly, I did smoke a bowl earlier so I'm having some troubles. I've tested various arrangements of the code below ingame, but no sounds have played.

PHP Code:
public Action Listener_Say(int iClient, const char[] strCommandint iArgs)
{
    if (!
iClient || iClient MaxClients || !IsClientInGame(iClient))
    {
        return 
Plugin_Continue;
    }
    
    
char strChat[100];
    
GetCmdArgString(strChatsizeof(strChat));
    
int iStart;
    if (
strChat[iStart] == '"')
    {
        
iStart++;
    }
    
int iLength strlen(strChat[iStart]);
    if (
strChat[iLength+iStart-1] == '"')
    {
        
strChat[iLength--+iStart-1] = '\0';
    }
    
    if (
StrContains(strChat[iStart], "attention"false) != -&& iLength <= 9)
    {
        for (
int i=1i<=MaxClientsi++)
        {
            if (
IsClientInGame(i) && g_bCanHearSounds[i])
            {
                
EmitSoundToClient(iTF2_ATTENTION__SNDLEVEL_NORMAL_SNDVOL_NORMAL______);
            }
        }
    }
    return 
Plugin_Continue;


Last edited by 404UserNotFound; 08-20-2016 at 18:34.
404UserNotFound is offline
Chaosxk
Veteran Member
Join Date: Aug 2010
Location: Westeros
Old 05-28-2016 , 01:41   Re: EmitSoundToClient based on whether or not a client has a bool set to true?
Reply With Quote #2

What are you trying to do here? :
Code:
char strChat[100];
    GetCmdArgString(strChat, sizeof(strChat));
    int iStart;
    if (strChat[iStart] == '"')
    {
        iStart++;
    }
    int iLength = strlen(strChat[iStart]);
    if (strChat[iLength+iStart-1] == '"')
    {
        strChat[iLength--+iStart-1] = '\0';
    }
__________________
Chaosxk is offline
Miu
Veteran Member
Join Date: Nov 2013
Old 05-28-2016 , 09:52   Re: EmitSoundToClient based on whether or not a client has a bool set to true?
Reply With Quote #3

you did it right
Miu is offline
Impact123
Veteran Member
Join Date: Oct 2011
Location: Germany
Old 05-28-2016 , 10:15   Re: EmitSoundToClient based on whether or not a client has a bool set to true?
Reply With Quote #4

You shouldn't need more than this as a base
PHP Code:
public void OnClientSayCommand_Post(int client, const char[] command, const char[] sArgs)
{
    if (
StrEqual(sArgs"attention"false))
    {
        
// Your loop here
    
}

The rest looks okay.

Quote:
Originally Posted by abrandnewday View Post
I'm not entirely sure how to "read" the code and figure out what it does
Apparently the "same" as the StripQuotes function.

Quote:
Originally Posted by abrandnewday View Post
I'm not sure why the listener fails when the if statements are removed.
Add something like this at the top and find out
PHP Code:
PrintToServer("Say command: '%s' -> '%s'"commandsArgs); 
__________________

Last edited by Impact123; 05-28-2016 at 10:37.
Impact123 is offline
Reply



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 10:18.


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