SA-MP Forums Archive
Quick question about a command. - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Quick question about a command. (/showthread.php?tid=323651)



Quick question about a command. - sniperwars - 06.03.2012

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.


Re: Quick question about a command. - GNGification - 06.03.2012

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;
     }



Re: Quick question about a command. - Campbell- - 06.03.2012

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.


Re: Quick question about a command. - sniperwars - 06.03.2012

Can you give me the code for that Campbell ?


Re: Quick question about a command. - Campbell- - 06.03.2012

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;
}



Re: Quick question about a command. - sniperwars - 06.03.2012

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."


Re: Quick question about a command. - Campbell- - 06.03.2012

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.");
}



Re: Quick question about a command. - FalconX - 06.03.2012

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


Re: Quick question about a command. - sniperwars - 06.03.2012

/stopradio is an unknown command.


Re: Quick question about a command. - FalconX - 06.03.2012

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