|| and && question.
#1

I am trying to make a /setadmin command, and I am trying to make it available for only RCON Admins or Level 1337 Admins. Now how do I go about this? I even looked in a C help forum to figure out the difference between
Код:
|| and &&
and once I figured that out I changed my command in light of this and there was no difference.

So here is my question. How can I make this command available for RCON Admins or Level 1337 Admins? Not a real big issue I just really need to learn to distinguish || from &&.

My code.

pawn Код:
if(!IsPlayerAdmin(playerid) || pInfo[playerid][pAdmin] != 1337)
    {
        return SendClientMessage(playerid,COLOR_LIGHTGRAY,"You are not authorized to use that command.");
    }
And here is the if statement that sets their admin level.

pawn Код:
else if(IsPlayerAdmin(playerid) || pInfo[playerid][pAdmin] == 1337)
    {
        format(tidstring,sizeof(tidstring),"Administrator %s has made you a level %d Adminstrator.",sin,aLevel);
        format(sidstring,sizeof(sidstring),"You have made %s a level %d Administrator.",tin,aLevel);
        SendClientMessage(tid,COLOR_AQUA,tidstring);
        SendClientMessage(sid,COLOR_AQUA,sidstring);
        pInfo[tid][pAdmin] = aLevel;
        return 1;
    }
Am I using the if statements correctly?
Reply
#2

Why not eliminate both the if/else if statements and just return a message if they are not an admin, like so:

pawn Код:
CMD:BLAH(BLAH)
{
if(!IsPlayerAdmin(playerid) && pInfo[playerid][pAdmin] != 1337) return SendClientMessage(playerid,COLOR_LIGHTGRAY,"You are not authorized to use that command.");
format(tidstring,sizeof(tidstring),"Administrator %s has made you a level %d Adminstrator.",sin,aLevel);
format(sidstring,sizeof(sidstring),"You have made %s a level %d Administrator.",tin,aLevel);
SendClientMessage(tid,COLOR_AQUA,tidstring);
SendClientMessage(sid,COLOR_AQUA,sidstring);
pInfo[tid][pAdmin] = aLevel;
return 1;
}
Reply
#3

|| OR
&& AND
! negation 1 != 2 will mean 1 NOT equal 2
Reply
#4

pawn Код:
if(!IsPlayerAdmin(playerid) || pInfo[playerid][pAdmin] != 1337)  return SendClientMessage(playerid,COLOR_LIGHTGRAY,"You are not authorized to use that command.");
format(tidstring,sizeof(tidstring),"Administrator %s has made you a level %d Adminstrator.",sin,aLevel);
format(sidstring,sizeof(sidstring),"You have made %s a level %d Administrator.",tin,aLevel); SendClientMessage(tid,COLOR_AQUA,tidstring);
SendClientMessage(sid,COLOR_AQUA,sidstring);
pInfo[tid][pAdmin] = aLevel;
return 1;
In my opinion this is the best way of doing it.
Reply
#5

Quote:
Originally Posted by DRIFT_HUNTER
Посмотреть сообщение
|| OR
&& AND
! negation 1 != 2 will mean 1 NOT equal 2
Thank you, this is what I was looking for.
Reply
#6

pawn Код:
IsPlayerAdmin(playerid) || pInfo[playerid][AdminLevel] == 1337
This code first checks if the player is an RCON admin. If he is an RCON admin, it does not check the second code but if he isn't an RCON admin, then it checks if the variable pInfo[playerid][AdminLevel] is equal to 1337. If any of the above statements is incorrect, the code can still run if the other one is correct.

pawn Код:
IsPlayerAdmin(playerid) && pInfo[playerid][AdminLevel] == 1337
First checks if the player is an RCON admin and if he is, then it checks if his pInfo[playerid][AdminLevel] is equal to 1337. If any of the above statements is found incorrect, it will make both of them false.
Reply
#7

https://sampwiki.blast.hk/wiki/Control_Structures
Reply
#8

Quote:
Originally Posted by suhrab_mujeeb
Посмотреть сообщение
pawn Код:
IsPlayerAdmin(playerid) || pInfo[playerid][AdminLevel] == 1337
This code first checks if the player is an RCON admin. If he is an RCON admin, it does not check the second code but if he isn't an RCON admin, then it checks if the variable pInfo[playerid][AdminLevel] is equal to 1337. If any of the above statements is incorrect, the code can still run if the other one is correct.

pawn Код:
IsPlayerAdmin(playerid) && pInfo[playerid][AdminLevel] == 1337
First checks if the player is an RCON admin and if he is, then it checks if his pInfo[playerid][AdminLevel] is equal to 1337. If any of the above statements is found incorrect, it will make both of them false.
Wow, thank you for going more in depth. Very appreciated.
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)