05.01.2012, 22:30
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
then we want the dialog to show.
here is ShowPlayerDialog explained:
You want to add that line followed by return 1; then bracket the cmd of.
My strcmp cmd:
DCMD :
I don't need to explain anymore on simple cmds....
Third
We want the buttons to actually do something...
so search for
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
Explained :
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)
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"
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");
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;
}
Third
We want the buttons to actually do something...
so search for
pawn Code:
public OnDialogResponse
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;
}
- 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
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;
}