CMD:toggle(playerid, params[])
{
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]", settings, info);
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(string, sizeof(string), "* %s yes. ", PlayerName(playerid));
ProxDetector(30, playerid, string, COLOR_PURPLE);
}
if(pInfo[playerid][rChat] == 1)
{
pInfo[playerid][rChat] = 1;
format(string, sizeof(string), "* %s not. ", PlayerName(playerid));
ProxDetector(30, playerid, string, COLOR_PURPLE);
return 1;
}
}
return 1;
}
// 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");
}
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."); }
> 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 |
> 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. |
pawn Код:
|
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.
|
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."); } 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. |
CMD:toggle(playerid, params[])
{
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(str, sizeof(str), "* %s yes.", PlayerName(playerid));
ProxDetector(30, playerid, str, COLOR_PURPLE);
}
else
{
pInfo[playerid][rChat] = 1;
format(str, sizeof(str), "* %s not.", PlayerName(playerid));
ProxDetector(30, playerid, str, COLOR_PURPLE);
}
return 1;
}
else SendClientMessage(playerid, -1, "Use /toggle (PM, TesterChat, AdminChat, Radio)");
return 1;
}
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(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(str2), "* %s uses fingers and cliks OFF.", PlayerName(playerid));
ProxDetector(30, playerid, str2, COLOR_PURPLE);
}
return 1;
}
}
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;
}
pawn Код:
|