[Tutorial] Making a basic audio system!
#1

Making a basic audio system!

Hi my name is xXitsgodzillaXx and I am going to show you how to make a basic audio system where you can find individual songs and get different radios.

Okay so we need to make sure with all of our includes and such so first we want to get zcmd so our commands will execute each function faster. Link for Zcmd: https://sampforum.blast.hk/showthread.php?tid=91354 And then you will need "a_http" which comes default when you download the server package if you still dont have it just redownload the package here: http://files.sa-mp.com/samp03x_svr_R1-2_win32.zip

Okay so lets start we must make sure that the include are being used in the script so we are going to put "#include <zcmd>" and "#include <a_http>"

So our script should look like this at the top so far.
pawn Code:
#define FILTERSCRIPT

#include <a_samp>
#include <zcmd>
#include <a_http>

#if defined FILTERSCRIPT

public OnFilterScriptInit()
{
    print("\n--------------------------------------");
    print(" Blank Filterscript by your name here");
    print("--------------------------------------\n");
    return 1;
}

public OnFilterScriptExit()
{
    return 1;
}

#else

main()
{
    print("\n----------------------------------");
    print(" Blank Gamemode by your name here");
    print("----------------------------------\n");
}

#endif
Okay so once that is done we need to define the dialogs so let's do that. We will put "#define Music_dialog (insert any number in between 1 and 32767)

pawn Code:
#define FILTERSCRIPT

#include <a_samp>
#include <zcmd>
#include <a_http>

#if defined FILTERSCRIPT

#define Music_dialog 8487

public OnFilterScriptInit()
{
    print("\n--------------------------------------");
    print(" Blank Filterscript by your name here");
    print("--------------------------------------\n");
    return 1;
}

public OnFilterScriptExit()
{
    return 1;
}

#else

main()
{
    print("\n----------------------------------");
    print(" Blank Gamemode by your name here");
    print("----------------------------------\n");
}

#endif
Okay so lets make our first command lets call it uhh... "/music"? yes?
So lets do this any where on the script. but make sure it's not under ANY callbacks or you will get errors.

Okay so lets type our command which will be this "CMD:music(playerid, params[]);" This here will execute all the functions when we type "/music" in game. Now lets add some functions like "ShowPlayerDialog". Now the command should look like this.

pawn Code:
CMD:musiclist(playerid, params[])
{
    ShowPlayerDialog(playerid, Music_dialog, DIALOG_STYLE_LIST, "Music", "Creed - Higher\nStopMusic", "Play", "Close");
    return 1;
}
now hit "CTRL + F" and type "OnDialogResponse" and click "find next". should find it if not just type anywhere on the script
pawn Code:
public OnDialogResponse
{
    if(dialogid == Music_dialog)
    {
        if(response)
        {
            if(listitem == 0)
            {
                PlayAudioStreamForPlayer(playerid, "");
            }
}
So lets start using the PlayAudioStreamForPlayer function. Looks like this
pawn Code:
PlayAudioStreamForPlayer(playerid,(URL Goes here));
Now lets pick a song doesnt matter which one. Now in order to get a song we need to go to this website: www.dilandau.eu Type in a song in the search bar then listen to it just to make sure that its the right one that you want.
When you have found your song just right click the download button and click "copy link location" So im just going to pick any song.. lets go with "Higher" by creed. Now that we have our song lets paste the link in the "URL" params" Now the dialog Should look somthing like this.

pawn Code:
public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
    if(dialogid == Music_dialog)
    {
        if(response)
        {
            if(listitem == 0)
            {
                PlayAudioStreamForPlayer(playerid, "http://jweb.taconic.net/music/creed-my_own_prison.mp3");
            }
            if(listitem == 1)
            {
                StopAudioStreamForPlayer(playerid);
            }
        }
        return 1;
    }
    return 0;
}
"StopAudioStreamForPlayer" Is pretty self explanatory. and for the returns ALWAYS REMEMBER TO DO
"
return 1;
}
return 0;
}"
at the bottom of OnDialogResponse.

So now our filterscript Should look like this once you remove all of the other callbacks and stuff we dont need.

pawn Code:
#define FILTERSCRIPT

#include <a_samp>
#include <zcmd>
#include <a_http>

#if defined FILTERSCRIPT

#define Music_dialog 8487

#else
#endif

CMD:music(playerid, params[])
{
    ShowPlayerDialog(playerid, Music_dialog, DIALOG_STYLE_LIST, "Music","Creed - Higher\nStop Music","Play","Close");
    return 1;
}

public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
    if(dialogid == Music_dialog)
    {
        if(response)
        {
            if(listitem == 0)
            {
                PlayAudioStreamForPlayer(playerid, "http://jweb.taconic.net/music/creed-my_own_prison.mp3");
            }
            if(listitem == 1)
            {
                StopAudioStreamForPlayer(playerid);
            }
        }
        return 1;
    }
    return 0;
}
This is my first Tutorial so any feed back is appreciated. Please tell me how I did!
Reply
#2

Not much of a tutorial. All you are doing is showing code and telling them where to put it, along with a link to find music.

None the less, people trying to help the community is always welcome in my book.

PS: If your response is "It was meant for intermediate users" or something, please don't. If you are going to show a basic audio system, intermediate scripters should already know this.
Reply
#3

Okay
Reply
#4

Like kindred posted above, you shouldn't just show code, try annotating parts of the code using comments and explain some of the lines in the overall post instead of a copy/paste tutorial.

Anyway nice for a first tutorial
Reply
#5

i don't even think http.inc is needed. because PlayerAudioStreamForPlayer already does the link thing + its included in a_samp.inc
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)