[Tutorial] Dialog Music Player (STRCMP, DCMD... )
#1

Welcome to my tutorial on creating a dialog music player.

First, we will need direct links to the MP3 or radiostation or other files.

Keep them in a notepad file for now.

I have "http://brp.comlu.com/downloads/loginaudio.mp3" I'll just use that for them all.


Second You want to create the command it self.

if you are using strcmp:

under OnPlayerCommandText

put the command you want
pawn Code:
if(strcmp(cmd, "/heal", true) == 0)
then we want the dialog to show.

here is ShowPlayerDialog explained:

pawn Code:
ShowPlayerDialog(playerid, dialogid, DIALOG_STYLE_LIST, Dialog Title"", MenuItems"", Button 1: "Stop Music", Button 2:"Exit");
  • playerid - to show the dialog to the player that typed the cmd
  • dialogid - the id of the dialog to link it with OnDialogResponse
  • DIALOG_STYLE_LIST - The type of dialog it is
  • Dialog Title - simply the title of the dialog e.g. "Music Player"
  • Menu Items - the items in the menu, seperate with \n
  • Button 1 - the first button, I have "Stop Music"
  • Button 2 - The second button - I have "Exit"
here is mine :
pawn Code:
ShowPlayerDialog(playerid, 2, DIALOG_STYLE_LIST, "Music Player", "Music No 1\nNo 2\n No 3\n No 4\n No5", "Stop Music", "Exit");
You want to add that line followed by return 1; then bracket the cmd of.

My strcmp cmd:

pawn Code:
if(strcmp(cmd, "/music", true) == 0)
 {
    ShowPlayerDialog(playerid, 2, DIALOG_STYLE_LIST, "Music Player", "Music No 1\nNo 2\n No 3\n No 4\n No5", "Stop Music", "Exit");
    return 1;
 }

DCMD :
pawn Code:
dcmd_music(playerid, params[])
 {
    ShowPlayerDialog(playerid, 2, DIALOG_STYLE_LIST, "Music Player", "Music No 1\nNo 2\n No 3\n No 4\n No5", "Stop Music", "Exit");
    return 1;
 }
pawn Code:
public OnPlayerCommandText(playerid, cmdtext[])
{
    dcmd(music, 5, cmdtext);
    return 0;
}
I don't need to explain anymore on simple cmds....

Third
We want the buttons to actually do something...

so search for
pawn Code:
public OnDialogResponse
Now we want the check to see if they opened the right dialog, using the dialog id you put; I put 2 for the dialog ID.

then we want the base of the code

pawn Code:
public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
    if(dialogid == 2)
    {
        if(response)
        {
            switch(listitem)
            {
                case 0:
                {
                    //Selected Item: "Music No 1"
                }
                case 1:
                {
                    //Selected Item: "No 2"
                }
                case 2:
                {
                    //Selected Item: " No 3"
                }
                case 3:
                {
                    //Selected Item: " No 4"
                }
                case 4:
                {
                    //Selected Item: " No5"
                }
            }
        }
        else
        {
            //The player has pressed "Stop Music".
            switch(listitem
            {
                case 0:
                {
                    //Selected Item: "Music No 1"
                }
                case 1:
                {
                    //Selected Item: "No 2"
                }
                case 2:
                {
                    //Selected Item: " No 3"
                }
                case 3:
                {
                    //Selected Item: " No 4"
                }
                case 4:
                {
                    //Selected Item: " No5"
                }
            }
        }
    }
    return 0;
}
Explained :
  • First check (if(dialogid) == 2) - thats checking if its the right dialog (put your dialog id you entered on the ShowPlayerDialog on the second option
  • if(response) - if they double clicked on the item, add the PlayAudioStreamForPlayer(playerid, URL:"");
  • case 0 - what ever amount of music you have - its the menu item, case 0 is the first song
  • } else { - Button 2 - Stop Music, place StopAudioStreamForPlayer(playerid); under each case
After you have scripted it... it should look like this!
pawn Code:
public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
    if(dialogid == 2)
    {
        if(response)
        {
            switch(listitem))
            {
                case 0:
                {
                    //Selected Item: "Music No 1"
                    PlayAudioStreamForPlayer(playerid, "http://brp.comlu.com/downloads/loginaudio.mp3");
                    return 1;
                }
                case 1:
                {
                    //Selected Item: "No 2"
                    PlayAudioStreamForPlayer(playerid, "http://brp.comlu.com/downloads/loginaudio.mp3");
                    return 1;
                }
                case 2:
                {
                    //Selected Item: " No 3"
                    PlayAudioStreamForPlayer(playerid, "http://brp.comlu.com/downloads/loginaudio.mp3");
                    return 1;
                }
                case 3:
                {
                    //Selected Item: " No 4"
                    PlayAudioStreamForPlayer(playerid, "http://brp.comlu.com/downloads/loginaudio.mp3");
                    return 1;
                }
                case 4:
                {
                    //Selected Item: " No5"
                    PlayAudioStreamForPlayer(playerid, "http://brp.comlu.com/downloads/loginaudio.mp3");
                    return 1;
                }
            }
        }
        else
        {
            //The player has pressed "Stop Music".
            StopAudioStreamForPlayer(playerid);
            switch(listitem
            {
                case 0:
                {
                    //Selected Item: "Music No 1"
                    StopAudioStreamForPlayer(playerid);
                    return 1;
                }
                case 1:
                {
                    //Selected Item: "No 2"
                    StopAudioStreamForPlayer(playerid);
                    return 1;
                }
                case 2:
                {
                    //Selected Item: " No 3"
                    StopAudioStreamForPlayer(playerid);
                    return 1;
                }
                case 3:
                {
                    //Selected Item: " No 4"
                    StopAudioStreamForPlayer(playerid);
                    return 1;
                }
                case 4:
                {
                    //Selected Item: " No5"
                    StopAudioStreamForPlayer(playerid);
                    return 1;
                }
            }
        }
    }
    return 0;
}
Reply
#2

bump.
Reply
#3

Quote:
Originally Posted by vincee
View Post
bump.
ROFL !!! This shit just made my day.
Reply
#4

Quote:
Originally Posted by =WoR=G4M3Ov3r
View Post
ROFL !!! This shit just made my day.
For what reason, within every comment or response you make comes nothing generally productive? Are you just 'hunting' for posts? I'm just a bit curious.
Reply
#5

That's a really Nice Tutorial Vince - Good Job
Reply
#6

Quote:
Originally Posted by DrakeX
View Post
For what reason, within every comment or response you make comes nothing generally productive? Are you just 'hunting' for posts? I'm just a bit curious.
In fact, I am, read the so called "tutorial", and you'll know what I mean.

And who the hell even bumps his own tutorial for comments ?, usually people who don't get comments means that people don't find the following thread considered as a tutorial.
Reply
#7

I never bumped for "comments" at all, I bumped for criticism.
Reply
#8

What the duck is this?
pawn Code:
...
            switch(listitem
            {
                case 0:
                {
                    //Selected Item: "Music No 1"
                    StopAudioStreamForPlayer(playerid);
                    return 1;
                }
                case 1:
                {
                    //Selected Item: "No 2"
                    StopAudioStreamForPlayer(playerid);
                    return 1;
                }
                case 2:
                {
                    //Selected Item: " No 3"
                    StopAudioStreamForPlayer(playerid);
                    return 1;
                }
                case 3:
                {
                    //Selected Item: " No 4"
                    StopAudioStreamForPlayer(playerid);
                    return 1;
                }
                case 4:
                {
                    //Selected Item: " No5"
                    StopAudioStreamForPlayer(playerid);
                    return 1;
                }
            }
Remove it!
Reply
#9

Quote:
Originally Posted by =WoR=G4M3Ov3r
View Post
In fact, I am, read the so called "tutorial", and you'll know what I mean.

And who the hell even bumps his own tutorial for comments ?, usually people who don't get comments means that people don't find the following thread considered as a tutorial.
If you came to realization that this tutorial is poor, why have you failed to mention the flaws so he can improve them? Instead, you attempt to 'hunt for posts' and 'troll' him, seriously.
Reply


Forum Jump:


Users browsing this thread: 3 Guest(s)