[Tutorial] How to: Create a radio system as dialogs
#1

Hello there, I will be showing how to create radio system using PlayAudioStreamForPlayer function in dialogs.

Alright so, lets start.

At the top of your script, add

pawn Код:
#include <a_samp>
Also, you need to define a color, uhmm.. Let's choose this color to be blue, add this after the include:
pawn Код:
#define COLOR_BLUE 0xFFFFFF
Now, you need to define the dialogs numbers. add this after the define above, add this:
pawn Код:
#define DIALOG1 9312 // You can choose any number
#define DIALOG2 9313
Now, we have to create the command. Under OnPlayerCommandText add:
pawn Код:
if (strcmp("/playradio", cmdtext, true, 10) == 0)
    {
    if(!IsPlayerInAnyVehicle(playerid)) // You can remove this if you want, this means the radio won't start If you're not inside a vehicle.
    {
    SendClientMessage(playerid, COLOR_BLUE, "In-case you want to turn the radio on, you have to be in a vehicle!");
    return 1;
    }

        ShowPlayerDialog(playerid, 9312, DIALOG_STYLE_LIST, "Radio Station", "Radio Channels\nTurn the music off", "Select", "Cancel"); // Now, we're using the first dialog, you can add any options you want, for example, I've added 'Radio Channels, and turn the music off.
        return 1;
    }
    return 0;
}
Now, under public OnPlayerDialogResponse add this:
pawn Код:
if(dialogid == 9313) // Here, we're gonna use the second dialog, which contains the radio channels
    {
      if(response)
      {
       if(listitem == 0)
       {
       new Float:X, Float:Y, Float:Z ;//Float:Distance = 10.0; // This means the distance that the player would be able to hear music
       GetPlayerPos(playerid, X, Y, Z);
       PlayAudioStreamForPlayer(playerid, "http://205.188.215.230:8002/listen.pls"); // Here, you can add any stream URL you'd like,
       SendClientMessage(playerid, COLOR_BLUE, "Music started!");
       return 1;
       }
       if(listitem == 1)
       {
       new Float:X, Float:Y, Float:Z;// Float:Distance = 10.0;
       GetPlayerPos(playerid, X, Y, Z);
       PlayAudioStreamForPlayer(playerid, "http://205.188.215.229:8004/listen.pls");
       SendClientMessage(playerid, COLOR_BLUE, "Music started!");
       return 1;
       }
       if(listitem == 2)
       {
       new Float:X, Float:Y, Float:Z ;//Float:Distance = 10.0;
       GetPlayerPos(playerid, X, Y, Z);
       PlayAudioStreamForPlayer(playerid, "http://205.188.215.228:8002/listen.pls");
       SendClientMessage(playerid, COLOR_BLUE, "Music started!");
       return 1;
       }
       if(listitem == 3)
       {
       new Float:X, Float:Y, Float:Z;// Float:Distance = 10.0;
       GetPlayerPos(playerid, X, Y, Z);
       PlayAudioStreamForPlayer(playerid, "http://205.188.215.229:8006/listen.pls");
       SendClientMessage(playerid, COLOR_BLUE, "Music started!");
       return 1;
       }
       if(listitem == 4)
       {
       new Float:X, Float:Y, Float:Z ;//Float:Distance = 10.0;
       GetPlayerPos(playerid, X, Y, Z);
       PlayAudioStreamForPlayer(playerid, "http://205.188.215.229:8042/listen.pls");
       SendClientMessage(playerid, COLOR_BLUE, "Music started!");
       return 1;
       }
       if(listitem == 5)
       {
       new Float:X, Float:Y, Float:Z;//Float:Distance = 10.0;
       GetPlayerPos(playerid, X, Y, Z);
       PlayAudioStreamForPlayer(playerid, "http://205.188.215.225:8022/listen.pls");
       SendClientMessage(playerid, COLOR_BLUE, "Music started!");
       return 1;
       }
       if(listitem == 6)
       {
       new Float:X, Float:Y, Float:Z ;//Float:Distance = 10.0;
       GetPlayerPos(playerid, X, Y, Z);
       PlayAudioStreamForPlayer(playerid, "http://205.188.215.229:8040/listen.pls");
       SendClientMessage(playerid, COLOR_BLUE, "Music started!");
       return 1;
       }
       if(listitem == 7)
       {
       new Float:X, Float:Y, Float:Z ;//Float:Distance = 10.0;
       GetPlayerPos(playerid, X, Y, Z);
       PlayAudioStreamForPlayer(playerid, "http://yp.shoutcast.com/sbin/tunein-station.pls?id=357703");
       SendClientMessage(playerid, COLOR_BLUE, "Music started!");
       return 1;
       }
       if(listitem == 8)
       {
       new Float:X, Float:Y, Float:Z ;//Float:Distance = 10.0;
       GetPlayerPos(playerid, X, Y, Z);
       PlayAudioStreamForPlayer(playerid, "http://yp.shoutcast.com/sbin/tunein-station.pls?id=1026951");
       SendClientMessage(playerid, COLOR_BLUE, "Music started!");
       return 1;
       }
       if(listitem == 9)
       {
       new Float:X, Float:Y, Float:Z ;//Float:Distance = 10.0;
       GetPlayerPos(playerid, X, Y, Z);
       PlayAudioStreamForPlayer(playerid, "http://yp.shoutcast.com/sbin/tunein-station.pls?id=2057543");
       SendClientMessage(playerid, COLOR_BLUE, "Music started!");
       return 1;
       }
       if(listitem == 10)
       {
       new Float:X, Float:Y, Float:Z ;//Float:Distance = 10.0;
       GetPlayerPos(playerid, X, Y, Z);
       PlayAudioStreamForPlayer(playerid, "http://yp.shoutcast.com/sbin/tunein-station.pls?id=1543115");
       SendClientMessage(playerid, COLOR_BLUE, "Music started!");
       return 1;
       }
       if(listitem == 11)
       {
       new Float:X, Float:Y, Float:Z ;//Float:Distance = 10.0;
       GetPlayerPos(playerid, X, Y, Z);
       PlayAudioStreamForPlayer(playerid, "http://yp.shoutcast.com/sbin/tunein-station.pls?id=616366");
       SendClientMessage(playerid, COLOR_BLUE, "Music started!");
       return 1;
       }
       if(listitem == 12)
       {
       new Float:X, Float:Y, Float:Z ;//Float:Distance = 10.0;
       GetPlayerPos(playerid, X, Y, Z);
       PlayAudioStreamForPlayer(playerid, "http://yp.shoutcast.com/sbin/tunein-station.pls?id=1283516");
       SendClientMessage(playerid, COLOR_BLUE, "Music started!");
       return 1;
       }
       if(listitem == 13)
       {
       new Float:X, Float:Y, Float:Z ;//Float:Distance = 10.0;
       GetPlayerPos(playerid, X, Y, Z);
       PlayAudioStreamForPlayer(playerid, "http://yp.shoutcast.com/sbin/tunein-station.pls?id=737152");
       SendClientMessage(playerid, COLOR_BLUE, "Music started!");
       return 1;
       }
       if(listitem == 14)
       {
       new Float:X, Float:Y, Float:Z ;//Float:Distance = 10.0;
       GetPlayerPos(playerid, X, Y, Z);
       PlayAudioStreamForPlayer(playerid, "http://yp.shoutcast.com/sbin/tunein-station.pls?id=259629");
       SendClientMessage(playerid, COLOR_BLUE, "Music started!");
       return 1;
       }
       if(listitem == 15)
       {
       new Float:X, Float:Y, Float:Z;//, Float:Distance = 10.0;
       GetPlayerPos(playerid, X, Y, Z);
       PlayAudioStreamForPlayer(playerid, "http://yp.shoutcast.com/sbin/tunein-station.pls?id=1193516");
       SendClientMessage(playerid, COLOR_BLUE, "Music started!");
       return 1;
       }
       if(listitem == 16)
       {
       new Float:X, Float:Y, Float:Z;//, Float:Distance = 10.0;
       GetPlayerPos(playerid, X, Y, Z);
       PlayAudioStreamForPlayer(playerid, "http://yp.shoutcast.com/sbin/tunein-station.pls?id=1878");
       SendClientMessage(playerid, COLOR_BLUE, "Music started!");
       }
       return 1;

       }
    }
    if(dialogid == 9312)
    {
      if(response)
      {
       if(listitem == 0)
       {
       ShowPlayerDialog(playerid, 9313, DIALOG_STYLE_LIST, "Choose the channel you would like to listen!", "977 The Hitz Channel\n977 The 80s Channel\n181.FM - POWER 181\n1POWER\n108.FM - THE HITLIST\nChroniX Metal\nHOT 108 JAMZ\nSpart FM Tupac Channel\nAlex Jones FM\nFrench Kiss FM\nBlackBeat FM\nDEFJAY\nPower Hitz\nSky FM\nOld School 99\nTrance Channel\nIbiza Sonica", "Select", "Cancel"); // Here, you can add any channel you want, incase you have the streaming URL for it
       }
       if(listitem == 1)
       {
       StopAudioStreamForPlayer(playerid); // Now, this will turn the radio stream off, this means you won't be able to hear the streaming.
       SendClientMessage(playerid, COLOR_BLUE, "Music off.");
       }
       return 1;
            }
        }
    return 1;
}
Reply
#2

SERVER: Unknown command...
Reply
#3

Quote:
Originally Posted by kaiks
Посмотреть сообщение
SERVER: Unknown command...
Well, probably you have added/deleted something wrong, also. Add this script as a filter-script, do not add it in your gamemode.
Reply
#4

great job
Reply
#5

how do you make it so when you leave a vehicle the music will stop playing.. every time i leave a vehicle the music will still be playing
Reply
#6

This tutorial looks like you just copy-pasted it from a game-mode.

Can you at-least explain WHY are these dialogs, floats, etc. used? I won't call this a tutorial unless you explain the in-depths of why are those used. (No offence)
Reply
#7

Yet another tutorial with no explanation on what is going on.

Edit: Who have I annoyed?
Reply
#8

Or you could use an array to make it easy to add/edit radio stations.
Reply
#9

Better use 'switch'.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)