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

Admin Connect Sounds


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
CollinHell
Junior Member
Join Date: Nov 2009
Location: Ossining, New York
Old 07-25-2010 , 15:24   Admin Connect Sounds
Reply With Quote #1

Hiya, I'm writing my first plugin. The plugin plays a unique sound for each admin when OnClientAuthorized is called, reading from a .cfg file for the STEAMID and sound for each admin (It does not read whether or not they're admins).

I've got most of the functionality down, and I've read through the API for each and every command I've used, and I've read through every wiki page in "Sourcemod Scripting", most of them more than once, but my plugin just refuses to play a sound. I'm only testing it with my own sound at this moment, but would anybody be able to discern why this does not work?

Here's the code to the addon itself:
PHP Code:
#include <sourcemod>
#include <sdktools>
#define PLUGIN_VERSION "1.0"
//

//
 
public Plugin:myinfo =
 {
    
name "AdminConnectSounds",
    
author "CollinHell",
    
description "Plays a unique sound for each admin",
    
version PLUGIN_VERSION,
    
url "bucknastysurf.com"
 
}
  
  public 
OnPluginStart()
  {
    
PrintToChatAll("Admin Connect Sounds loaded!")
    new 
String:config_File[64]
    if (!
FileExists("cfg/sourcemod/adminconnectsounds.cfg"))
    {
        
BuildPath(Path_SMconfig_Filesizeof(config_File), "cfg/sourcemod/adminconnectsounds.cfg")
    }
  }
  
  public 
OnMapStart()
  {
    new 
Handle:config OpenFile("cfg/sourcemod/adminconnectsounds.cfg""r");
    if (
config == INVALID_HANDLE)
    {
        return 
INVALID_HANDLE;
    }
  
    new 
String:preCacheSound[255];
    while (!
IsEndOfFile(config) && ReadFileLine(configpreCacheSoundsizeof(preCacheSound)))
    {
        if (
StrContains(preCacheSound"STEAM"true)!= -|| !IsCharAlpha(preCacheSound[0]))
        {
            continue;
        }
        
PrecacheSound(preCacheSoundtrue)
        
PrintToServer("File %s  precatched."preCacheSound
        
//AddFileToDownloadsTable(preCacheSound)
        
PrintToServer("File %s added to downloads table."preCacheSound)
    }
    
CloseHandle(config);
    return 
Plugin_Handled;
  }
  
 public 
OnClientAuthorized(client, const String:auth[])
 {
    new 
Handle:config OpenFile("cfg/adminconnectsounds.cfg""r");
    if (
config == INVALID_HANDLE)
    {
        return 
INVALID_HANDLE;
    }
    new 
cfg_Match
    
new String:cfg_Line[255]
    while (!
IsEndOfFile(config) && ReadFileLine(configcfg_Linesizeof(cfg_Line)))
    {
        if (
StrContains(cfg_Line"STEAM"true)!= -1)
        {
            
PrintToServer("Line is STEAM...")
            if (
StrEqual(cfg_Lineauthtrue)== true)
            {
                
PrintToServer("Line is matching STEAM")
                
cfg_Match 1
            
}
        }
        else if (!
IsCharAlpha(cfg_Line[0]))
        {
            
PrintToServer("!IsCharAlpha")
            continue;
        }
        else
        {
            
PrintToServer("Line is 'else'.")
            if (
cfg_Match == 1)
            {
                
PrintToServer("cfg_Match == true")
                new 
String:play_Path[200];
                
Format(play_Pathsizeof(play_Path), "play %s"cfg_Line)
                new 
play_MaxPlayers GetMaxClients();
                for (new 
1<=play_MaxPlayersi++)
                {
                    new 
bool:play_IsInGame IsClientInGame(i);
                    if (
play_IsInGame == true)
                    {
                        
ClientCommand(iplay_Path);
                    }
                }
            }
            break;
        }

    }
    
CloseHandle(config);
    return 
Plugin_Handled;
    
// This code DOES work.
    /* if (StrEqual(auth, "STEAM_0:0:16452962"))
    {
        // Start playing sound to clients
        new String:target_soundPath[200];
        Format(target_soundPath, sizeof(target_soundPath), "play bot/i_am_dangerous.wav");
        new target_playersConnected = GetMaxClients();
        for (new target_playerClient = 1; target_playerClient <= target_playersConnected; target_playerClient++)
        {
            new target_playerInGameStatus = IsClientInGame(target_playerClient);
            if (target_playerInGameStatus == 1)
            {
                ClientCommand(target_playerClient, target_soundPath);
            }
        }
    } */
 

And here's cfg/sourcemod/adminconnectsounds.cfg:

Code:
STEAM_0:0:16452962
bot/i_am_dangerous.wav
__________________
But what about second breakfast?
CollinHell is offline
Monkeys
Veteran Member
Join Date: Jan 2010
Old 07-25-2010 , 15:38   Re: Admin Connect Sounds
Reply With Quote #2

All the PrintToServers work?
If they do, print the play_Path after formatting it. Maybe a corrupt charactre crawled in there.


Also
new bool:play_IsInGame = IsClientInGame(i);
if (
play_IsInGame == true)


No need to create an extra var.
You can simply do
if (IsClientInGame(i))
__________________
Get a lid on that zombie,
he's never gonna be alri-i-ight.
Oooh get a lid on that zombie,
or he's gonna feed all night.
Monkeys is offline
CollinHell
Junior Member
Join Date: Nov 2009
Location: Ossining, New York
Old 07-25-2010 , 16:00   Re: Admin Connect Sounds
Reply With Quote #3

Actually, come to think of it, none of the PrintToServer lines show up in HLSW, but PrintToChatAll lines do. I've replaced all of the server prints with chatall prints. Here's the code now:

PHP Code:
#include <sourcemod>
#include <sdktools>
#define PLUGIN_VERSION "1.0"
//

//
 
public Plugin:myinfo =
 {
    
name "AdminConnectSounds",
    
author "CollinHell",
    
description "Plays a unique sound for each admin",
    
version PLUGIN_VERSION,
    
url "bucknastysurf.com"
 
}
  
  public 
OnPluginStart()
  {
    
PrintToChatAll("Admin Connect Sounds loaded!")
    new 
String:config_File[64]
    if (!
FileExists("cfg/sourcemod/adminconnectsounds.cfg"))
    {
        
BuildPath(Path_SMconfig_Filesizeof(config_File), "cfg/sourcemod/adminconnectsounds.cfg")
    }
  }
  
  public 
OnMapStart()
  {
    new 
Handle:config OpenFile("cfg/sourcemod/adminconnectsounds.cfg""r");
    if (
config == INVALID_HANDLE)
    {
        
PrintToChatAll("INVALID_HANDLE")
    }
  
    new 
String:preCacheSound[255];
    while (!
IsEndOfFile(config) && ReadFileLine(configpreCacheSoundsizeof(preCacheSound)))
    {
        if (
StrContains(preCacheSound"STEAM"true)!= -|| !IsCharAlpha(preCacheSound[0]))
        {
            continue;
        }
        
PrecacheSound(preCacheSoundtrue)
        
PrintToChatAll("File %s  precatched."preCacheSound
        
//AddFileToDownloadsTable(preCacheSound)
        
PrintToChatAll("File %s added to downloads table."preCacheSound)
    }
    
CloseHandle(config);
    return 
Plugin_Handled;
  }
  
 public 
OnClientAuthorized(client, const String:auth[])
 {
    
PrintToChatAll("Starting OnClientAuthorized...")
    new 
Handle:config OpenFile("cfg/adminconnectsounds.cfg""r");
    if (
config == INVALID_HANDLE)
    {
        
PrintToChatAll("INVALID_HANDLE")
    }
    new 
bool:cfg_Match
    
new String:cfg_Line[255]
    while (!
IsEndOfFile(config) && ReadFileLine(configcfg_Linesizeof(cfg_Line)))
    {
        if (
StrContains(cfg_Line"STEAM"true)!= -1)
        {
            
PrintToChatAll("Line is STEAM...")
            if (
StrEqual(cfg_Lineauthtrue)== true)
            {
                
PrintToChatAll("Line is matching STEAM")
                
cfg_Match true
            
}
        }
        else if (!
IsCharAlpha(cfg_Line[0]))
        {
            
PrintToChatAll("!IsCharAlpha")
            continue;
        }
        else
        {
            
PrintToChatAll("Line is 'else'.")
            if (
cfg_Match == true)
            {
                
PrintToChatAll("cfg_Match == true")
                new 
String:play_Path[200];
                
Format(play_Pathsizeof(play_Path), "play %s"cfg_Line)
                
PrintToChatAll(play_Path)
                new 
play_MaxPlayers GetMaxClients();
                for (new 
1<=play_MaxPlayersi++)
                {
                    if (
IsClientInGame(i))
                    {
                        
ClientCommand(iplay_Path);
                    }
                }
            }
            break;
        }

    }
    
CloseHandle(config);
    return 
Plugin_Handled;
    
    
/* if (StrEqual(auth, "STEAM_0:0:16452962"))
    {
        // Start playing sound to clients
        new String:target_soundPath[200];
        Format(target_soundPath, sizeof(target_soundPath), "play bot/i_am_dangerous.wav");
        new target_playersConnected = GetMaxClients();
        for (new target_playerClient = 1; target_playerClient <= target_playersConnected; target_playerClient++)
        {
            new target_playerInGameStatus = IsClientInGame(target_playerClient);
            if (target_playerInGameStatus == 1)
            {
                ClientCommand(target_playerClient, target_soundPath);
            }
        }
    } */
 

The problem is, even
PHP Code:
PrintToChatAll("Starting OnClientAuthorized..."
doesn't show up. Could OnClientAuthorized() just be not starting at all?

Also, thanks so much for your prompt reply.
__________________
But what about second breakfast?
CollinHell is offline
Monkeys
Veteran Member
Join Date: Jan 2010
Old 07-25-2010 , 16:10   Re: Admin Connect Sounds
Reply With Quote #4

Quote:
SourceMod checks new clients every few frames and calls OnClientAuthorized as soon as it sees valid information. So there is no guarantee as to when OnClientAuthorized will be called (for that, use OnClientPostAdminCheck).
OnClientPostAdminCheck(client)

is your best bet.

http://docs.sourcemod.net/api/index....d=show&id=396&


EDIT: Reading about it, you might need to check if he's admin or not.
__________________
Get a lid on that zombie,
he's never gonna be alri-i-ight.
Oooh get a lid on that zombie,
or he's gonna feed all night.
Monkeys is offline
CollinHell
Junior Member
Join Date: Nov 2009
Location: Ossining, New York
Old 07-25-2010 , 17:55   Re: Admin Connect Sounds
Reply With Quote #5

Thanks! I'm going out now, but I'll give it a try when I get back. After using that, should I use something like
PHP Code:
new AdminId:id GetUserAdmin(client);
if (
id != INVALID_ADMIN_ID)
{
    
GetClientAuthString(clientString:auth[], maxlen);

but are you sure I would need to validate admin status first?
__________________
But what about second breakfast?
CollinHell is offline
Monkeys
Veteran Member
Join Date: Jan 2010
Old 07-25-2010 , 21:06   Re: Admin Connect Sounds
Reply With Quote #6

Quote:
Originally Posted by CollinHell View Post
Thanks! I'm going out now, but I'll give it a try when I get back. After using that, should I use something like
PHP Code:
new AdminId:id GetUserAdmin(client);
if (
id != INVALID_ADMIN_ID)
{
    
GetClientAuthString(clientString:auth[], maxlen);

but are you sure I would need to validate admin status first?
Not sure. But seeing as the description says "this will surely fire after each ClientPutInServer", I think it fires for normal users too (although their admin check will be negative, it'll still be a check)
__________________
Get a lid on that zombie,
he's never gonna be alri-i-ight.
Oooh get a lid on that zombie,
or he's gonna feed all night.
Monkeys is offline
CollinHell
Junior Member
Join Date: Nov 2009
Location: Ossining, New York
Old 07-27-2010 , 22:08   Re: Admin Connect Sounds
Reply With Quote #7

Awesome! I used OnClientPostAdminCheck, and it at least starts the block now, but I'm getting INVALID_HANDLE, which comes from this line here:
PHP Code:
new Handle:config OpenFile("cfg/adminconnectsounds.cfg""r");
        if (
config == INVALID_HANDLE)
        {
            
PrintToChatAll("INVALID_HANDLE")
        } 
I'm gonna go read a little more about this, maybe I have the modes wrong? I saw one addon that had the mod as "rt", but reading the wiki and going to the Pawn website, "t" is not a mode. Could this be a Source-only mode, or was it a mistake by the other coder?
__________________
But what about second breakfast?
CollinHell is offline
Monkeys
Veteran Member
Join Date: Jan 2010
Old 07-27-2010 , 23:00   Re: Admin Connect Sounds
Reply With Quote #8

Quote:
Originally Posted by CollinHell View Post
Awesome! I used OnClientPostAdminCheck, and it at least starts the block now, but I'm getting INVALID_HANDLE, which comes from this line here:
PHP Code:
new Handle:config OpenFile("cfg/adminconnectsounds.cfg""r");
        if (
config == INVALID_HANDLE)
        {
            
PrintToChatAll("INVALID_HANDLE")
        } 
I'm gonna go read a little more about this, maybe I have the modes wrong? I saw one addon that had the mod as "rt", but reading the wiki and going to the Pawn website, "t" is not a mode. Could this be a Source-only mode, or was it a mistake by the other coder?
Well, the file doesn't exist because no computer I know of can store a file in
://cfg/adminconnectsounds.cfg
You need to build a path before using it. Sourcepawn doesn't know how to use a relative path all to well.
So in your case:

PHP Code:
decl String:Path[125] = "";
BuildPath(Path_SMPathsizeof(Path), "cfg/adminconnectsounds.cfg");
new 
Handle:config OpenFile(Path"r");
        if (
config == INVALID_HANDLE)
        {
            
PrintToChatAll("INVALID_HANDLE")
        } 
__________________
Get a lid on that zombie,
he's never gonna be alri-i-ight.
Oooh get a lid on that zombie,
or he's gonna feed all night.
Monkeys is offline
p3tsin
Senior Member
Join Date: Sep 2005
Location: Finland
Old 07-28-2010 , 09:03   Re: Admin Connect Sounds
Reply With Quote #9

Quote:
Originally Posted by Monkeys View Post
Sourcepawn doesn't know how to use a relative path all to well.
Oh?

Quote:
Originally Posted by files.inc
Code:
/**
 * @global All paths in SourceMod natives are relative to the mod folder 
 * unless otherwise noted.
 *
 * Most functions in SourceMod (at least, ones that deal with direct 
 * file manipulation) will support an alternate path specification.
 *
 * If the path starts with the string "file://" and the PathType is 
 * not relative, then the "file://" portion is stripped off, and the 
 * rest of the path is used without any modification (except for 
 * correcting slashes).  This can be used to override the path 
 * builder to supply alternate absolute paths.  Examples:
 *
 * file://C:/Temp/file.txt
 * file:///tmp/file.txt
 */
__________________
plop
p3tsin is offline
Monkeys
Veteran Member
Join Date: Jan 2010
Old 07-28-2010 , 10:21   Re: Admin Connect Sounds
Reply With Quote #10

Quote:
Originally Posted by p3tsin View Post
Oh?
I had no idea. Then why does it always act up on me :/ God damn you, picky SP!
__________________
Get a lid on that zombie,
he's never gonna be alri-i-ight.
Oooh get a lid on that zombie,
or he's gonna feed all night.
Monkeys 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 13:58.


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