AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   playing sound does not work (https://forums.alliedmods.net/showthread.php?t=240916)

proffs 05-24-2014 13:15

playing sound does not work
 
I have this on my BM but it wont play or preache any sound file.


PHP Code:

new g_sound_music[][] =
{      
        
"sound/misc/sg1.mp3",
        
"sound/misc/sg2.mp3",
        
"sound/misc/sg3.mp3",
        
"sound/misc/sg4.mp3",
        
"sound/misc/sg5.mp3"
 
};

new 
bool:g_BlockMusic;


public 
plugin_precache()
{

        for(new 
i=0i<sizeof(g_sound_music); i++)
        {
                
precache_generic(g_sound_music[i]);
        }
}



public 
ActionMusic()
{
        if(!
g_BlockMusic)
        {
                new 
rand random(sizeof(g_sound_music));
                new 
command[128];
                
format(commandcharsmax(command), "mp3 play %s"g_sound_music[rand]);
                new 
iPlayers[32], iNum;
                
get_players(iPlayersiNum);
                for(new 
i=0;i<=iNum;i++)
                {
                        new 
id iPlayers[i];
                        if(
is_user_connected(id))
                        {
                                
client_cmd(idcommand);
                        }
                }
                
g_BlockMusic true;
                
set_task(40.0"AllowMusic");
        }
}
 
public 
AllowMusic()
{
        
g_BlockMusic true;



Fuck For Fun 05-24-2014 13:29

Re: playing sound does not work
 
Code:

format(command, charsmax(command), "mp3 play %s", g_sound_music[rand]);
:arrow:
Code:

format(command, charsmax(command), "mp3 play ^"%s^"", g_sound_music[rand]);

proffs 05-24-2014 13:40

Re: playing sound does not work
 
Quote:

Originally Posted by Fuck For Fun (Post 2141980)
Code:

format(command, charsmax(command), "mp3 play %s", g_sound_music[rand]);
:arrow:
Code:

format(command, charsmax(command), "mp3 play ^"%s^"", g_sound_music[rand]);

Still not working, It doesn't even preache the sounds!

Fuck For Fun 05-24-2014 14:02

Re: playing sound does not work
 
It's so weird, I'm not used to working with such a messy code
Try this:

Code:

new g_sound_music[][] =
{     
        "misc/sg1.mp3",
        "misc/sg2.mp3",
        "misc/sg3.mp3",
        "misc/sg4.mp3",
        "misc/sg5.mp3"
 
};

new bool:g_BlockMusic;


public plugin_precache()
{
   
        for ( new i = 0; i < sizeof g_sound_music; i++ )
        precache_sound( g_sound_music[ i ] );   
}



public ActionMusic()
{
        if(!g_BlockMusic)
        {
                new rand = random(sizeof(g_sound_music));
                new command[128];
                format(command, charsmax(command), "mp3 play ^"sound/%s^"", g_sound_music[rand]);
                new iPlayers[32], iNum;
                get_players(iPlayers, iNum);
                for(new i=0;i<=iNum;i++)
                {
                        new id = iPlayers[i];
                        if(is_user_connected(id))
                        {
                                client_cmd(id, command);
                        }
                }
                g_BlockMusic = true;
                set_task(40.0, "AllowMusic");
        }
}
 
public AllowMusic()
{
        g_BlockMusic = true;
}


Flick3rR 05-24-2014 16:37

Re: playing sound does not work
 
Hahaha, bros! Really funny! :D
Just the bool in the task should become FALSE. Repeat - false! Because in the function the check is for false, and it's setted on true. Therefore, to work second time and play song again after 40 secs, the bool should be false in the task. Funny, yeah :D That's why it's playing only one song.


All times are GMT -4. The time now is 09:37.

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