10.01.2014, 07:01
(
Last edited by PinkFloydLover; 10/01/2014 at 11:19 AM.
)
After reading this thread I came up with this idea for displaying admin commands using dialogs, dini and a little snippet out of gl_common.inc called 'token_by_delim', I'm currently running it on my server and it works great.
Using this method all your admin commands will automatically update into an organized dialog menu, this can easily be modified so that it works for all commands.
Put this in your /acmds command:
OnDialog:
now create the ini file in the destination that you entered, the inside of the file should look like this:
and you need a command that checks the players admin level, here's mine:
put that under every admin command you have (see below).
I added a command that lets you change the level of admin commands while ingame:
You will also need this snippet from gl_commons:
I was originally going to use SQLite and save all the commands to a table, this way I could add a description for each command and have it all accessible through the dialog, but this is a lot easier and pretty simple.
You might have to edit this code to get it to work as I have just copied it straight from my gm.
Using this method all your admin commands will automatically update into an organized dialog menu, this can easily be modified so that it works for all commands.
Put this in your /acmds command:
pawn Code:
ShowPlayerDialog(playerid, 666, DIALOG_STYLE_LIST, "Admin Commands", "Level 1 Commands \nLevel 2 Commands \nLevel 3 Commands \nLevel 4 Commands \nLevel 5 Commands \nConfig Commands \nOwner Commands", "Select", "Cancel");
pawn Code:
OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
if(dialogid == 666)
{
if(response)
{
new
File:pFile,
line[256],
var_from_line[128],
Command[24],
Level,
index,
count = -1,
DisplayStr[128],
aLVL = listitem + 1;
//change this destination to wherever you want
pFile = fopen("AdminCommands.INI", filemode:io_read);
if(!pFile)
return 1;
while(fread(pFile, line, 256) > 0)
{
index = 0;
index = token_by_delim(line,var_from_line,'=',index);
if(index == (-1)) continue;
format(Command, 24, "%s\n", var_from_line);
index = token_by_delim(line,var_from_line,' ',index+1);
Level = strval(var_from_line);
if(Level == aLVL)
{
count++;
format(CMDCount[count], 24, "%s", Command);
strins(DisplayStr, Command, 0);
}
}
fclose(pFile);
ShowPlayerDialog(playerid, 667, DIALOG_STYLE_LIST, "Admin Commands", DisplayStr, "Select", "Back");
}
return 1;
}
Code:
freeze=2 kick=2 ban=4 setlevel=5 cmdlvl=5
pawn Code:
stock CheckAdmin(playerid, command[])
{
//change these around to match your settings
if(p_INFO[playerid][ADMIN] < dini_Int("AdminCommands.INI",command))
{
new
p_STR[128];
format(p_STR, 128, "ERROR: You need to be level %d to use this command.", dini_Int("AdminCommands.INI",command));
SendClientMessage(playerid, WHITE, p_STR);
return 0;
}
return 1;
}
I added a command that lets you change the level of admin commands while ingame:
pawn Code:
dcmd_cmdlvl(playerid, params[])
{
//this string should be spelt same as the one in your AdminCommands.INI file
if(!CheckAdmin(playerid, "cmdlvl"))
return 1;
new
CMD[24],
LVL;
if(sscanf(params, "s[24]i", CMD, LVL))
{
SendClientMessage(playerid, WHITE, "USAGE: /cmdlvl <Command> <Level>");
return 1;
}
dini_IntSet("AdminCommands.INI",CMD, LVL);
new
pSTR[128];
format(pSTR, 128, "You have set the command, \"%s\"'s level requirement to %d.", CMD, LVL);
SendClientMessage(playerid, YELLOW, pSTR);
return 1;
}
pawn Code:
stock token_by_delim(const string[], return_str[], delim, start_index)
{
new x=0;
while(string[start_index] != EOS && string[start_index] != delim) {
return_str[x] = string[start_index];
x++;
start_index++;
}
return_str[x] = EOS;
if(string[start_index] == EOS) start_index = (-1);
return start_index;
}
You might have to edit this code to get it to work as I have just copied it straight from my gm.

