|| and && question. -
ReneG - 22.02.2012
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 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?
Re: || and && question. -
coole210 - 22.02.2012
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;
}
Re: || and && question. -
DRIFT_HUNTER - 22.02.2012
|| OR
&& AND
! negation 1 != 2 will mean 1 NOT equal 2
Re: || and && question. -
JhnzRep - 22.02.2012
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.
Re: || and && question. -
ReneG - 22.02.2012
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.
Re: || and && question. - suhrab_mujeeb - 22.02.2012
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.
Re: || and && question. -
[HiC]TheKiller - 22.02.2012
https://sampwiki.blast.hk/wiki/Control_Structures
Re: || and && question. -
ReneG - 22.02.2012
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.