Random Music
#1

Hi can anyone help me with adding random music on player spawn
like playaudiostreamforplayer?
Reply
#2

Make an array of audio streams, use the random function to generate a number between 0 and MAX_AUDIO_STREAMS, where MAX_AUDIO_STREAMS is the number of audio streams that you included in your array and use PlayAudioStreamForPlayer(playerid, AudioStreamsArray[random_variable]);

That is the main idea, you should be able to develop it.
Reply
#3

I have this code_
stock RandomMusic(playerid)
{

new rand = random(5);
switch(rand)
{
case 0:
{
PlayAudioStreamForPlayer(playerid, "http://mp3.shmidt.net/files/from_flash/2156/f8d0b9b35fccc03a31d990b62940b9e448febe9db1a41661ce/Nelly_-_Here_Comes_The_Boom.mp3");
}
case 1:
{
PlayAudioStreamForPlayer(playerid, "http://raddad.free.fr/musiquepuce///'Til I collapse.mp3");
}
case 2:
{
PlayAudioStreamForPlayer(playerid, "http://a.tumblr.com/tumblr_lpb606uHE91qhb27eo1.mp3");
}
case 3:
{
PlayAudioStreamForPlayer(playerid, "http://a.tumblr.com/tumblr_m0uvryGX7P1r60k0fo1.mp3");
}
case 4:
{
PlayAudioStreamForPlayer(playerid, "http://mp3ska4ka.ru/audio/107519246/54624629/Roy_Jones_Jr-Go_Hard_Or_Go_Home.mp3");
}
}
}
return 1;
}


public OnPlayerSpawn...
{
RandomMusic(playerid);

but this error:
C:\Users\z\Desktop\zv.pwn(1850) : error 017: undefined symbol "RandomMusic"
1850 : RandomMusic(playerid);
Reply
#4

Remove one of the 3 closing curly brackets '}' between case 4 and return 1, there should be 2 instead of 3.

This is what bad coding style (indentation) leads to, people. Always indent your code!
Reply
#5

I have make to:
case 0:
{
PlayAudioStreamForPlayer(playerid, "http://mp3.shmidt.net/files/from_flash/2156/f8d0b9b35fccc03a31d990b62940b9e448febe9db1a41661ce/Nelly_-_Here_Comes_The_Boom.mp3");
}
case 1:
{
PlayAudioStreamForPlayer(playerid, "http://raddad.free.fr/musiquepuce///'Til I collapse.mp3");
}
case 2:
{
PlayAudioStreamForPlayer(playerid, "http://a.tumblr.com/tumblr_lpb606uHE91qhb27eo1.mp3");
}
case 3:
{
PlayAudioStreamForPlayer(playerid, "http://a.tumblr.com/tumblr_m0uvryGX7P1r60k0fo1.mp3");
}
case 4:
{
PlayAudioStreamForPlayer(playerid, "http://mp3ska4ka.ru/audio/107519246/54624629/Roy_Jones_Jr-Go_Hard_Or_Go_Home.mp3");
}

return 1;
}

compiler complete,but server not on
Reply
#6

Hold on, let me show you how a switch-statement should look:
pawn Код:
stock RandomMusic(playerid)
{
    new rand = random(5);
    switch(rand)
    {
        case 0:
        {
            PlayAudioStreamForPlayer(playerid, "http://mp3.shmidt.net/files/from_flash/2156/f8d0b9b35fccc03a31d990b62940b9e448febe9db1a41661ce/Nelly_-_Here_Comes_The_Boom.mp3");
        }
        case 1:
        {
            PlayAudioStreamForPlayer(playerid, "http://raddad.free.fr/musiquepuce///'Til I collapse.mp3");
        }
        case 2:
        {
            PlayAudioStreamForPlayer(playerid, "http://a.tumblr.com/tumblr_lpb606uHE91qhb27eo1.mp3");
        }
        case 3:
        {
            PlayAudioStreamForPlayer(playerid, "http://a.tumblr.com/tumblr_m0uvryGX7P1r60k0fo1.mp3");
        }
        case 4:
        {
            PlayAudioStreamForPlayer(playerid, "http://mp3ska4ka.ru/audio/107519246/54624629/Roy_Jones_Jr-Go_Hard_Or_Go_Home.mp3");
        }
    }
    return 1;
}
See? It's way cleaner and it's easier to see the matching brackets this way. Use the TAB key to indent your code.
Reply
#7

not function
Reply
#8

You have to be more specific. Provide some errors, or server_log if the compiler doesn't give anything but the server doesn't start up.
Reply
#9

not errors
I complete compiler
but I start server up,but server not start up
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)