A good way to sort and present commands...
#19

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:
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");
OnDialog:

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;
    }
now create the ini file in the destination that you entered, the inside of the file should look like this:

Code:
freeze=2
kick=2
ban=4
setlevel=5
cmdlvl=5
and you need a command that checks the players admin level, here's mine:
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;
}
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:
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;
}
You will also need this snippet from gl_commons:

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;
}
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.
Reply


Messages In This Thread
A good way to sort and present commands... - by Scenario - 30.07.2013, 04:02
Re: A good way to sort and present commands... - by JimmyCh - 30.07.2013, 11:44
Re: A good way to sort and present commands... - by Vince - 30.07.2013, 12:38
Re: A good way to sort and present commands... - by Scenario - 30.07.2013, 15:04
Re: A good way to sort and present commands... - by MP2 - 30.07.2013, 15:47
Re: A good way to sort and present commands... - by Kar - 30.07.2013, 16:25
Re: A good way to sort and present commands... - by Vince - 30.07.2013, 16:30
Re: A good way to sort and present commands... - by Scenario - 30.07.2013, 17:03
Re: A good way to sort and present commands... - by Slice - 05.08.2013, 09:10
Re: A good way to sort and present commands... - by Slice - 05.08.2013, 12:35
Re: A good way to sort and present commands... - by legodude - 06.08.2013, 09:55
Re: A good way to sort and present commands... - by Slice - 06.08.2013, 10:05
Re: A good way to sort and present commands... - by RealCop228 - 06.08.2013, 15:07
Re: A good way to sort and present commands... - by Slice - 06.08.2013, 16:59
Re: A good way to sort and present commands... - by RealCop228 - 06.08.2013, 17:09
Re: A good way to sort and present commands... - by [XST]O_x - 06.08.2013, 20:11
Re: A good way to sort and present commands... - by Macluawn - 06.08.2013, 20:24
Re: A good way to sort and present commands... - by Lorenc_ - 09.08.2013, 07:43
Re: A good way to sort and present commands... - by PinkFloydLover - 10.01.2014, 07:01

Forum Jump:


Users browsing this thread: 1 Guest(s)