Quote:
Originally Posted by Crayder
You didn't fix anything, you're still only accepting things that are not zero... xD
The example is for scripts that have all flags set, which is how it tends to be if you're using flags. You can't have a flag that is nothing so you can't check for a flag that's not set because it is 0 and you can't do bit operations on it. I can't explain things when I first wake up... but I think you get my point?
But, if you prefer to have a way to see if no flags are set, you should be using OR not AND.
|
Or simply when flags is 0 (non set), it means it is a non-admin command.
pawn Code:
#include <a_samp>
#include <Pawn.CMD>
main() {}
enum (<<= 1)
{
CMD_ADMIN = 1, // 0b00000000000000000000000000000001
CMD_MODER, // 0b00000000000000000000000000000010
CMD_JR_MODER // 0b00000000000000000000000000000100
};
new pPermissions[MAX_PLAYERS];
flags:ban(CMD_ADMIN);
cmd:ban(playerid, params[])
{
return 1;
}
cmd:rules(playerid, params[])
{
return 1;
}
public OnPlayerCommandReceived(playerid, cmd[], params[], flags)
{
printf("OnPlayerCommandReceived(%d, \"%s\", \"%s\", %d)", playerid, cmd, params, flags);
if (!(flags & pPermissions[playerid]))
{
printf("player %d doesn’t have access to command '%s'", playerid, cmd);
return 0;
}
return 1;
}
public PC_OnInit()
{
const testAdminPlayerId = 1, testSimplePlayerId = 4;
pPermissions[testAdminPlayerId] = CMD_ADMIN | CMD_MODER | CMD_JR_MODER;
pPermissions[testSimplePlayerId] = 0;
PC_EmulateCommand(testAdminPlayerId, "/ban 4 some reason");
PC_EmulateCommand(testSimplePlayerId, "/ban 1 some reason");
PC_EmulateCommand(testAdminPlayerId, "/rules");
PC_EmulateCommand(testSimplePlayerId, "/rules");
}
Output:
Code:
OnPlayerCommandReceived(1, "ban", "4 some reason", 1)
OnPlayerCommandReceived(4, "ban", "1 some reason", 1)
player 4 doesn’t have access to command 'ban'
OnPlayerCommandReceived(1, "rules", "", 0)
player 1 doesn’t have access to command 'rules'
OnPlayerCommandReceived(4, "rules", "", 0)
player 4 doesn’t have access to command 'rules'
Nobody can use /rules command unless you change that line to:
pawn Code:
if (flags != 0 && !(flags & pPermissions[playerid]))
Output:
pawn Code:
OnPlayerCommandReceived(1, "ban", "4 some reason", 1)
OnPlayerCommandReceived(4, "ban", "1 some reason", 1)
player 4 doesn’t have access to command 'ban'
OnPlayerCommandReceived(1, "rules", "", 0)
OnPlayerCommandReceived(4, "rules", "", 0)
accessible by every player.