Raised This Month: $ Target: $400
 0% 

Precache sounds from file


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
FiFiX
Senior Member
Join Date: May 2008
Location: Poland
Old 04-04-2009 , 04:26   Precache sounds from file
Reply With Quote #1

Hello. How to mace function that will precache sounds from .ini file. FE:
In sounds.ini I've got:
Code:
"sounds/FiFiX/1.wav"
"sounds/FiFiX/2.mp3"
"sounds/FiFiX/3.wav"
"sounds/FiFiX/4.mp3"
And I want to play it radomly by command.
FiFiX is offline
Send a message via Skype™ to FiFiX
TheRadiance
Senior Member
Join Date: Nov 2007
Location: Kazakhstan
Old 04-04-2009 , 05:19   Re: Precache sounds from file
Reply With Quote #2

PHP Code:
#include < amxmodx >
#include < amxmisc >

new g_szPrecached 32 ] [ 64 ]

public 
plugin_init ( )
{
    
register_plugin "PrecacheSound""1.0""FiFiX" )
    
set_task random_float 5.015.0 ), "Task_PlaySounds")
}

public 
plugin_precache ( )
{
    new 
szPath 64 ]
    
get_configsdir szPathsizeof szPath ) - )
    
format szPathsizeof szPath ) - 1"%s/sounds.ini"szPath )

    if ( !
file_exists szPath ) )
        return

    new 
iCount

    
for ( new 0file_size szPath); ++ )
    {
        new 
szText 64 ]
        new 
iLen
        read_file 
szPathaszTextsizeof szText ) - 1iLen )

        if ( ( 
szText ] != ';' ) && (szText ] != '/' ) && file_exists szText ) )
        {
            
g_szPrecached iCount++ ] = szText
            precache_sound 
szText )
        }
    }
}

public 
Task_PlaySounds ( )
{
    
client_cmd 0"spk ^"%s^""g_szPrecached random 32 ) ] )
    
set_task random_float 5.015.0 ), "Task_PlaySounds")


Last edited by TheRadiance; 04-04-2009 at 05:44.
TheRadiance is offline
Send a message via ICQ to TheRadiance
ConnorMcLeod
Veteran Member
Join Date: Jul 2006
Location: France (95)
Old 04-04-2009 , 05:22   Re: Precache sounds from file
Reply With Quote #3

Better to use "new" files natives rather than read_file, but it's less important in plugin_precache.
__________________
- tired and retired -

- my plugins -
ConnorMcLeod is offline
FiFiX
Senior Member
Join Date: May 2008
Location: Poland
Old 04-04-2009 , 05:23   Re: Precache sounds from file
Reply With Quote #4

@up
What it exactly mean?

And how to radomly play sounds?
Also would be great if amx will log sounds which it precached.
FiFiX is offline
Send a message via Skype™ to FiFiX
TheRadiance
Senior Member
Join Date: Nov 2007
Location: Kazakhstan
Old 04-04-2009 , 05:28   Re: Precache sounds from file
Reply With Quote #5

Quote:
Better to use "new" files natives rather than read_file, but it's less important in plugin_precache.
I know, but i've never used "new" file natives ( don't know how ), because of this i'm always use old method .
Quote:
And how to radomly play sounds?
Also would be great if amx will log sounds which it precached.
I've added a console command, check the script.
TheRadiance is offline
Send a message via ICQ to TheRadiance
FiFiX
Senior Member
Join Date: May 2008
Location: Poland
Old 04-04-2009 , 05:39   Re: Precache sounds from file
Reply With Quote #6

But I want play it from plugin.
It would be:
Code:
#include < amxmodx > 
#include < amxmisc > 

new g_szPrecached [ 32 ] [ 64 ] 

public plugin_init ( ) 
{ 
    register_plugin ( "PrecacheSound", "1.0", "FiFiX" ) 
} 

public plugin_precache ( ) 
{ 
    new szPath [ 64 ] 
    get_configsdir ( szPath, sizeof ( szPath ) - 1 ) 
    format ( szPath, sizeof ( szPath ) - 1, "%s/sounds.ini", szPath ) 

    if ( !file_exists ( szPath ) ) 
        return 

    new iCount 

    for ( new a = 0; a < file_size ( szPath, 1 ); a ++ ) 
    { 
        new szText [ 64 ] 
        new iLen 
        read_file ( szPath, a, szText, sizeof ( szText ) - 1, iLen ) 

        if ( ( szText [ 0 ] != ';' ) && (szText [ 0 ] != '/' ) && file_exists ( szText ) ) 
        { 
            g_szPrecached [ iCount++ ] = szText 
            precache_sound ( szText ) 
        } 
    } 
} 

public Command_PlaySound ( ) 
{ 

    client_cmd ( 0, "spk ^"%s^"", g_szPrecached [ random ( 32 ) ] ) 

    return PLUGIN_HANDLED 
}

And in plugin just add:
Code:
Command_PlaySound();

Last edited by FiFiX; 04-04-2009 at 05:45.
FiFiX is offline
Send a message via Skype™ to FiFiX
FiFiX
Senior Member
Join Date: May 2008
Location: Poland
Old 04-08-2009 , 17:26   Re: Precache sounds from file
Reply With Quote #7

Quote:
Originally Posted by FiFiX View Post
But I want play it from plugin.
It would be:
Code:
#include < amxmodx > 
#include < amxmisc > 

new g_szPrecached [ 32 ] [ 64 ] 

public plugin_init ( ) 
{ 
    register_plugin ( "PrecacheSound", "1.0", "FiFiX" ) 
} 

public plugin_precache ( ) 
{ 
    new szPath [ 64 ] 
    get_configsdir ( szPath, sizeof ( szPath ) - 1 ) 
    format ( szPath, sizeof ( szPath ) - 1, "%s/sounds.ini", szPath ) 

    if ( !file_exists ( szPath ) ) 
        return 

    new iCount 

    for ( new a = 0; a < file_size ( szPath, 1 ); a ++ ) 
    { 
        new szText [ 64 ] 
        new iLen 
        read_file ( szPath, a, szText, sizeof ( szText ) - 1, iLen ) 

        if ( ( szText [ 0 ] != ';' ) && (szText [ 0 ] != '/' ) && file_exists ( szText ) ) 
        { 
            g_szPrecached [ iCount++ ] = szText 
            precache_sound ( szText ) 
        } 
    } 
} 

public Command_PlaySound ( ) 
{ 

    client_cmd ( 0, "spk ^"%s^"", g_szPrecached [ random ( 32 ) ] ) 

    return PLUGIN_HANDLED 
}

And in plugin just add:
Code:
Command_PlaySound();
Hey, how to add here line which will log precached files into log_amx and how to make if extention is different than mp3 or wav plugin logs unknow extention and precache another file.
FiFiX is offline
Send a message via Skype™ to FiFiX
TheRadiance
Senior Member
Join Date: Nov 2007
Location: Kazakhstan
Old 04-04-2009 , 05:44   Re: Precache sounds from file
Reply With Quote #8

Quote:
But I want play it from plugin.
Check my script again.
TheRadiance is offline
Send a message via ICQ to TheRadiance
ConnorMcLeod
Veteran Member
Join Date: Jul 2006
Location: France (95)
Old 04-04-2009 , 05:48   Re: Precache sounds from file
Reply With Quote #9

Example on hw to precache .mp3 files :

PHP Code:
public plugin_precache() {
    new 
configfile[64]
    
get_configsdir(configfile63)
    
format(configfile63"%s/loadingsongs.ini"configfile)

// should be useless
//    if(!file_exists(configfile))
//        return

//    g_Sounds = ArrayCreate(128)

    
new File fopen(configfile"rt")
    if(!
File)
        return
    new 
Text[256], Sound[128]
    while(!
feof(File))
    {
        
fgets(FileText255)
        
trim(Text)
        if(!
Text[0] || Text[0] == ';' || (Text[0] == '/' && Text[1] == '/'))
            continue
        
parse(TextSound127)
        if(!
equaliSound[strlen(Sound)-4], ".mp3"))
        {
    
//        log_amx("Fichier %s ne porte pas l'extension ^".mp3^"", Sound)
            
continue
        }
        if(!
file_exists(Sound))
        {
    
//        log_amx("Fichier %s inexistant", Sound)
            
continue
        }
//        ArrayPushString(g_Sounds, Sound)
        
precache_generic(Sound)
    }
    
fclose(File)

__________________
- tired and retired -

- my plugins -
ConnorMcLeod is offline
FiFiX
Senior Member
Join Date: May 2008
Location: Poland
Old 04-04-2009 , 05:46   Re: Precache sounds from file
Reply With Quote #10

Heh Okay, Look for my edited. I want to place line in plugin hmm f.e. When player connect, and when he disconnects.
In:
Code:
public client_connect(id)
I'll just add:
Code:
Command_PlaySound( );
FiFiX is offline
Send a message via Skype™ to FiFiX
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 02:21.


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