[Tutorial] How to make a radio system with dialogs (beginner!)
#1

Hey and i'm gunna be telling you guys how to make a pretty basic radio system using dialogs...

First of all we're going to need to put our includes in:

pawn Код:
#include <a_samp> // this is needed for every script
#include <zcmd> // this is not necessarily needed but we're going to use it for our commands!
ZCMD is a quicker command processor, a lot faster than the standard one strcmp....

Then we have to define the colours we are going to use... these are the colours i used!
pawn Код:
#define C_RED 0xAA3333AA
#define COLOR_YELLOW 0xFFFF00AA
#define C_GREEN 0x33AA33AA
this just defines the colours to that colour code! For example if you put #define C_RED (code of yellow) C_RED would actually be yellow!

We also have to define the dialogs name!
pawn Код:
#define DIALOG_RADIO 1
What this does, is make it so we can use ShowPlayerDialog(playerid, DIALOG_RADIO... rather than use (1), this is normally used if you have multiple dialogs as it is much easier to keep track!

now we need to make our variable... this will be used later the check if the player is/isn't listening to the radio!
pawn Код:
new islistening[MAX_PLAYERS];
noooow we move on to the actual scripting part! We are going to make sure that the variable is set to 0 so the server knows we aren't listening to the radio!
pawn Код:
public OnPlayerConnect(playerid)
{
    islistening[playerid] = 0;
    return 1;
}
This callback is called when the player connects to the server which will then set the variable to 0 (not listening to radio)

Now the most important part, the commands!
First off we're gonna make the /radio command and then the /stopradio command!
pawn Код:
CMD:radio(playerid,cmdtext[])
{
    if(!IsPlayerInAnyVehicle(playerid)) return SendClientMessage(playerid, C_RED, "You aren't in a Vehicle!");
    ShowPlayerDialog(playerid, DIALOG_RADIO, DIALOG_STYLE_LIST, "Radio Stations","1. Radio 1\r\n2. Radio 2\r\n3. Radio 3\r\n4. Radio 4","Listen","Cancel");
    return 1;
}
So this willl not go under any call back what so ever. this is seperate from any other callback!

Line 1: This is checking if the player is in a vehicle or not! and if the player is NOT in the vehicle it will send the message with the colour of red "You aren't in a vehicle!"
Line 2: this will show the player a dialog with the ID of DIALOG_RADIO and the style of the dialog is a list! Then we have "radio stations" as the title of this dialog. Then the listed items are Radio 1, Radio 2, Radio 3 and Radio 4... \r\n2 etc will make a new line and put 2 etc in front of the Radio 2 or whatever! then you can either click listen which will obviously turn the radio on... or click cancel which will close the dialog.

pawn Код:
CMD:stopradio(playerid,cmdtext[])
{
    if(!IsPlayerInAnyVehicle(playerid)) return SendClientMessage(playerid, C_RED, "You aren't in a vehicle!"); //this checks if the player is in a vehicle like I explained before!
    if(islistening[playerid] == 1) //this is checking if the variable is set to 1 (will be when we click a radio, explained later
    {
        StopAudioStreamForPlayer(playerid); //self explanatory, this will stop the radio...
        SendClientMessage(playerid, C_RED, "You turned your radio off!"); //send the player a message...
    }
    else //if the variable is 0
    {
        SendClientMessage(playerid, C_RED, "You aren't listening to your radio!"); //this will send the player a message informing his he isnt listening to the radio..
    }
    return 1;
} //closes the command
Well, at the moment if the player exits a vehicle, he will still be listening to the radio....
pawn Код:
public OnPlayerExitVehicle(playerid,vehicleid) //this is called when the player exits there vehicle
{
    StopAudioStreamForPlayer(playerid); //stops the streamed radio...
    return 1;
}
Now we have to create the actual function!

pawn Код:
public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
    switch(dialogid)
    {
        case DIALOG_RADIO:
        {
            if(!response) //the '!' mark means you clicked cancel, and will close the dailog...
            {
                SendClientMessage(playerid, C_RED, "You cancelled!"); //sent message to the player
            }
            if(response) //if you click listen... it will play what you have clicked
            {
                switch(listitem)
                {
                    case 0: //first item in the list
                    {
                        islistening[playerid] = 1; //making the variable 1, is listening to radio...
                        PlayAudioStreamForPlayer(playerid,"http://yp.shoutcast.com/sbin/tunein-station.pls?id=1281016&play_status=1"); //this will play the radio station from that url/stream.
                    }
                    case 1: //same as case 0: etc...
                    {
                        islistening[playerid] = 1;
                        PlayAudioStreamForPlayer(playerid,"http://yp.shoutcast.com/sbin/tunein-station.pls?id=1283516&play_status=1");
                    }
                    case 2:
                    {
                        islistening[playerid] = 1;
                        PlayAudioStreamForPlayer(playerid,"http://yp.shoutcast.com/sbin/tunein-station.pls?id=1283516&play_status=1");
                    }
                    case 3:
                    {
                        islistening[playerid] = 1;
                        PlayAudioStreamForPlayer(playerid,"http://yp.shoutcast.com/sbin/tunein-station.pls?id=663859&play_status=1");
                    }
                }
            }
        }
    }
    return 1;
}
I hope this helped you, not the best tutorial... sorry but i did my best...

Credits
Tutorial: Bigal
ZCMD Include: https://sampforum.blast.hk/showthread.php?tid=91354 (ZEEX)
Reply


Messages In This Thread

Forum Jump:


Users browsing this thread: 2 Guest(s)