Stock function
#1

I made this stock function to check if a player is an admin, so I don't have to keep writing the whole check out every time I make a command:

pawn Код:
stock AdminCheck(playerid, levell)
{
    if(!IsPlayerAdmin(playerid) || pData[playerid][Level] < levell) return SendClientMessage(playerid, ERROR, "Error: {FFFFFF}You do not have permission to use this command!");
    return 1;
}
Then when I make a command I do:
pawn Код:
CMD:setscore(playerid, params[])
{
    new score;
   
    AdminCheck(playerid, 3);
//rest of code
But when I use a command and I'm an admin, it sends the error message but then still continues doing what it's supposed to do. For example if I do /kick, it'll do:
Код:
Error: You do not have permission to use this command!
Usage: /kick [player name/ID] [reason]
in the chat.
Reply
#2

Try this.

pawn Код:
stock AdminCheck(playerid, levell)
{
    if(!IsPlayerAdmin(playerid) && pData[playerid][Level] < levell) return SendClientMessage(playerid, ERROR, "Error: {FFFFFF}You do not have permission to use this command!");
    return 1;
}
Reply
#3

Uh, try returning the players admin level, and then try if(AdminCheck(....)), I guess :\
Reply
#4

Quote:
Originally Posted by Kyance
Посмотреть сообщение
Uh, try returning the players admin level, and then try if(AdminCheck(....)), I guess :\
Is that really the only way? Really don't fancy going through every check to change it! :P
Reply
#5

Actually, you would be better off using a macro for this..
pawn Код:
#define AdminCheck(%0,%1) if(!IsPlayerAdmin((%0)) && pData[(%0)][Level] < (%1))\
    return SendClientMessage((%0), ERROR, "Error: {FFFFFF}You do not have permission to use this command!");
Using a stock function, no matter what it returns, it won't really 'break' the code, it will just return a value and continue... macros act as a 'text' replacement.
Reply
#6

Quote:
Originally Posted by Threshold
Посмотреть сообщение
Actually, you would be better off using a macro for this..
pawn Код:
#define AdminCheck(%0,%1) if(!IsPlayerAdmin((%0)) && pData[(%0)][Level] < (%1))\
    return SendClientMessage((%0), ERROR, "Error: {FFFFFF}You do not have permission to use this command!");
Using a stock function, no matter what it returns, it won't really 'break' the code, it will just return a value and continue... macros act as a 'text' replacement.
Awesome! Thanks
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)