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

Solved [CS:S] Problems with EmitSound


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
farawayf
Senior Member
Join Date: Jan 2019
Old 12-14-2019 , 10:56   [CS:S] Problems with EmitSound
Reply With Quote #1

Sounds not playing, but debugs works and sounds downloading so problem with emitsound. And there is no error logs.
Can someone look at this sourcecode and say what is wrong ?

PHP Code:
#include <sourcemod>
#include <sdktools>
#include <clientprefs>
#include <mapchooser_extended>

char cStartSound[135], cEndSound[135];

bool bIsClientDisabledSounds[MAXPLAYERS 1] =  {false, ... };
Handle hCookie;

public 
void OnPluginStart() {
    
hCookie RegClientCookie("votesounds""Vote Sounds"CookieAccess_Public);
    
RegConsoleCmd("sm_sounds"Sounds);
}

public 
void OnMapStart() {
    
char path[PLATFORM_MAX_PATH], buffer[135]; 
    
BuildPath(Path_SMpathsizeof(path), "configs/votesounds/sounds.ini");
    
    
KeyValues kv CreateKeyValues("sounds");
    
kv.ImportFromFile(path);

    
kv.Rewind();
    if(
kv.JumpToKey("startsound"false)) {
        
kv.GetString("sound"buffer135);
        
Format(cStartSound135buffer);
        
Format(buffer135"sound/%s"cStartSound);
        
AddFileToDownloadsTable(buffer);
        
PrecacheSound(buffer);
    }
    if(
kv.JumpToKey("endsound"false)) {
        
kv.GetString("sound"buffer135);
        
Format(cEndSound135buffer);
        
Format(buffer135"sound/%s"cEndSound);
        
AddFileToDownloadsTable(buffer);
        
PrecacheSound(buffer);
    }
}

public 
void OnClientCookiesCached(int client) {
    static 
char cValue[2];
    
GetClientCookie(clienthCookiecValuesizeof(cValue));
    
bIsClientDisabledSounds[client] = view_as<bool>(StringToInt(cValue));
}

public 
Action Sounds(int clientint args) {
    if(
IsClientInGame(client)) {
        if (
bIsClientDisabledSounds[client]) bIsClientDisabledSounds[client] = false;
        else if (!
bIsClientDisabledSounds[client]) bIsClientDisabledSounds[client] = true;
        
        
PrintToChat(client"Sounds are %s"bIsClientDisabledSounds[client] ? "disabled" "enabled");
        
        static 
char cValue[2];
        
IntToString(bIsClientDisabledSounds[client], cValuesizeof(cValue));
        
SetClientCookie(clienthCookiecValue);
    }
    return 
Plugin_Handled;
}

public 
OnMapVoteStarted() {
    
EmitSounds(cStartSound);
    
// DEBUG PrintToChatAll("soundstart");
}

public 
OnMapVoteEnd(const char[] map) {
    
EmitSounds(cEndSound);
    
// DEBUG PrintToChatAll("soundend");
}

void EmitSounds(const char[] cSound) {
    for(
int i 1MaxClientsi++) {
        if(
IsClientInGame(i) && !IsFakeClient(i)) {
            if(!
bIsClientDisabledSounds[i]) {
                
EmitSoundToClient(icSound);
            }
        }
    }


Last edited by farawayf; 12-14-2019 at 16:39.
farawayf is offline
Balimbanana
Member
Join Date: Jan 2017
Old 12-14-2019 , 14:28   Re: [CS:S] Problems with EmitSound
Reply With Quote #2

Part of it might be that PrecacheSound is relative to the sounds directory.
Line 29 and 36:
Code:
PrecacheSound(buffer);
Should be CStartSound (29) and CEndSound (36) instead of buffer.
You might also want to include a FileExists check in there as well for the full path in case it attempts to add files that don't exist.
You could also have a debug print at the EmitSoundToClient point for checking if the bIsClientDisabledSounds[#] is correctly set and the sound path.
Code:
void EmitSounds(const char[] cSound) {
    for(int i = 1; i < MaxClients; i++) {
        if(IsClientInGame(i) && !IsFakeClient(i)) {
            PrintToServer("EmitSound %s to %i IsDisabled %i",cSound,i,bIsClientDisabledSounds[i]); // DEBUG
            if(!bIsClientDisabledSounds[i]) {
                EmitSoundToClient(i, cSound);
            }
        }
    }
}
Balimbanana is offline
farawayf
Senior Member
Join Date: Jan 2019
Old 12-14-2019 , 14:33   Re: [CS:S] Problems with EmitSound
Reply With Quote #3

Quote:
Originally Posted by Balimbanana View Post
Part of it might be that PrecacheSound is relative to the sounds directory.
Line 29 and 36:
Code:
PrecacheSound(buffer);
Should be CStartSound (29) and CEndSound (36) instead of buffer.
You might also want to include a FileExists check in there as well for the full path in case it attempts to add files that don't exist.
You could also have a debug print at the EmitSoundToClient point for checking if the bIsClientDisabledSounds[#] is correctly set and the sound path.
Code:
void EmitSounds(const char[] cSound) {
    for(int i = 1; i < MaxClients; i++) {
        if(IsClientInGame(i) && !IsFakeClient(i)) {
            PrintToServer("EmitSound %s to %i IsDisabled %i",cSound,i,bIsClientDisabledSounds[i]); // DEBUG
            if(!bIsClientDisabledSounds[i]) {
                EmitSoundToClient(i, cSound);
            }
        }
    }
}
so, i need to cut "sound/" from path to make it precache ?
farawayf is offline
Balimbanana
Member
Join Date: Jan 2017
Old 12-14-2019 , 14:47   Re: [CS:S] Problems with EmitSound
Reply With Quote #4

Yes, PrecacheSound assumes the path entered is already in sound/
If it still doesn't work, check that debug I put and see if some values are being overwritten somewhere maybe.
Balimbanana is offline
farawayf
Senior Member
Join Date: Jan 2019
Old 12-14-2019 , 16:38   Re: [CS:S] Problems with EmitSound
Reply With Quote #5

Quote:
Originally Posted by Balimbanana View Post
Yes, PrecacheSound assumes the path entered is already in sound/
If it still doesn't work, check that debug I put and see if some values are being overwritten somewhere maybe.
yes, it worked now. thanks!
farawayf is offline
Dragokas
Veteran Member
Join Date: Nov 2017
Location: Ukraine on fire
Old 12-16-2019 , 03:14   Re: [CS:S] Problems with EmitSound
Reply With Quote #6

Perhaps, it's good to add "true" as well:
PHP Code:
PrecacheSound(buffertrue); 
__________________
Expert of CMD/VBS/VB6. Malware analyst. L4D fun (Bloody Witch & FreeZone)
[My plugins] [My tools] [GitHub] [Articles] [HiJackThis+] [Donate]
Dragokas is offline
Reply


Thread Tools
Display Modes

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 22:12.


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