#1

Код:
    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?
Reply
#2

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 )
Reply
#3

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
Reply
#4

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)
    {

    }
}
Reply
#5

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.
Reply
#6

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?
Reply
#7

PHP код:
|| && //shit
(|| b) && //ok 
Reply
#8

Quote:
Originally Posted by AbyssMorgan
Посмотреть сообщение
PHP код:
|| && //shit
(|| b) && //ok 
In other words,
Wrap it before you set it?
Reply
#9

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


Forum Jump:


Users browsing this thread: 1 Guest(s)