SA-MP Forums Archive
Can I use several songs? - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Can I use several songs? (/showthread.php?tid=472821)



Can I use several songs? - Songason - 30.10.2013

So on public OnPlayerConnect(playerid) I have that a song plays till you clicked spawn.

Can I set different songs so it's like a different song everytime you relog?

Code currently:
Код:
public OnPlayerConnect(playerid)
{
	for (new i = 0; i < 4; i ++)
	{
	    DriveThruItems[playerid][i] = 0;
	}
	if(Security != 0)
	{
	    SendClientMessage(playerid, COLOR_YELLOW, "Host has broken one of the Agreement rules, action has been taken.");
	    Kick(playerid);
	    return 1;
	}
	gPlayerLoggin{playerid} = 1;
	TextDrawShowForPlayer(playerid, Website);
	gPlayerAnimLibsPreloaded[playerid] = 0;
	gActivePlayers[playerid]++;
	ShowArea(playerid);
	numplayers++;
 	Spawned[playerid] = 0;
	BusID[playerid] = 0;
	BusCost[playerid] = 0;
	PlayerSitting[playerid] = 0;
 	PlayAudioStreamForPlayer(playerid,"not necessary atm for you guys ;p");



Re: Can I use several songs? - Songason - 30.10.2013

Help please.


Re: Can I use several songs? - RayDcosta - 31.10.2013

u can do something like using a random number.
it cant ensure u listen to a different song every time, but most of the times the user will hear a different song.
make a switch case.
with numbers from 1 to x (x is the total number of songs u have)
so assuming its 1 to 10
make a random number chooser like rand(1,x+1) [remember to put x+1 cause then it will choose a random number from 1 to x]
after that, make switch cases from 1 to x like i said and have this random number chooser right above that.
so every time the user logs in, it chooses like a random number from 1 to x.
and then based on that a song is selected and played. hope i helped u.
cheers


Re: Can I use several songs? - Songason - 31.10.2013

Quote:
Originally Posted by RayDcosta
Посмотреть сообщение
u can do something like using a random number.
it cant ensure u listen to a different song every time, but most of the times the user will hear a different song.
make a switch case.
with numbers from 1 to x (x is the total number of songs u have)
so assuming its 1 to 10
make a random number chooser like rand(1,x+1) [remember to put x+1 cause then it will choose a random number from 1 to x]
after that, make switch cases from 1 to x like i said and have this random number chooser right above that.
so every time the user logs in, it chooses like a random number from 1 to x.
and then based on that a song is selected and played. hope i helped u.
cheers
Alright, but where should I put the ehhh rand[1,x+1). My code for example:

Код:
new
	a = 5;
switch (a)
{
	case 1:
	{
		song
	}
	case 2:
	{
		song
	}
	case 5:
	{
		song
	}
	default:
	{
		song
	}
}



Re: Can I use several songs? - Elorreli - 31.10.2013

Quote:
Originally Posted by Songason
Посмотреть сообщение
Alright, but where should I put the ehhh rand[1,x+1). My code for example:

Код:
new
	a = 5;
switch (a)
{
	case 1:
	{
		song
	}
	case 2:
	{
		song
	}
	case 5:
	{
		song
	}
	default:
	{
		song
	}
}
new a = random(5);

Starts with ID 0 tho, could always +1.


AW: Can I use several songs? - BigETI - 31.10.2013

pawn Код:
static const music_arr[][] =
{
    "Link 1st",
    "Link 2nd",
    "Link 3rd",
    // ...
    "Link nth"
}; // An array

public OnPlayerConnect(playerid)
{
    // Your code...
    PlayAudioStreamForPlayer(playerid, music_arr[random(sizeof music_arr)]);
    return 1;
}
nuff' said.