[Tutorial] Making a music command.
#1

Hey everyone today ill show you how to make a music cmd,like when you enter the name of the song it plays.
For example if the name is thefox ill do /thefox and the song will play,so lets get started.

First include and define the following:
pawn Код:
#include <zcmd>
#define COLOR_GREEN 0x00FF00FF
Now lets make the command.
Put the name of the song as the cmd,my song is called burn so my cmd will be burn.
pawn Код:
CMD:burn(playerid, params[])
{
Now we are going to make it global so everyone in the server will hear it.
pawn Код:
for(new i=0; i<MAX_PLAYERS; i++)
{
Now we have to put the link for the song that we will be streaming,to do this go to a music download site and copy the download link of the song.
pawn Код:
PlayAudioStreamForPlayer(i,"http://dl.farskids405.com/Aria/92/4/15/Ellie%20Goulding%20-%20Burn%20[128].mp3");
Now we are going to make a message that will tell players the name of the song that is playing.
pawn Код:
SendClientMessageToAll(COLOR_GREEN,"Track playing-Ellie Goulding - Burn");
}
return 1;
}
Now we are finished,your cmd should look like this:
pawn Код:
CMD:burn(playerid, params[])
{
if(PlayerInfo[playerid][pAdmin] < 1) return 0;
for(new i=0; i<MAX_PLAYERS; i++)
{
PlayAudioStreamForPlayer(i,"http://dl.farskids405.com/Aria/92/4/15/Ellie%20Goulding%20-%20Burn%20[128].mp3");
SendClientMessageToAll(COLOR_GREEN,"Track playing-Ellie Goulding - Burn");
}
return 1;
}
If you need any help please comment and please rep this tut.
Thanks-Jeremy
Reply
#2

Explain more.
Reply
#3

You should explain more about the for loop and AdminLevel thing.
Reply
#4

Is this a tutorial? It's short. :/
Reply
#5

Ok. So from this tutorial, people will get 15 errors. Here they are:

Код:
C:\Users\cex\Desktop\Game Files\Grand County Roleplay\pawno\include\zcmd.inc(62) : warning 235: public function lacks forward declaration (symbol "OnGameModeInit")
C:\Users\cex\Desktop\Game Files\Grand County Roleplay\pawno\include\zcmd.inc(64) : error 017: undefined symbol "funcidx"
C:\Users\cex\Desktop\Game Files\Grand County Roleplay\pawno\include\zcmd.inc(65) : error 017: undefined symbol "funcidx"
C:\Users\cex\Desktop\Game Files\Grand County Roleplay\pawno\include\zcmd.inc(66) : error 017: undefined symbol "funcidx"
C:\Users\cex\Desktop\Game Files\Grand County Roleplay\pawno\include\zcmd.inc(68) : error 017: undefined symbol "CallLocalFunction"
C:\Users\cex\Desktop\Game Files\Grand County Roleplay\pawno\include\zcmd.inc(83) : warning 235: public function lacks forward declaration (symbol "OnPlayerCommandText")
C:\Users\cex\Desktop\Game Files\Grand County Roleplay\pawno\include\zcmd.inc(85) : error 017: undefined symbol "CallLocalFunction"
C:\Users\cex\Desktop\Game Files\Grand County Roleplay\pawno\include\zcmd.inc(94) : error 017: undefined symbol "tolower"
C:\Users\cex\Desktop\Game Files\Grand County Roleplay\pawno\include\zcmd.inc(96) : warning 217: loose indentation
C:\Users\cex\Desktop\Game Files\Grand County Roleplay\pawno\include\zcmd.inc(96) : error 017: undefined symbol "format"
C:\Users\cex\Desktop\Game Files\Grand County Roleplay\pawno\include\zcmd.inc(96) : warning 202: number of arguments does not match definition
C:\Users\cex\Desktop\Game Files\Grand County Roleplay\pawno\include\zcmd.inc(96) : warning 202: number of arguments does not match definition
C:\Users\cex\Desktop\Game Files\Grand County Roleplay\pawno\include\zcmd.inc(96) : warning 202: number of arguments does not match definition
C:\Users\cex\Desktop\Game Files\Grand County Roleplay\pawno\include\zcmd.inc(97) : warning 217: loose indentation
C:\Users\cex\Desktop\Game Files\Grand County Roleplay\pawno\include\zcmd.inc(98) : warning 217: loose indentation
C:\Users\cex\Desktop\Game Files\Grand County Roleplay\pawno\include\zcmd.inc(102) : error 017: undefined symbol "CallLocalFunction"
C:\Users\cex\Desktop\Game Files\Grand County Roleplay\pawno\include\zcmd.inc(104) : error 017: undefined symbol "CallLocalFunction"
C:\Users\cex\Desktop\Game Files\Grand County Roleplay\pawno\include\zcmd.inc(108) : error 017: undefined symbol "CallLocalFunction"
C:\Users\cex\Desktop\Game Files\Grand County Roleplay\pawno\include\zcmd.inc(110) : error 017: undefined symbol "CallLocalFunction"
C:\Users\cex\Desktop\burn.pwn(6) : error 017: undefined symbol "PlayerInfo"
C:\Users\cex\Desktop\burn.pwn(6) : warning 215: expression has no effect
C:\Users\cex\Desktop\burn.pwn(6) : error 001: expected token: ";", but found "]"
C:\Users\cex\Desktop\burn.pwn(6) : error 029: invalid expression, assumed zero
C:\Users\cex\Desktop\burn.pwn(6) : fatal error 107: too many error messages on one line

Compilation aborted.Pawn compiler 3.2.3664	 	 	Copyright © 1997-2006, ITB CompuPhase
What is this? You've not explained it what so ever. This is what should be done.

First of all, you will need to include the following:

pawn Код:
#include <a_samp>
#include <zcmd>
The reason for including these, is first of all: a_samp - This gives all of the functions needed to even compile the script to make it work, then along with the majority of all SA-MP functions.

zcmd - This is a command processor. This will be used to create the command and let it run smoothly without error.

After you have done that, you are going to need to create the command. This is how it is done:

pawn Код:
command(burn, playerid, params[]) //This is how the ZCMD processor is used, this is creating the command so it can be used and perform the required code.
{
    for(new i=0; i<MAX_PLAYERS; i++) //This will create a loop to see who is connected to the server.
    {
        if(IsPlayerConnected(i)) //This will check the loop to see if the player(s) are connected, and if so they will be selected and the music file will be played out to them.
        {
            PlayAudioStreamForPlayer(i,"http://dl.farskids405.com/Aria/92/4/15/Ellie%20Goulding%20-%20Burn%20[128].mp3"); //This function will grab the mp3 file from the URL, then play it back to the connected players.
            SendClientMessageToAll(-1, "Track playing-Ellie Goulding - Burn"); //This will send a message to all connected players, notifying them that "Ellie Goulding - Burn" is playing.
        }
    }
    return 1;
}
It's as simple as that. To see all comments, on the box above; scroll to the right hand side.




What is so hard about that? 5 minutes of work. (I know it's not explained all the best, but it still makes more sense to all others IMO.)
Reply
#6

Also there's bug.

You should use SendClientMessage instead SendClientMessageToAll, because it'll send many times to each player.
Reply
#7

Quote:
Originally Posted by Skimmer
Посмотреть сообщение
Also there's bug.

You should use SendClientMessage instead SendClientMessageToAll, because it'll send many times to each player.
The point of this is to show all players what song is palying nub.
Reply
#8

You're using SendClientMessageToAll, inside a loop. That scrolls over MAX_PLAYERS which is by default 500.
So.. It sends SendClientMessageToAll 500 times? Perfect!

For your next tutorial, before releasing it. Test it, and explain much more. A dynamic music command would be more better here. This stuff should probably go on the wiki for quick command show. Tho it should be in default order, not ZCMD.
Reply
#9

pawn Код:
CMD:burn(playerid, params[])
{
if(PlayerInfo[playerid][pAdmin] < 1) return 0;
for(new i=0; i<MAX_PLAYERS; i++)
{
PlayAudioStreamForPlayer(i,"http://dl.farskids405.com/Aria/92/4/15/Ellie%20Goulding%20-%20Burn%20[128]. mp3");
SendClientMessageToAll(COLOR_GREEN,"Track playing-Ellie Goulding - Burn");        
return 1;
}
return 1;
}
Would it show only 1 time if we put "return 1;" under sendclientmessage?
Reply
#10

Quote:
Originally Posted by TheFlyer
Посмотреть сообщение
pawn Код:
CMD:burn(playerid, params[])
{
if(PlayerInfo[playerid][pAdmin] < 1) return 0;
for(new i=0; i<MAX_PLAYERS; i++)
{
PlayAudioStreamForPlayer(i,"http://dl.farskids405.com/Aria/92/4/15/Ellie%20Goulding%20-%20Burn%20[128]. mp3");
SendClientMessageToAll(COLOR_GREEN,"Track playing-Ellie Goulding - Burn");        
return 1;
}
return 1;
}
Would it show only 1 time if we put "return 1;" under sendclientmessage?
Nope, because you're breaking the loop after playerid 0 has been processed.
All players will see the message, but only player 0 will hear it.

pawn Код:
command(burn, playerid, params[]) //This is how the ZCMD processor is used, this is creating the command so it can be used and perform the required code.
{
    for(new i=0; i<MAX_PLAYERS; i++) //This will create a loop to see who is connected to the server.
    {
        if(IsPlayerConnected(i)) //This will check the loop to see if the player(s) are connected, and if so they will be selected and the music file will be played out to them.
        {
            PlayAudioStreamForPlayer(i,"http://dl.farskids405.com/Aria/92/4/15/Ellie%20Goulding%20-%20Burn%20[128].mp3"); //This function will grab the mp3 file from the URL, then play it back to the connected players.
        }
    }
    SendClientMessageToAll(-1, "Track playing-Ellie Goulding - Burn"); //This will send a message to all connected players, notifying them that "Ellie Goulding - Burn" is playing.

    return 1;
}

Just put the message outside the loop.
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)