iPLEOMAX

Dynamic Command Permissions - Method #2

Jan 15th, 2016
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 1.51 KB | None | 0 0
  1. #include <a_samp.inc>
  2. #include <ZCMD.inc>
  3.  
  4. /******************************************************************************/
  5. /*  If you want to stick to only using enums:
  6.     Pros:
  7.         No loop
  8.     Cons:
  9.         Split into two parts (enum and variable)
  10.  */
  11. /******************************************************************************/
  12.  
  13. #define CMDMinLevel[%0] gCMDMinLevel[E_CMD_%0]
  14. #define CMDSetMinLevel(%0,%1) gCMDMinLevel[E_CMD_%0] = %1
  15.  
  16. //The only reason we need to use "E_CMD_" prefix for each of the command names
  17. //is because it will interfere with local variables named 'v' or 'kill', etc
  18. //Unfornately PAWN doesn't categorize enum constants
  19.  
  20. enum E_CMD_PERMISSIONS {
  21.     E_CMD_v,
  22.     E_CMD_setlevel,
  23.     E_CMD_kill
  24. };
  25.  
  26. //Obviously you can modify these values from database because they are variables.
  27. //But you need to make sure index is correct
  28.  
  29. new
  30.     gCMDMinLevel[E_CMD_PERMISSIONS] = {
  31.         2,
  32.         5,
  33.         1
  34.     }
  35. ;
  36.  
  37. /******************************************************************************/
  38. /* Your regular scripts here                                                  */
  39. /******************************************************************************/
  40.  
  41. enum e_pInfo {
  42.     aLevel
  43. };
  44.  
  45. new pInfo[MAX_PLAYERS][e_pInfo];
  46.  
  47. main(){}
  48.  
  49. public OnFilterScriptInit() {
  50.     //Changing permissions
  51.     CMDSetMinLevel(v, 5);
  52.     return true;
  53. }
  54.  
  55. CMD:v(playerid, params[]) {
  56.     if(pInfo[playerid][aLevel] < CMDMinLevel[v])
  57.         return SendClientMessage(playerid, 0xFF0000FF, "ERROR: Insufficient permissions to use this command!");
  58.  
  59.     return true;
  60. }
Add Comment
Please, Sign In to add comment