Variables Help!
#1

So I've been working on my script, but the problem is, the variables are applying for everybody. I want everybody to go by the same variable, but each individual has there own value. What it does right now, is if somebody does /radiooff, it'll turn the radio variable to 0 for everybody.

All I'm doing is putting the variable at the top of the script like this:

PHP код:
new radio 
Then, the script for it is:

PHP код:
    if (strcmp("/radiooff"cmdtexttrue10) == 0)
    {
        if(
radio == 1)
        {
            
StopAudioStreamForPlayer(playerid);
            
SendClientMessage(playeridwhite"To turn the radio back on, do /radioon");
              
radio--;
        }
        else if(
radio == 0)
        {
            
SendClientMessage(playeridwhite"Your radio is already off!");
        }
    } 
Then, the radio on is:
PHP код:
    if (strcmp("/radioon"cmdtexttrue10) == 0)
    {
        if(
radio == 0)
        {
            
PlayAudioStreamForPlayer(playerid"http://yp.shoutcast.com/sbin/tunein-station.pls?id=1283896");
            
SendClientMessage(playeridwhite"Your radio has been turned on. To turn it off, type /radiooff");
            
radio++;
        }
        else if(
radio == 1)
        {
            
SendClientMessage(playeridwhite"Your radio is already on, to turn it off, do /radiooff!");
        }
    } 
The radio-- and radio++ are taking affect for everybody's variables.
Help Please!
Reply
#2

try radio=0 & radio = 1, instead of -- & ++

edit :

Код:
    new radio[MAX_PLAYERS];
    if (strcmp("/radiooff", cmdtext, true, 10) == 0) 
    { 
        if(radio[playerid] == 1) 
        { 
            StopAudioStreamForPlayer(playerid); 

            SendClientMessage(playerid, white, "To turn the radio back on, do /radioon"); 
              radio[playerid]=0;
        } 
        else if(radio[playerid] == 0) 
        { 
            SendClientMessage(playerid, white, "Your radio is already off!"); 
        } 
    }  

   if (strcmp("/radioon", cmdtext, true, 10) == 0) 
    { 
        if(radio[playerid] == 0) 
        { 
            PlayAudioStreamForPlayer(playerid, "http://yp.shoutcast.com/sbin/tunein-station.pls?id=1283896"); 
            SendClientMessage(playerid, white, "Your radio has been turned on. To turn it off, type /radiooff"); 
            radio[playerid]=1; 
        } 
        else if(radio[playerid] == 1) 
        { 
            SendClientMessage(playerid, white, "Your radio is already on, to turn it off, do /radiooff!"); 
        } 
    }
Reply
#3

You need to do this. I'll rewrite the code for you.

pawn Код:
new radio[MAX_PLAYERS] = 0;

if (strcmp("/radiooff", cmdtext, true, 10) == 0)
    {
        if(radio[playerid] == 1)
        {
            StopAudioStreamForPlayer(playerid);

            SendClientMessage(playerid, white, "To turn the radio back on, do /radioon");
              radio[playerid] = 0;
        }
        else if(radio[playerid] == 0)
        {
            SendClientMessage(playerid, white, "Your radio is already off!");
        }
    }

if (strcmp("/radioon", cmdtext, true, 10) == 0)
    {
        if(radio[playerid] == 0)
        {
            PlayAudioStreamForPlayer(playerid, "http://yp.shoutcast.com/sbin/tunein-station.pls?id=1283896");
            SendClientMessage(playerid, white, "Your radio has been turned on. To turn it off, type /radiooff");
            radio[playerid] = 1;
        }
        else if(radio[playerid] == 1)
        {
            SendClientMessage(playerid, white, "Your radio is already on, to turn it off, do /radiooff!");
        }
    }
You were making a global variable. That was your issue. Try using my code and tell me if it works or not.
Reply
#4

With one cmd you can turn it on or off. Much simple
PHP код:
if (strcmp("/radio"cmdtexttrue7) == 0
{
    if(
radio[playerid] == 0)
    {
        
PlayAudioStreamForPlayer(playerid"http://yp.shoutcast.com/sbin/tunein-station.pls?id=1283896");
        
SendClientMessage(playeridwhite"You are listening to radio ....");
        
radio[playerid] = 1;
    }
    else
    {
        
StopAudioStreamForPlayer(playerid);
        
SendClientMessage(playeridwhite"Thank you for listeing the radio, tune again soon.");
        
radio[playerid] = 0;
    }
    return 
1;

Reply
#5

Quote:
Originally Posted by Steven82
Посмотреть сообщение
You need to do this. I'll rewrite the code for you.

pawn Код:
new radio[MAX_PLAYERS] = 0;

if (strcmp("/radiooff", cmdtext, true, 10) == 0)
    {
        if(radio[playerid] == 1)
        {
            StopAudioStreamForPlayer(playerid);

            SendClientMessage(playerid, white, "To turn the radio back on, do /radioon");
              radio[playerid] = 0;
        }
        else if(radio[playerid] == 0)
        {
            SendClientMessage(playerid, white, "Your radio is already off!");
        }
    }

if (strcmp("/radioon", cmdtext, true, 10) == 0)
    {
        if(radio[playerid] == 0)
        {
            PlayAudioStreamForPlayer(playerid, "http://yp.shoutcast.com/sbin/tunein-station.pls?id=1283896");
            SendClientMessage(playerid, white, "Your radio has been turned on. To turn it off, type /radiooff");
            radio[playerid] = 1;
        }
        else if(radio[playerid] == 1)
        {
            SendClientMessage(playerid, white, "Your radio is already on, to turn it off, do /radiooff!");
        }
    }
You were making a global variable. That was your issue. Try using my code and tell me if it works or not.
Thanks alot! It worked!
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)