Logical OR || Operator doesn't work properly
#1

I am creating sendrcon command on my server

Код:
CMD:sendrcon(playerid, params[])
{
	if(!IsPlayerAdmin(playerid) || pInfo[playerid][Admin] == 6) return SendClientMessage(playerid, 0xFFFFFFFF, "[HPRP]: You don't have enough permissions to use this command");
	{
        new rconcmd[128];
	    if(sscanf(params, "s[128]", rconcmd)) return SendClientMessage(playerid, 0xFFFFFFFF, "[HPRP] SYNTAX: /sendrcon [message]");
		{
			SendRconCommand(rconcmd);
			format(rconcmd, sizeof(rconcmd), "Command %s has been sent to RCON", rconcmd);
			SendClientMessage(playerid, 0xFFFFFFFF, rconcmd);
		}
	}
	return CMD_SUCCESS;
}
but when i got both var on my player, it says i don't have enough permission. but when i only have RCON assigned to my player, it works... so that means the error is on Logical OR Operator, cos i already check'd my stats, and i have Level 6 Admin on my player when i got denied... i've tried using both samp original pawn compiler and pawn-lang compiler

what do i need to do so when i got both var it would work?
Reply
#2

It should be like this:
PHP код:
if(!IsPlayerAdmin(playerid) || pInfo[playerid][Admin] != 6) return SendClientMessage(playerid0xFFFFFFFF"[HPRP]: You don't have enough permissions to use this command"); 
In your code, It says, "If the player is not an admin or if he is an admin with level 6, Send error message". That's not what you want. What you want is, "If the player is not and admin or if he is not level 6, Send error message". The operator != translates to if the admin level is not equal to six. But I would recommend you to do this.

PHP код:
if(!IsPlayerAdmin(playerid) || pInfo[playerid][Admin] < 6) return SendClientMessage(playerid0xFFFFFFFF"[HPRP]: You don't have enough permissions to use this command"); 
This means players with level 6 and above can use the command.
Reply
#3

!IsPlayerAdmin(playerid) || pInfo[playerid][Admin] == 6

See that thing in red? It is the equality operator, so if left is equal to right (pInfo[playerid][Admin] and 6) it will give a value of true.
What you need is the inequality operator ( != ), which checks if left and right aren't equal.

PS: Read this article about C/++ operators (ignore the C/++ specific things) because Pawn is based on C's syntax.
Reply
#4

rep to both of u guys xd thanks, i'm so dumb
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)