02.01.2012, 14:05
(
Last edited by LiamM; 05/01/2012 at 01:07 PM.
)
Creating a music system using 0.3d's PlayAudioStreamForPlayer
What are we going to learn at the end of this?
Your going to have learned how to create a dialog that shows a list of songs and how you can add more to that dialog if you want to at a later date.
What will I need?
All you need is ZCMD for the command that the players will type to display the music players dialog.
So Here We go!
Step One: Creating the dialog define
We need to make our definitions!
For the first part we will #define DIALOG_MUSICPLAYER
So do it like this at the top of your script anywhere you wish, if you already have dialogs, Great! do it there.
Step Two: Creating the command
For this we will be using ZCMD so make sure you have ZCMD if you want this to work!
Now let me explain this a little bit more, what the first line does ( if(!IsPlayerInAnyVehicle) ) checks if the player is in a vehicle, if he isn't they will be sent a message that tells them, they need to be in a vehicle to use this command.
If you would like to use the command without being in a vehicle, just remove that line.
ShowPlayerDialog, this is where we show the player the box with the list of songs. If you look at the 5th field ( The Message ) you will notice it says.
What does \n mean? \n is used to go to the next line, as we are using a list box that shows a list of songs, each song goes onto a new line.
You do not need to name them like I did, Song 1 Song 2 etc. You can name them what ever you like! Just make sure to keep the '\n' there!
Step Three: What to do if the player picks a song
So. We have created the dialog, with the names of the songs but what do we do if a player picks a song?
Under OnDialogResponse we need to put this. Which I will explain after.
So what are we doing here? First of,
This checks to see if the player is viewing the MusicPlayer dialog.
This is a vital part of the dialog, this checks if the player has clicked something on the dialog.
Now here is where we find what song they picked, you may think that the list starts at 1 since its the first thing. That's wrong. List items always start at 0
So this checks if the player clicked the first song, and if they did it plays the song, same with the other listitems, it checks if they picked another song instead.
This is where we play the song for the player, where it says "URL" you will need to change that to the song you wish to play, if you do not have a URL, but have the MP3 file. You can find sites all over the place that you can upload an MP3 file too, then copy the link and paste it in where it says "URL". Remembering to keep " " around the URL, or it won't work.
Here is an example of how to use PlayAudioStreamForPlayer with a valid URL.
Step Four: Adding more songs if you want too.
Well all you have to do is go back to the radio command, and where it says for example I will use this tutorials songs.
If you wish to add another song, all you have to do is \n for a new line, never forget that! and the name of the song you wish to add, here's an example
Don't forget though! You need to go back to OnDialogResponse and add the new listitem or it won't play!
And your done!
I hope this tutorial was helpful and I'm always open for suggestions in the comments to anything I could improve in the tutorial, if I did manage to help ya. Please, please rep me, thanks!
I'd like to thank Doreto for providing this link, this link allows you to upload your MP3 files, then you can copy the URL into your PlayAudioStreamForPlayer
Kiwi 6
What are we going to learn at the end of this?
Your going to have learned how to create a dialog that shows a list of songs and how you can add more to that dialog if you want to at a later date.
What will I need?
All you need is ZCMD for the command that the players will type to display the music players dialog.
So Here We go!
Step One: Creating the dialog define
We need to make our definitions!
For the first part we will #define DIALOG_MUSICPLAYER
So do it like this at the top of your script anywhere you wish, if you already have dialogs, Great! do it there.
pawn Code:
//Anywhere at the top of the script, do not put it in a callback!
#define DIALOG_MUSICPLAYER 1
//This creates a dialog definition which we will use when we ShowPlayerDialog later.
Step Two: Creating the command
For this we will be using ZCMD so make sure you have ZCMD if you want this to work!
pawn Code:
CMD:radio(playerid, params[])
{
if(!IsPlayerInAnyVehicle) return SendClientMessage(playerid, -1, "You need to be in a vehicle to use this command!"); // This is used if you only want people to play the song when their in a vehicle
ShowPlayerDialog(playerid, DIALOG_MUSICPLAYER, DIALOG_STYLE_LIST, "Music Player", "Song 1\nSong 2\nSong 3", "Play", "Close"); //This shows the dialog, notice we used DIALOG_MUSICPLAYER for the dialogid!
return 1;
}
If you would like to use the command without being in a vehicle, just remove that line.
ShowPlayerDialog, this is where we show the player the box with the list of songs. If you look at the 5th field ( The Message ) you will notice it says.
pawn Code:
Song 1\n Song2\n Song 3
You do not need to name them like I did, Song 1 Song 2 etc. You can name them what ever you like! Just make sure to keep the '\n' there!
Step Three: What to do if the player picks a song
So. We have created the dialog, with the names of the songs but what do we do if a player picks a song?
Under OnDialogResponse we need to put this. Which I will explain after.
pawn Code:
public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
if(dialogid == DIALOG_MUSICPLAYER) // This checks to see if the dialog the players viewing is the music player one
{
if(response) // If the player clicked a song
{
if(listitem == 0) // Since this is a list, we check if they clicked the first song on the list.
{
PlayAudioStreamForPlayer(playerid, "URL"); // Play the song
}
if(listitem == 1) // We now check if the player clicked the second song
{
PlayAudioStreamForPlayer(playerid, "URL"); // Play the song
}
if(listitem == 2) // or the third song.
{
PlayAudioStreamForPlayer(playerid, "URL"); // Play the song
}
}
}
return 1;
}
pawn Code:
if(dialogid == DIALOG_MUSICPLAYER)
pawn Code:
if(response)
pawn Code:
if(listitem == 0)
So this checks if the player clicked the first song, and if they did it plays the song, same with the other listitems, it checks if they picked another song instead.
pawn Code:
PlayAudioStreamForPlayer(playerid, "URL");
Here is an example of how to use PlayAudioStreamForPlayer with a valid URL.
pawn Code:
PlayAudioStreamForPlayer(playerid, "http://www.yourwebsite.com/playsong.mp3");
Step Four: Adding more songs if you want too.
Well all you have to do is go back to the radio command, and where it says for example I will use this tutorials songs.
pawn Code:
Song 1\nSong 2\nSong 3
pawn Code:
Song 1\nSong 2\nSong 3\nSong 4
And your done!
I hope this tutorial was helpful and I'm always open for suggestions in the comments to anything I could improve in the tutorial, if I did manage to help ya. Please, please rep me, thanks!
I'd like to thank Doreto for providing this link, this link allows you to upload your MP3 files, then you can copy the URL into your PlayAudioStreamForPlayer
Kiwi 6