[HELP] Playing random audiostreams
#1

How can i make that it playes random audiostreams like link1 link2 etc ?

EDIT:

Is this right ?

Код:
				new success = random(2);
				if(success == 1)
				{
				PlayAudioStreamForPlayer(i, "http");
				}
				if(success == 2)
				{
				PlayAudioStreamForPlayer(i, "http");
				}
Reply
#2

Quote:
Originally Posted by Jimbo01
Посмотреть сообщение
How can i make that it playes random audiostreams like link1 link2 etc ?

EDIT:

Is this right ?

Код:
				new success = random(2);
				if(success == 1)
				{
				PlayAudioStreamForPlayer(i, "http");
				}
				if(success == 2)
				{
				PlayAudioStreamForPlayer(i, "http");
				}
You can test it by yourself. I thinks its right
Reply
#3

yep, that is right, but I would do this (more organized)

pawn Код:
new rid = random(5);
switch(rid)
{
    case 1: { PlayAudioStreamForPlayer(i, "url here"); }
    case 2: { PlayAudioStreamForPlayer(i, "url here"); }
    case 3: { PlayAudioStreamForPlayer(i, "url here"); }
    case 4: { PlayAudioStreamForPlayer(i, "url here"); }
    case 5: { PlayAudioStreamForPlayer(i, "url here"); }
}
Reply
#4

Код:
switch(random(2))
{
	case 0:
	{
		PlayAudioStreamForPlayer(i, "http url here");
	}
	case 1:
	{
		PlayAudioStreamForPlayer(i, "http url here");
	}
}
  • Indent your code properly, it helps a lot and it looks better.
  • If you're choosing between numbers, use 'switch' instead of 'if'. (Like above)
  • Random(2) gives a random number BENEATH 2, so it outputs 0 or 1, but NEVER 2.
Reply
#5

Quote:
Originally Posted by admigo
Посмотреть сообщение
You can test it by yourself. I thinks its right
Quote:
Originally Posted by Pizzy
Посмотреть сообщение
yep, that is right, but I would do this (more organized)

pawn Код:
new rid = random(5);
switch(rid)
{
    case 1: { PlayAudioStreamForPlayer(i, "url here"); }
    case 2: { PlayAudioStreamForPlayer(i, "url here"); }
    case 3: { PlayAudioStreamForPlayer(i, "url here"); }
    case 4: { PlayAudioStreamForPlayer(i, "url here"); }
    case 5: { PlayAudioStreamForPlayer(i, "url here"); }
}
No, it's NOT right. Let me quickly explain. random(5) (for example) runs a random number from 0 to 4. It doesn't count 5 in. So, it should be
Код:
switch(random(5))
{
	case 0: { PlayAudioStreamForPlayer(i, "url here"); }
	case 1: { PlayAudioStreamForPlayer(i, "url here"); }
	case 2: { PlayAudioStreamForPlayer(i, "url here"); }
	case 3: { PlayAudioStreamForPlayer(i, "url here"); }
	case 4: { PlayAudioStreamForPlayer(i, "url here"); }
}
I mean seriously, don't you know the basics of computer languages? That cells start at 0 and not 1?
Reply
#6

Thanks all
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)