AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Precaching and playing sound from ini (https://forums.alliedmods.net/showthread.php?t=162333)

bibu 07-17-2011 16:20

Precaching and playing sound from ini
 
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

abdul-rehman 07-17-2011 17:12

Re: Precaching and playing sound from ini
 
So what's the problem ? :|

bibu 07-17-2011 17:29

Re: Precaching and playing sound from ini
 
Doesn't play anything.

Hunter-Digital 07-17-2011 17:34

Re: Precaching and playing sound from ini
 
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.

Exolent[jNr] 07-17-2011 21:01

Re: Precaching and playing sound from ini
 
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])
    }



e12harry 07-18-2011 02:59

Re: Precaching and playing sound from ini
 
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)

deadman909 07-18-2011 11:36

Re: Precaching and playing sound from ini
 
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



Exolent[jNr] 07-18-2011 11:43

Re: Precaching and playing sound from ini
 
Quote:

Originally Posted by deadman909 (Post 1513099)
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.

bibu 07-20-2011 17:12

Re: Precaching and playing sound from ini
 
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"

Exolent[jNr] 07-20-2011 18:49

Re: Precaching and playing sound from ini
 
Remove quotes from around the sound file.


All times are GMT -4. The time now is 00:58.

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