[Tutorial] How to make a music dialog
#1

Hi guys it's Sellize.


In this tutorial I'm going to explain how to make a dialog that can play music.
Alright, so first of all make sure at the top of your script it says "#include <a_samp>"

Now, we are going to make it a FS but you can make it a gamemode too. To make it a filterscript we remove the "//" from the "#define FILTERSCRIPT".

Now that we have done that we can go and look for this:


pawn Code:
public OnPlayerCommandText(playerid, cmdtext[]) // If a player types a command
{
    if (strcmp("/mycommand", cmdtext, true, 10) == 0) // The command
    {
        // Do something here
        return 1;
    }
    return 0;
}
Now that we found this, we are going to change the "mycommand" to something you want to be used to open your dialog. In this tutorial i will use "/music"

pawn Code:
public OnPlayerCommandText(playerid, cmdtext[]) // If a player types a command
{
    if (strcmp("/music", cmdtext, true, 10) == 0) // The command has been changed to music now.
    {
        // Do something here
        return 1;
    }
    return 0;
}
Alright, now we can start creating the dialog. A dialog is very simple to understand, here take a look:

pawn Code:
ShowPlayerDialog(// THe player, //The id we are going to assign, //The style, // The title, // Our music list, // First button, //second button)
At the first thing, (player) we are going to put "playerid" this will open the dialog for the player that types the command!

pawn Code:
ShowPlayerDialog(playerid, //The id we are going to assign, //The style, // The title, // Our music list, // First button, //second button)
The second thing (Dialog id) will be the id number we are going to call our dialog, this can be anything. I recommend make it a weird number to not cause any problems with other scripts. In this case i will call it "id 4576"

pawn Code:
ShowPlayerDialog(playerid, 4576, //The style, // The title, // Our music list, // First button, //second button)
The style will be "DIALOG_STYLE_LIST" since we want to have multiple music to listen to!

pawn Code:
ShowPlayerDialog(playerid, 4576, DIALOG_STYLE_LIST, // The title, // Our music list, // First button, //second button)
The title is the text that will be ontop of our dialog (Can't be clicked) I will call it Music

pawn Code:
ShowPlayerDialog(playerid, 4576, DIALOG_STYLE_LIST, "Music", // Our music list, // First button, //second button)
The list will contain our music (Clickable) to make multiple lines we use "\n" between words!

pawn Code:
ShowPlayerDialog(playerid, 4576, DIALOG_STYLE_LIST, "Music","Jingle bells\nMore music", // First button, //second button)
The first button will be the left button in our dialog, in my case I will call it "Select"! The second button will be the right button! I will call it "Cancel"

pawn Code:
ShowPlayerDialog(playerid, 4576, DIALOG_STYLE_LIST, "Music","Jingle bells\nMore music", "Select", "Cancel")
Great! Our dialog is almost done! Now we need a way to open it. We do that by putting the line we just made at the OnPlayerCommandText. Like this:

pawn Code:
public OnPlayerCommandText(playerid, cmdtext[])
{
    if (strcmp("/mycommand", cmdtext, true, 10) == 0)
    {
        ShowPlayerDialog(playerid, 4576, DIALOG_STYLE_LIST, "Music","Jingle bells\nMore music", "Select","Cancel"); // Like that
        return 1;
    }
    return 0;
}
Also do not forget to put ";" after the dialog line!

Alright, the dialog is done! but we still need to set it so that it will play our music!
This is all explained in the following code i made:


pawn Code:
//We look for OnDialogResponse and put the following in:
public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
if(response) // If he clicks the first button
    {
    switch(dialogid)
        {
        case 4576: // The case = our dialog id
            {
            switch(listitem)
            {
                case 0: // If he selects the first option
                {
                    SendClientMessage(playerid, 0xFFFFFF, "Now playing MUSICNAME.");
                    PlayAudioStreamForPlayer(playerid, "PUT YOUR .MP3 LINK HERE"); // Insert your own mp3 link, I'm not going to explain this!
                }
                case 1: // If the user selects the second option
                {
                    SendClientMessage(playerid, 0xFFFFFF, "Now playing MUSICNAME."); // This will send a message to the player saying That the music is playing (Put in your music name)
                    PlayAudioStreamForPlayer(playerid, "PUTYOUR .MP3 LINK HERE"); // Insert your own mp3 link, I'm not going to explain this!
                }
            }
            }
    }
    }
return 1;
}
Thats it! You got your own music dialog! I hope you learnt something, sorry for my horrible Englsih!
Reply
#2

Nice, But How To Stop The Music?
Reply
#3

Quote:
Originally Posted by faiznurfaza
View Post
Nice, But How To Stop The Music?
To stop the music you put this in a command:
pawn Code:
StopAudioStreamForPlayer(playerid); // Stop the audio stream
Reply
#4

Thanks For Tut Sir.
Reply
#5

Quote:
Originally Posted by faiznurfaza
View Post
Thanks For Tut Sir.
That's okay
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)