Quick question about a command.
#1

Hi guys,

After fixing my radio script yesterday, I noticed something about a command I've scripted.
The command is /stopradio:

pawn Код:
if (strcmp("/stopradio", cmdtext, true, 10) == 0)
{
    StopAudioStreamForPlayer(playerid);
    SendClientMessage(playerid, COLOR_RED, "You have turned off the radio.");
    return 1;
}
I want to add another client message saying "The radio is already off". Can anyone help me out here ?
I want it to detect if the radio is on or off.
Reply
#2

Try something like this

NOTE: Havent tested + im using phone at school
if it doesnt work atleast you can understand the idea

Код:
if (strcmp("/stopradio", cmdtext, true, 10) == 0)
{
     if(Radio[playerid] = 1)
     {
           StopAudioStreamForPlayer(playerid) && SendClientMessage(playerid, COLOR_RED, "You have turned off  the radio.");
           return 1;
     }
Reply
#3

Use a bool and set it to TRUE upon starting the radio and to FALSE once you stop the radio. Then simply check if the radio is turned on or off in an if clause before you stop the radio.
Reply
#4

Can you give me the code for that Campbell ?
Reply
#5

pawn Код:
new bool:radio_on;

if (strcmp("/stopradio", cmdtext, true, 10) == 0)
{
    if(radio_on == TRUE)
    {
       StopAudioStreamForPlayer(playerid);
       SendClientMessage(playerid, COLOR_RED, "You have turned off the radio.");
       radio_on = FALSE;
    }
    else
    {
       /* ... */
    }
    return 1;
}
Reply
#6

I want the /stopradio command to detect if the radio is off.
If the radio is off, I want It to send a client message saying "The radio is already turned off."
Reply
#7

Quote:
Originally Posted by sniperwars
Посмотреть сообщение
I want the /stopradio command to detect if the radio is off.
If the radio is off, I want It to send a client message saying "The radio is already turned off."
Well, that's exactly what I've written down, it should be like that:

pawn Код:
new bool:radio_on; /* You have to use this bool in an enum or anywhere else so you can also use it in /startradio. */

if (strcmp("/stopradio", cmdtext, true, 10) == 0)
{
    if(radio_on == TRUE)
    {
       StopAudioStreamForPlayer(playerid);
       SendClientMessage(playerid, COLOR_RED, "You have turned off the radio.");
       radio_on = FALSE;
       return 1;
    }
    else return SendClientMessage(playerid, COLOR_RED, "The radio is already turned off.");
}
Reply
#8

Quote:
Originally Posted by sniperwars
Посмотреть сообщение
I want the /stopradio command to detect if the radio is off.
If the radio is off, I want It to send a client message saying "The radio is already turned off."
Well mate as the users above said..

You can use new variable like:-

pawn Код:
new IsRadioOn[MAX_PLAYERS];
Now in the command or any place where YOU ARE PLAYING an AUDIO stream, put:

pawn Код:
IsRadioOn[playerid] = 1; // on music command maybe
And on the /radiooff command

pawn Код:
if (strcmp("stopradio", cmdtext, true, 10) == 0)
{
    if(IsRadioOn[playerid] == 1)
    {
       StopAudioStreamForPlayer(playerid);
       SendClientMessage(playerid, COLOR_RED, "You have turned off the radio.");
       IsRadioOn[playerid] = 0;
    }
    else
    {
       SendClientMessage(playerid, -1, "The radio is NOT on");
     }
       return 1;
}
This way you can detect if the radio is on.

Hope this helps

-FalconX
Reply
#9

/stopradio is an unknown command.
Reply
#10

Quote:
Originally Posted by sniperwars
Посмотреть сообщение
/stopradio is an unknown command.
Ah, I am sorry I guess I miss-typed.

pawn Код:
if (strcmp("/stopradio", cmdtext, true, 10) == 0)
{
    if(IsRadioOn[playerid] == 1)
    {
       StopAudioStreamForPlayer(playerid);
       SendClientMessage(playerid, COLOR_RED, "You have turned off the radio.");
       IsRadioOn[playerid] = 0;
    }
    else
    {
       SendClientMessage(playerid, -1, "The radio is NOT on");
     }
       return 1;
}
Use this
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)