Raised This Month: $ Target: $400
 0% 

Precaching and playing sound from ini


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
bibu
Veteran Member
Join Date: Sep 2010
Old 07-17-2011 , 16:20   Precaching and playing sound from ini
Reply With Quote #1

I am trying to play a sound when connecting to the server, stealed much stuff from this plugin:

http://forums.alliedmods.net/showthread.php?p=152101

To what I came:

PHP Code:
#define MAX_SONGS 10

new configsdir[200]
new 
configfile[200]
new 
song[MAX_SONGS][64]
new 
songdir[MAX_SONGS][64]
new 
bool:precached[MAX_SONGS]

/* in precache */

    
new songdir2[64]
    
get_configsdir(configsdir199)
    
format(configfile199"%s/mod/connect_music.ini"configsdir)
    
    new 
trash
    
for(new i=0i<MAX_SONGSi++)
    {
        
precached[i] = false
        read_file
(configfileisong[i], 63trash)
        if(!
equali(song[i][4], ""))
        {
            
format(songdir[i], 63,"mod/%s"song[i])
            
format(songdir263"sound/mod/%s"song[i])
            if(
file_exists(songdir2))
            {
                
precached[i] = true
                
                
if(containi(song[i], ".mp3" ) != -1)
                {
                    
precache_generic(songdir[i])
                }
                else
                {
                    
precache_sound(songdir[i])
                }
            }
        }
    }

/* end precache */

public client_connect(id)
{
    new 
trash
    
for(new i=0i<MAX_SONGSi++)
    {
        
read_file(configfileisong[i], 63trash)
        if(
containi(song[i],".mp3"))
        {
            
client_cmd(id"mp3 play ^"sound/%s^""songdir[i])
        }
        else if(
containi(song[i],".wav"))
        {
            
client_cmd(id"spk ^"%s^""songdir[i])
        }
    }

Inside of my configs/mod/music.ini:

Quote:
blue_win.wav
__________________
Selling tons of my own private works.
Accepting paid work for clans and communities.
Don't hesitate to contact me.
bibu is offline
abdul-rehman
Veteran Member
Join Date: Jan 2010
Location: Khi, Pakistan
Old 07-17-2011 , 17:12   Re: Precaching and playing sound from ini
Reply With Quote #2

So what's the problem ?
__________________

My Plugins For ZP

Inactive due to College and Studies
abdul-rehman is offline
Send a message via Yahoo to abdul-rehman Send a message via Skype™ to abdul-rehman
bibu
Veteran Member
Join Date: Sep 2010
Old 07-17-2011 , 17:29   Re: Precaching and playing sound from ini
Reply With Quote #3

Doesn't play anything.
__________________
Selling tons of my own private works.
Accepting paid work for clans and communities.
Don't hesitate to contact me.
bibu is offline
Hunter-Digital
Veteran Member
Join Date: Aug 2006
Location: In the Game [ro]
Old 07-17-2011 , 17:34   Re: Precaching and playing sound from ini
Reply With Quote #4

Learn to debug yourself man, print a message when the spk command is triggered along with the path and stuff, maybe you got something wrong there.
Also, play the sound manually in the console to make sure it can be played.
__________________
Hunter-Digital is offline
Exolent[jNr]
Veteran Member
Join Date: Feb 2007
Location: Tennessee
Old 07-17-2011 , 21:01   Re: Precaching and playing sound from ini
Reply With Quote #5

PHP Code:
#define MAX_SONGS 10

new configsdir[200]
new 
configfile[200]
new 
song[MAX_SONGS][64]
new 
songdir[MAX_SONGS][64]
new 
bool:ismp3[MAX_SONGS]
new 
numsongs

public plugin_precache()
{
    new 
songdir2[64]
    
get_configsdir(configsdir199)
    
format(configfile199"%s/mod/connect_music.ini"configsdir)
    
    new 
fopen(configfile"rt")
    
    new 
temp[sizeof(song[]) + 1]
    while(
numsongs MAX_SONGS && !feof(f))
    {
        
fgets(ftempcharsmax(temp))
        
trim(temp)
        
        if(
temp[0])
        {
            
format(songdir263"sound/mod/%s"temp)
            
            if(
file_exists(songdir2))
            {
                if(
containi(temp".mp3") > 0)
                {
                    
ismp3[numsongs] = true
                    
                    precache_generic
(songdir2)
                    
copy(songdir[numsongs], 63songdir2)
                }
                else if(
containi(temp".wav") > 0)
                {
                    
formatex(songdir[numsongs], 63"mod/%s"temp)
                    
precache_sound(songdir[numsongs])
                }
                else
                {
                    continue
                }
                
                
numsongs++
            }
        }
    }
    
    
fclose(f)
}

public 
client_connect(id)
{
    if(
numsongs)
    {
        new 
random(numsongs)
        
client_cmd(id"%s ^"%s^""ismp3[i] ? "mp3 play" "spk"songdir[i])
    }

__________________
No private work or selling mods.
Quote:
Originally Posted by xPaw View Post
I love you exolent!

Last edited by Exolent[jNr]; 07-22-2011 at 09:08.
Exolent[jNr] is offline
e12harry
Member
Join Date: Apr 2010
Old 07-18-2011 , 02:59   Re: Precaching and playing sound from ini
Reply With Quote #6

Correct me if I am wrong but you are reading file (configs/mod/connect_music.ini):

get_configsdir(configsdir, 199)
format(configfile, 199, "%s/mod/connect_music.ini", configsdir)



and then you say that you have something in "configs/mod/music.ini"
Different files?

Check also Exolent[jNr] code above. Useprecache_generic(songdir2)
not

precache_generic
(songdir)
e12harry is offline
deadman909
Veteran Member
Join Date: Oct 2008
Old 07-18-2011 , 11:36   Re: Precaching and playing sound from ini
Reply With Quote #7

Just use this one.

Music goes in the fallowing directory: sound/misc/loading/
Meaning it goes in the folder called: loading

You may have to create the folders misc and than loading if you dont already have them.

PHP Code:
#include <amxmodx>
#define Maxsounds 5
#define DEBUG 0

new soundlist[Maxsounds][64]
new 
soundCount 0

public plugin_init() {
    
register_plugin("Loading Music","0.9","Andrax2000")
    return 
PLUGIN_CONTINUE
}

public 
plugin_precache() {
        new 
dh
        
new nameFull[64], name[64], nameExt[32]

        
dh open_dir("sound/misc/loading"nameFull63)

        do
    {
                
strtok(nameFull,name,63,nameExt,31,'.')
                if (
equali(nameExt"mp3")) {
#if DEBUG==1
                        
server_print("[AMXX LOADING MUSIC] Found %s "nameFull)
#endif
                        
soundlist[soundCount] = name
                        soundCount
++
                }
        }
    while(
soundCount<Maxsounds && next_file(dhnameFull63))
        
    
close_dir(dh)
    
server_print("[AMXX LOADING MUSIC] Found %i mp3s"soundCount)
    for (new 
0soundCounti++)
    {
        
format(name63"sound/misc/loading/%s.mp3",soundlist[i])
#if DEBUG==1
        
server_print("[AMXX LOADING MUSIC] Precaching %s "name)
#endif
        
precache_generic(name)        
    }
    return 
PLUGIN_CONTINUE
}

public 
client_connect(id) {
    new 
i
    i 
random_num(0,soundCount-1)
    
client_cmd(id,"mp3 play sound/misc/loading/%s",soundlist[i])
    return 
PLUGIN_CONTINUE

__________________

deadman909 is offline
Send a message via MSN to deadman909 Send a message via Yahoo to deadman909
Exolent[jNr]
Veteran Member
Join Date: Feb 2007
Location: Tennessee
Old 07-18-2011 , 11:43   Re: Precaching and playing sound from ini
Reply With Quote #8

Quote:
Originally Posted by deadman909 View Post
Just use this one.
Unnecessary 2nd loop for precache.
No .wav support.
All sounds must be in same folder, so if wanted to use an existing sound, players must have to download it again in new directory.
Bad method to copy string into sound list.
__________________
No private work or selling mods.
Quote:
Originally Posted by xPaw View Post
I love you exolent!
Exolent[jNr] is offline
bibu
Veteran Member
Join Date: Sep 2010
Old 07-20-2011 , 17:12   Re: Precaching and playing sound from ini
Reply With Quote #9

Wow exactly, thanks.
However I get this:

Quote:
Warning: Symbol is never used: "song".
And the sound doesn't play. The sound is in "sound/mod/mysound.wav". Inside of my ini file:

"mysound.wav"

When I try to play the sound like this, it works:

"spk mod/mysound.wav"
__________________
Selling tons of my own private works.
Accepting paid work for clans and communities.
Don't hesitate to contact me.
bibu is offline
Exolent[jNr]
Veteran Member
Join Date: Feb 2007
Location: Tennessee
Old 07-20-2011 , 18:49   Re: Precaching and playing sound from ini
Reply With Quote #10

Remove quotes from around the sound file.
__________________
No private work or selling mods.
Quote:
Originally Posted by xPaw View Post
I love you exolent!
Exolent[jNr] 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 00:58.


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