If || -
yvoms - 03.01.2016
Код:
if(gTeam[playerid] == TEAM_COP || gTeam[playerid] == TEAM_CIA || gTeam[playerid] == TEAM_FBI && pData[playerid][Copban] != 0)
{
SendClientMessage(playerid,COLOR_WHITE,"{FF0000}[ERROR]{FFFFFF} You are banned from using the cop classuse /unbanme to get unbanned.");
return 0;
}
|| = Or, right?
On compiling i dont get any error however ingame i get the message You are banned from using the cop class use /unbanme to get unbanned while the value in the database is 0,
only appears to occur for the Team_cop and Team_Cia
the other one works
Does || not work in a if function?
Re: If || -
Godey - 03.01.2016
Quote:
if(gTeam[playerid] == TEAM_COP || gTeam[playerid] == TEAM_CIA || gTeam[playerid] == TEAM_FBI && pData[playerid][Copban] != 0)
{
SendClientMessage(playerid,COLOR_WHITE,"{FF0000}[ERROR]{FFFFFF} You are banned from using the cop classuse /unbanme to get unbanned.");
return 0;
}
|
Yes, || means OR.
Have you tried,
Код:
if((gTeam[playerid] == TEAM_COP) || (gTeam[playerid] == TEAM_CIA) || (gTeam[playerid] == TEAM_FBI) && (pData[playerid][Copban]) != 0)
{
SendClientMessage(playerid,COLOR_WHITE,"{FF0000}[ERROR]{FFFFFF} You are banned from using the cop classuse /unbanme to get unbanned.");
return 0;
}
(I'm not on my PC, correct me if I'm wrong
)
Re: If || -
AndySedeyn - 03.01.2016
Using brackets in such an if-statement can make a difference. Try:
PHP код:
if((gTeam[playerid] == TEAM_COP || gTeam[playerid] == TEAM_CIA || gTeam[playerid] == TEAM_FBI) && pData[playerid][Copban] != 0)
It works just like in mathematics:
Код:
2 - 5 * 4 = -18
(2 - 5) * 4 = -12
Re: If || -
SickAttack - 03.01.2016
Quote:
Originally Posted by AndySedeyn
Using brackets in such an if-statement can make a difference. Try:
PHP код:
if((gTeam[playerid] == TEAM_COP || gTeam[playerid] == TEAM_CIA || gTeam[playerid] == TEAM_FBI) && pData[playerid][Copban] != 0)
It works just like in mathematics:
Код:
2 - 5 * 4 = -18, while (2-5) * 4 = -12
|
There is no point in validating anything related to a player's class if they aren't cop banned.
pawn Код:
if(pData[playerid][Copban])
{
if(gTeam[playerid] == TEAM_COP || gTeam[playerid] == TEAM_CIA || gTeam[playerid] == TEAM_FBI)
{
}
}
Re: If || -
Karan007 - 03.01.2016
You can use this aswell.
PHP код:
if(pData[playerid][Copban] && gTeam[playerid] == TEAM_COP || gTeam[playerid] == TEAM_CIA || gTeam[playerid] == TEAM_FBI)
{
//Your code here
}
Note: It checks if the player is cop banned then checks if the player chose the following teams.
Re: If || -
yvoms - 03.01.2016
Quote:
Originally Posted by Karan007
You can use this aswell.
PHP код:
if(pData[playerid][Copban] && gTeam[playerid] == TEAM_COP || gTeam[playerid] == TEAM_CIA || gTeam[playerid] == TEAM_FBI)
{
//Your code here
}
Note: It checks if the player is cop banned then checks if the player chose the following teams.
|
So if im correct if(pData[playerid][Copban] automaticly fetches the value?
Re: If || -
AbyssMorgan - 03.01.2016
PHP код:
a || b && c //shit
(a || b) && c //ok
Re: If || -
yvoms - 03.01.2016
Quote:
Originally Posted by AbyssMorgan
PHP код:
a || b && c //shit
(a || b) && c //ok
|
In other words,
Wrap it before you set it?
Re: If || -
SickAttack - 03.01.2016
Quote:
Originally Posted by yvoms
So if im correct if(pData[playerid][Copban] automaticly fetches the value?
|
You were checking for "not 0, != 0", so in this particular matter, we can do the following: "if(pData[playerid][Copban])" means not 0 and "if(!pData[playerid][Copban])" means 0. Just like with booleans "if(a)" means if "a" is true and "if(!a)" means if "a" is false.
What's 0 is false, what's not 0 is true.
And like I said, there's ABSOLUTELY no need for you to validate their class whatsoever if a player is not cop banned. Meaning, go with any of the following:
pawn Код:
if(pData[playerid][Copban])
{
if(gTeam[playerid] == TEAM_COP || gTeam[playerid] == TEAM_CIA || gTeam[playerid] == TEAM_FBI)
{
}
}
pawn Код:
if((pData[playerid][Copban]) && (gTeam[playerid] == TEAM_COP || gTeam[playerid] == TEAM_CIA || gTeam[playerid] == TEAM_FBI))
{
}
Not that the inner parenthesis are separating each condition as it goes (just like in groups).
Example:
pawn Код:
if((2 == 2 || 3 == 4) && (5 == 5))
If the first condition in "(2 == 2 || 3 == 4)" is true, then the condition is completed; otherwise, it isn't.