Command doesn't work.
#1

PHP код:
CMD:toggle(playeridparams[])
{
    if(
isnull(params))
    {
        
SendClientMessage(playerid, -1"Use /toggle [Function].");
        
SendClientMessage(playerid, -1"Options: PM, TesterChat, AdminChat, Radio");
        return 
1;
    }
    new 
settings[24], info[24], string[128];
    
sscanf(params"s[24]s[24]"settingsinfo);
    if(!
strcmp(settings"PM"true))
    {
    if(
pInfo[playerid][pPM] == 1)
    {
    
pInfo[playerid][pPM] = 0;
     
SendClientMessage(playerid,-1,""COL_LGREEN" Now you get PMs.");
    }
     if(
pInfo[playerid][pPM] == 1)
    {
    
pInfo[playerid][pPM] = 1;
     
SendClientMessage(playerid,-1,""COL_LGREEN" Now you don't get PMs.");
    }
    return 
1;
    }
    
    if(!
strcmp(settings"TesterChat"true))
    {
    if(
pInfo[playerid][tChat] == 1)
    {
    
pInfo[playerid][tChat] = 0;
     
SendClientMessage(playerid,-1,""COL_LGREEN" Activatedl.");
    }
     if(
pInfo[playerid][tChat] == 1)
    {
    
pInfo[playerid][tChat] = 1;
     
SendClientMessage(playerid,-1,""COL_LGREEN" not");
    }
    return 
1;
    }
    if(!
strcmp(settings"AdminChat"true))
    {
    if(
pInfo[playerid][aChat] == 1)
    {
    
pInfo[playerid][aChat] = 0;
     
SendClientMessage(playerid,-1,""COL_LGREEN" Yes.");
    }
     if(
pInfo[playerid][aChat] == 1)
    {
    
pInfo[playerid][aChat] = 1;
     
SendClientMessage(playerid,-1,""COL_LGREEN" Not");
    }
    return 
1;
    }
    
    if(!
strcmp(settings"Radio"true))
    {
    if(
pInfo[playerid][rChat] == 1)
    {
    
pInfo[playerid][rChat] = 0;
     
format(stringsizeof(string), "* %s yes. "PlayerName(playerid));
      
ProxDetector(30playeridstringCOLOR_PURPLE);
      }
     if(
pInfo[playerid][rChat] == 1)
    {
    
pInfo[playerid][rChat] = 1;
     
format(stringsizeof(string), "* %s not. "PlayerName(playerid));
      
ProxDetector(30playeridstringCOLOR_PURPLE);
    return 
1;
    }
}
    return 
1;

If I type in game /toggle it shows the options

If I type /toggle PM nothing happens.
Reply
#2

pawn Код:
// pPM must be changed to bool:pPM = true and so on...

CMD:toggle(playerid, params[]) {

  static settings[24], info[24];
  if(!sscanf(params, "s[24]s[24]", settings, info) {

    if(!strcmp(settings, "pm", true) {

      pInfo[playerid][pPM] = !pInfo[playerid][pPM]; // This makes the value switch. (true becomes false, false becomes true)
      if(pInfo[playerid][pPM]) return SendClientMessage(playerid, -1, "Now you're getting PMs!");
      else return SendClientMessage(playerid, -1, "Now you're not getting PMs.");
    }
   
    else if(!strcmp(settings, "testerchat", true)) {

      pInfo[playerid][tChat] = !pInfo[playerid][tChat];
      if(pInfo[playerid][pPM]) return SendClientMessage(playerid, -1, "Now you'll read the Tester Chat!");
      else return SendClientMessage(playerid, -1, "Now you're not reading the Tester Chat.");
    }
   
    else return SendClientMessage(playerid, -1, "The option typed in wasn't found.");
  }
 
  else return SendClientMessage(playerid, -1, "Use /toggle [Function]."),
    SendClientMessage(playerid, -1, "Options: PM, TesterChat, AdminChat, Radio");
}
Reply
#3

Start off with fixing your indentation. Along with that, use sscanf instead of isnull.
You should consider looking at your code.
Код:
    if(pInfo[playerid][pPM] == 1) 
    { 
    pInfo[playerid][pPM] = 0; 
     SendClientMessage(playerid,-1,""COL_LGREEN" Now you get PMs."); 
    } 
     if(pInfo[playerid][pPM] == 1) 
    { 
    pInfo[playerid][pPM] = 1; 
     SendClientMessage(playerid,-1,""COL_LGREEN" Now you don't get PMs."); 
    }
In pseudocode this is:
Quote:

> if player has pm set to 1
> set pm to 0
> send them a message saying they get pm

> if player has pm set to 1
> set pm to 1
> send them a message saying they wont get dm's

basically, you're running the same check twice with just the second and third step varying. here's how you could fix it, in pseudocode. you'll have to convert this over to pawn afterwards.

Quote:

> if player has pm set to 1
> set pm to 0
> send them a message saying they get pm

> else if player has pm set to 0
> set pm to 1
> send them a message saying they wont get dm's.

you could also run a switch rather than if and else if. Have fun.
Reply
#4

Quote:
Originally Posted by Ermanhaut
Посмотреть сообщение
pawn Код:
// pPM must be changed to bool:pPM = true and so on...

CMD:toggle(playerid, params[]) {

  static settings[24], info[24];
  if(!sscanf(params, "s[24]s[24]", settings, info) {

    if(!strcmp(settings, "pm", true) {

      pInfo[playerid][pPM] = !pInfo[playerid][pPM]; // This makes the value switch. (true becomes false, false becomes true)
      if(pInfo[playerid][pPM]) return SendClientMessage(playerid, -1, "Now you're getting PMs!");
      else return SendClientMessage(playerid, -1, "Now you're not getting PMs.");
    }
   
    else if(!strcmp(settings, "testerchat", true)) {

      pInfo[playerid][tChat] = !pInfo[playerid][tChat];
      if(pInfo[playerid][pPM]) return SendClientMessage(playerid, -1, "Now you'll read the Tester Chat!");
      else return SendClientMessage(playerid, -1, "Now you're reading the Tester Chat.");
    }
   
    else return SendClientMessage(playerid, -1, "The option typed in wasn't found.");
  }
 
  else return SendClientMessage(playerid, -1, "Use /toggle [Function]."),
    SendClientMessage(playerid, -1, "Options: PM, TesterChat, AdminChat, Radio");
}
You shouldn't spoonfeed code. The guy is no longer going to learn anything from you doing that. Also, the statement you made about the bools aren't necessarily true considering that 0 = false and 1 = true. It will, however, prevent mentions of compiler warnings if you are using the community pawn-lang compiler, first maintained by zeex.
Reply
#5

Quote:
Originally Posted by Infin1ty
Посмотреть сообщение
You shouldn't spoonfeed code. The guy is no longer going to learn anything from you doing that. Also, the statement you made about the bools aren't necessarily true considering that 0 = false and 1 = true. It will, however, prevent mentions of compiler warnings if you are using the community pawn-lang compiler, first maintained by zeex.
I was bored, saw his code and wanted to help, no big deal.
Besides, just tell someone his mistakes whitout showing him some work, he will give up or wait until someone do what i did.

Anyway, i'm wrong.
Reply
#6

Quote:
Originally Posted by Infin1ty
Посмотреть сообщение
Start off with fixing your indentation. Along with that, use sscanf instead of isnull.
You should consider looking at your code.
Код:
    if(pInfo[playerid][pPM] == 1) 
    { 
    pInfo[playerid][pPM] = 0; 
     SendClientMessage(playerid,-1,""COL_LGREEN" Now you get PMs."); 
    } 
     if(pInfo[playerid][pPM] == 1) 
    { 
    pInfo[playerid][pPM] = 1; 
     SendClientMessage(playerid,-1,""COL_LGREEN" Now you don't get PMs."); 
    }
In pseudocode this is:


basically, you're running the same check twice with just the second and third step varying. here's how you could fix it, in pseudocode. you'll have to convert this over to pawn afterwards.



you could also run a switch rather than if and else if. Have fun.
I don't have indention errors, IDK why pasted it with errors.

Beside that, I have tried to fix it with "else if" but it didn't work.
Reply
#7

PHP код:
CMD:toggle(playeridparams[]) 
{
    new 
settings[24];
    if(
sscanf(params"s[24]"settings)) return SendClientMessage(playerid, -1"Use /toggle (PM, TesterChat, AdminChat, Radio)");
    if(!
strcmp(settings"pm"true))
    { 
        if(
pInfo[playerid][pPM] == 1
        {
            
pInfo[playerid][pPM] = 0
            
SendClientMessage(playerid, -1""COL_LGREEN" Now you get PMs."); 
        } 
        else
        { 
            
pInfo[playerid][pPM] = 1
            
SendClientMessage(playerid, -1""COL_LGREEN" Now you don't get PMs."); 
        }
        return 
1
    }  
    else if(!
strcmp(settings"testerchat"true)) 
    { 
        if(
pInfo[playerid][tChat] == 1
        {
            
pInfo[playerid][tChat] = 0
            
SendClientMessage(playerid, -1,""COL_LGREEN" Activatedl."); 
        } 
        else
        { 
            
pInfo[playerid][tChat] = 1
            
SendClientMessage(playerid, -1,""COL_LGREEN" not"); 
        } 
        return 
1
    } 
    else if(!
strcmp(settings"adminchat"true)) 
    { 
        if(
pInfo[playerid][aChat] == 1
        { 
            
pInfo[playerid][aChat] = 0
            
SendClientMessage(playerid, -1,""COL_LGREEN" Yes."); 
        } 
        else
        { 
            
pInfo[playerid][aChat] = 1
            
SendClientMessage(playerid, -1,""COL_LGREEN" Not"); 
        } 
        return 
1
    }
    else if(!
strcmp(settings"radio"true)) 
    {
        new 
str[MAX_PLAYER_NAME+10];
        if(
pInfo[playerid][rChat] == 1
        { 
            
pInfo[playerid][rChat] = 0;
            
format(strsizeof(str), "* %s yes."PlayerName(playerid));
            
ProxDetector(30playeridstrCOLOR_PURPLE);
        } 
        else
        { 
            
pInfo[playerid][rChat] = 1
            
format(strsizeof(str), "* %s not."PlayerName(playerid)); 
            
ProxDetector(30playeridstrCOLOR_PURPLE); 
        }
        return 
1;
    }
    else 
SendClientMessage(playerid, -1"Use /toggle (PM, TesterChat, AdminChat, Radio)");
    return 
1;

Reply
#8

PHP код:
    else if(!strcmp(settings"Radio"true))
    {
        if(!
PlayerHasItem(playerid,"Statie Radio")) return SendClientMessage(playerid, -1"You don't have radio");
        {
        new 
str[128], str2[128];
        if(
pInfo[playerid][rChat] == 1)
        {
            
pInfo[playerid][rChat] = 0;
            
format(strsizeof(str), "* %s uses fingers and clicks ON."PlayerName(playerid));
            
ProxDetector(30playeridstrCOLOR_PURPLE);
        }
        else
        {
            
pInfo[playerid][rChat] = 1;
            
format(strsizeof(str2), "* %s uses fingers and cliks OFF."PlayerName(playerid));
            
ProxDetector(30playeridstr2COLOR_PURPLE);
        }
        return 
1;
    }
        } 
the clicks OFF text is shown "blank". Do you know why?
Reply
#9

pawn Код:
else if(!strcmp(settings, "Radio", true))
    {
        if(!PlayerHasItem(playerid,"Statie Radio")) return SendClientMessage(playerid, -1, "You don't have radio");
        new str[128];
        if(pInfo[playerid][rChat] == 1)
        {
            pInfo[playerid][rChat] = 0;
            format(str, sizeof(str), "* %s uses fingers and clicks ON.", PlayerName(playerid));
            ProxDetector(30, playerid, str, COLOR_PURPLE);
        }
        else
        {
            pInfo[playerid][rChat] = 1;
            format(str, sizeof(str), "* %s uses fingers and cliks OFF.", PlayerName(playerid));
            ProxDetector(30, playerid, str, COLOR_PURPLE);
        }
        return 1;
    }
you dont have to use multi variables for string, one is enough, and it happend cuz u were storing value in str2, and sending str which is empty
Reply
#10

Quote:
Originally Posted by ReD_HunTeR
Посмотреть сообщение
pawn Код:
else if(!strcmp(settings, "Radio", true))
    {
        if(!PlayerHasItem(playerid,"Statie Radio")) return SendClientMessage(playerid, -1, "You don't have radio");
        new str[128];
        if(pInfo[playerid][rChat] == 1)
        {
            pInfo[playerid][rChat] = 0;
            format(str, sizeof(str), "* %s uses fingers and clicks ON.", PlayerName(playerid));
            ProxDetector(30, playerid, str, COLOR_PURPLE);
        }
        else
        {
            pInfo[playerid][rChat] = 1;
            format(str, sizeof(str), "* %s uses fingers and cliks OFF.", PlayerName(playerid));
            ProxDetector(30, playerid, str, COLOR_PURPLE);
        }
        return 1;
    }
you dont have to use multi variables for string, one is enough, and it happend cuz u were storing value in str2, and sending str which is empty
Oh, yes, I didn't see that str is not str2. Thanks!
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)