Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <a_samp.inc>
- #include <ZCMD.inc>
- /******************************************************************************/
- /* If you are going to load the command levels from database, this is the only approach:
- An array with list of cmds "gCMDMinLevel"
- Pros:
- Dynamically load command list from database
- Cons:
- Each executed command needs a loop through all cmds
- Not as bad as it sounds like tho.
- */
- /******************************************************************************/
- enum e_PERMISSION {
- e_P_COMMAND[32],
- e_P_LEVEL
- };
- new gCMDMinLevel[][e_PERMISSION] = {
- {"kick", 1},
- {"v", 2},
- {"setlevel", 5}
- //etc...
- };
- //You'll be using this in the ZCMD
- #define CMDMinLevel[%0] iCMDMinLevel(#%0)
- stock iCMDMinLevel(cmd[]) {
- for(new i = 0; i < sizeof gCMDMinLevel; i++) {
- if(!strcmp(cmd, gCMDMinLevel[i][e_P_COMMAND], true)) {
- return gCMDMinLevel[i][e_P_LEVEL];
- }
- }
- printf("[WARNING] Command '%s' doesn't exist in permissions.", cmd);
- return 0;
- }
- //Use this function to update command's permission level from database or something
- stock CMDSetMinLevel(cmd[], level) {
- for(new i = 0; i < sizeof gCMDMinLevel; i++) {
- if(!strcmp(cmd, gCMDMinLevel[i][e_P_COMMAND], true)) {
- gCMDMinLevel[i][e_P_LEVEL] = level;
- printf("[SUCCESS] Command '%s' permission level set to %i.", cmd, level);
- return;
- }
- }
- printf("[WARNING] Command '%s' doesn't exist in permissions.", cmd);
- }
- /******************************************************************************/
- /* Your regular scripts here */
- /******************************************************************************/
- enum e_pInfo {
- aLevel
- };
- new pInfo[MAX_PLAYERS][e_pInfo];
- main(){}
- public OnFilterScriptInit() {
- //Changing permissions
- CMDSetMinLevel("v", 3);
- CMDSetMinLevel("banana", 10);
- return true;
- }
- CMD:v(playerid, params[]) {
- if(pInfo[playerid][aLevel] < CMDMinLevel[v])
- return SendClientMessage(playerid, 0xFF0000FF, "ERROR: Insufficient permissions to use this command!");
- SendClientMessage(playerid, -1, "Access granted!");
- return true;
- }
Advertisement
Add Comment
Please, Sign In to add comment