Stock function - Printable Version
+- SA-MP Forums Archive (
https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (
https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (
https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Stock function (
/showthread.php?tid=532953)
Stock function -
Derexi - 21.08.2014
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.
Re: Stock function -
Stinged - 21.08.2014
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;
}
Re: Stock function -
Kyance - 21.08.2014
Uh, try returning the players admin level, and then try if(AdminCheck(....)), I guess :\
Re: Stock function -
Derexi - 21.08.2014
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
Re: Stock function -
Threshold - 21.08.2014
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.
Re: Stock function -
Derexi - 21.08.2014
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