Help /admins
#1

Hi. I don't remember how you could do it that the administrators show up in the window. I have made the PlayerInfo[playerid][pRank] variable.

Reply
#2

use https://sampwiki.blast.hk/wiki/Strcat
Reply
#3

Here's mine, change it to your liking.

pawn Code:
CMD:admins(playerid, params[])
{
    SendClientMessage(playerid, -1, ""COL_ORANGE"--- | Online Administrators | ---");
    new count = 0;
    for(new i = 0; i < MAX_PLAYERS; i++)
    {
        if(!IsPlayerConnected(i)) continue;
        if(!pInfo[i][pAdmin]) continue;
        new string[90], playersname[MAX_PLAYER_NAME];
        GetPlayerName(i, playersname, sizeof(playersname));
        switch(pInfo[i][pAdmin])
        {
            case 1: format(string, sizeof(string), ""COL_ORANGE"Trial Administrator: {FFFFFF}%s (%i)", playersname, i);
            case 2: format(string, sizeof(string), ""COL_ORANGE"Server Administrator: {FFFFFF}%s (%i)", playersname, i);
            case 3: format(string, sizeof(string), ""COL_ORANGE"Senior Administrator: {FFFFFF}%s (%i)", playersname, i);
            case 4: format(string, sizeof(string), ""COL_ORANGE"General Administrator: {FFFFFF}%s (%i)", playersname, i);
            case 5: format(string, sizeof(string), ""COL_ORANGE"Head Administrator: {FFFFFF}%s (%i)", playersname, i);
            case 6: format(string, sizeof(string), ""COL_ORANGE"Server Director: {FFFFFF}%s (%i)", playersname, i);
            default: continue;
        }
        SendClientMessage(playerid, -1, string);
        count++;
    }
    if(!count) SendClientMessage(playerid, -1, ""COL_ORANGE"There are no Administrators Online");
    return 1;
}
Reply
#4

After entering the /semi1 command in /admins, it displays that there is no administrator. After entering /rank1 it is displayed in the dialogue that I am the administrator. Why after entering /semi1 does not appear to me that I am a semi-administrator?
Code:
#include "a_samp"
#include "Pawn.CMD"

main(){}

new SemiAdmin[MAX_PLAYERS];
new Rank[MAX_PLAYERS];

public OnGameModeInit()
{
	return 1;
}
public OnGameModeExit()
{
	return 1;
}
CMD:admins(playerid, params[])
{
	new count = 0;

	for(new i = 0; i < MAX_PLAYERS; i++)
	{
		if(!IsPlayerConnected(i)) continue;
		if(!SemiAdmin[i]) continue;
		if(!Rank[i]) continue;

		new string[128];
		new pName[24];

		GetPlayerName(i, pName, sizeof(pName));

		switch(SemiAdmin[i])
		{
			case 1: format(string, sizeof(string), "Semi Administrator [Level 1]: %s (ID: %d)", pName, i);
			case 2: format(string, sizeof(string), "Semi Administrator [Level 2]: %s (ID: %d)", pName, i);
			case 3: format(string, sizeof(string), "Semi Administrator [Level 3]: %s (ID: %d)", pName, i);
			default: return false;
		}
		switch(Rank[i])
		{
			case 1: format(string, sizeof(string), "Administrator: %s (ID: %d)", pName, i);
			case 2: format(string, sizeof(string), "Vice Head Admin: %s (ID: %d)", pName, i);
			case 3: format(string, sizeof(string), "Head Admin: %s (ID: %d)", pName, i);
			default: return false;
		}

		ShowPlayerDialog(playerid, 7777, DIALOG_STYLE_MSGBOX, "Online Administrators", string, "OK", "");

		count++;
	}
	if(!count) ShowPlayerDialog(playerid, 0, DIALOG_STYLE_MSGBOX, "No Administrators", "There are no Administrators Online", "OK", "");
	return 1;
}
CMD:rank1(playerid)
{
	Rank[playerid] = 1;
	return 1;
}
CMD:rank2(playerid)
{
	Rank[playerid] = 2;
	return 1;
}
CMD:rank3(playerid)
{
	Rank[playerid] = 3;
	return 1;
}
CMD:semi1(playerid)
{
	SemiAdmin[playerid] = 1;
	Rank[playerid] = 0;
	return 1;
}
CMD:semi2(playerid)
{
	SemiAdmin[playerid] = 2;
	Rank[playerid] = 0;
	return 1;
}
CMD:semi3(playerid)
{
	SemiAdmin[playerid] = 3;
	Rank[playerid] = 0;
	return 1;
}
Reply
#5

Some notices:
- That script would only show the admin with the highest playerid.
- If SemiAdmin for someone is not 1,2 or 3, it would:
* Show nothing at all if the lowest playerid has that level
* Show the last admin with SemiAdmin or Rank having value 1,2 or 3
- ^ Same goes for array Rank
- Since SemiAdmin and Rank only hold value 0, 1, 2 or 3, you might wanna pack those arrays / accessing a single byte instead of a whole cell to save some space (x4 per array).
- Instead of switching between Rank/SemiAdmin and then formatting the string, you might aswell create arrays holding the names of the levels.

Quote:

Why after entering /semi1 does not appear to me that I am a semi-administrator?

Quote:

- If SemiAdmin for someone is not 1,2 or 3, it would:
* Show nothing at all if the lowest playerid has that level
* Show the last admin with SemiAdmin or Rank having value 1,2 or 3
- ^ Same goes for array Rank

It first formats the string if SemiAdmin is 1,2 or 3. Then, it checks Rank. If it is not 1, 2 or 3 (default) you use 'return false'. When using return, you break the entire function (in this case, the command). SemiAdmin is 1, 2 or 3 but Rank is 0 so it breaks the entire command, and probably shows you a "SERVER: Unknown command" aswell since you returned false (= 0).
Reply
#6

Is this the best way?
Code:
#include "a_samp"
#include "Pawn.CMD"

main(){}

new Admin[MAX_PLAYERS];
new SemiAdminLVL[MAX_PLAYERS];

public OnGameModeInit()
{
	return 1;
}
public OnGameModeExit()
{
	return 1;
}
CMD:admins(playerid, params[])
{
	new count = 0;

	for(new i = 0; i < MAX_PLAYERS; i++)
	{
		if(!IsPlayerConnected(i)) continue;
		if(!Admin[i]) continue;

		new string[128];
		new pName[24];

		GetPlayerName(i, pName, sizeof(pName));

		switch(Admin[i])
		{
			case 1: format(string, sizeof(string), "Semi-Administrator [Level %d]: %s (ID: %d)", SemiAdminLVL, pName, i);
			case 2: format(string, sizeof(string), "Administrator: %s (ID: %d)", pName, i);
			case 3: format(string, sizeof(string), "Vice Head Admin: %s (ID: %d)", pName, i);
			case 4: format(string, sizeof(string), "Head Admin: %s (ID: %d)", pName, i);
			default: continue;
		}

		ShowPlayerDialog(playerid, 7777, DIALOG_STYLE_MSGBOX, "Online Administrators", string, "OK", "");

		count++;
	}
	if(!count) ShowPlayerDialog(playerid, 0, DIALOG_STYLE_MSGBOX, "No Administrators", "There are no Administrators Online", "OK", "");
	return 1;
}
CMD:rank1(playerid)
{
	Admin[playerid] = 2;
	return 1;
}
CMD:rank2(playerid)
{
	Admin[playerid] = 3;
	return 1;
}
CMD:rank3(playerid)
{
	Admin[playerid] = 4;
	return 1;
}
CMD:semi1(playerid)
{
	Admin[playerid] = 1;
	SemiAdminLVL[playerid] = 1;
	return 1;
}
CMD:semi2(playerid)
{
	Admin[playerid] = 1;
	SemiAdminLVL[playerid] = 2;
	return 1;
}
CMD:semi3(playerid)
{
	Admin[playerid] = 1;
	SemiAdminLVL[playerid] = 3;
	return 1;
}
Reply
#7

This is how I would do it:

pawn Code:
new const AdminLevelName[][] = {
    "User",
    "Semi Administrator [Level 1]",
    "Semi Administrator [Level 2]",
    "Semi Administrator [Level 3]",
    "Administrator",
    "Vice Head Admin",
    "Head Admin"
};
new AdminLevel[MAX_PLAYERS char];

CMD:admins(playerid)
{
    new admins_string[500], count;
    for (new i; i < MAX_PLAYERS; i++) //I would actually use foreach, but sticking to your way for now
    {
        if (!IsPlayerConnected(i) || IsPlayerNPC(i) || !AdminLevel{i}) continue;
       
        new pName[MAX_PLAYER_NAME];
        GetPlayerName(i, pName, MAX_PLAYER_NAME);
        format(admins_string, sizeof(admins_string), "%s%s: %s (ID: %d)\n", admins_string, AdminLevelName[AdminLevel{i}], pName, i);
        count++;
    }
    if (!count)
        ShowPlayerDialog(playerid, 7777, DIALOG_STYLE_MSGBOX, "Online Administrators", "There are currently no administrators online", "OK", "");
    else ShowPlayerDialog(playerid, 7777, DIALOG_STYLE_MSGBOX, "Online Administrators", admins_string, "OK", "");
    return 1;
}
I would not actually do it exactly like that, but according to your code, I would change it to something like this.
Note the next few things:

1) There is an array named "AdminLevelName". By using AdminLevelName[0] it would return "User", AdminLevelName[1] would return "Semi Administrator [Level 1]" etcetera. Rather than switching between two variables, you can now get the level name from the array.
2) Note how I used "const" for AdminLevelName; because of this, you can't alter the array after creating it to prevent problems
3) I use 'AdminLevel' to hold someone's level. Note how I used 'MAX_PLAYERS char' instead of 'MAX_PLAYERS'. This decreases the array size by 4 (what it basically does is MAX_PLAYERS / 4)
4) As an addition to 3), I use {playerid} (or {i}, in this scenario) instead of [playerid] (or [i]).
By using curly brackets ({}) instead of the regular ones ([]) you access a single byte instead of a whole cell.
One cell uses 4 bytes. Whereas 1 byte, well, uses 1 byte. When accessing a single byte you can only use values from 0 up to 255. Since AdminLevel is, in this scenario, is 0 up to 6, I'm accessing a single byte instead of a whole cell. This saves 4 times the space it otherwise would use.
Reply
#8

Hello, does anybody know how could I do the command /admins like this one?

If picture is not showing see here: https://imgur.com/a/VZJFqqC
Reply
#9

Quote:
Originally Posted by Kwarde
View Post
This is how I would do it:

pawn Code:
new const AdminLevelName[][] = {
    "User",
    "Semi Administrator [Level 1]",
    "Semi Administrator [Level 2]",
    "Semi Administrator [Level 3]",
    "Administrator",
    "Vice Head Admin",
    "Head Admin"
};
new AdminLevel[MAX_PLAYERS char];

CMD:admins(playerid)
{
    new admins_string[500], count;
    for (new i; i < MAX_PLAYERS; i++) //I would actually use foreach, but sticking to your way for now
    {
        if (!IsPlayerConnected(i) || IsPlayerNPC(i) || !AdminLevel{i}) continue;
       
        new pName[MAX_PLAYER_NAME];
        GetPlayerName(i, pName, MAX_PLAYER_NAME);
        format(admins_string, sizeof(admins_string), "%s%s: %s (ID: %d)\n", admins_string, AdminLevelName[AdminLevel{i}], pName, i);
        count++;
    }
    if (!count)
        ShowPlayerDialog(playerid, 7777, DIALOG_STYLE_MSGBOX, "Online Administrators", "There are currently no administrators online", "OK", "");
    else ShowPlayerDialog(playerid, 7777, DIALOG_STYLE_MSGBOX, "Online Administrators", admins_string, "OK", "");
    return 1;
}
I would not actually do it exactly like that, but according to your code, I would change it to something like this.
Note the next few things:

1) There is an array named "AdminLevelName". By using AdminLevelName[0] it would return "User", AdminLevelName[1] would return "Semi Administrator [Level 1]" etcetera. Rather than switching between two variables, you can now get the level name from the array.
2) Note how I used "const" for AdminLevelName; because of this, you can't alter the array after creating it to prevent problems
3) I use 'AdminLevel' to hold someone's level. Note how I used 'MAX_PLAYERS char' instead of 'MAX_PLAYERS'. This decreases the array size by 4 (what it basically does is MAX_PLAYERS / 4)
4) As an addition to 3), I use {playerid} (or {i}, in this scenario) instead of [playerid] (or [i]).
By using curly brackets ({}) instead of the regular ones ([]) you access a single byte instead of a whole cell.
One cell uses 4 bytes. Whereas 1 byte, well, uses 1 byte. When accessing a single byte you can only use values from 0 up to 255. Since AdminLevel is, in this scenario, is 0 up to 6, I'm accessing a single byte instead of a whole cell. This saves 4 times the space it otherwise would use.
Did not works. All the time it shows that there is no administrator.
Reply
#10

Quote:
Originally Posted by KamilPolska
View Post
Did not works. All the time it shows that there is no administrator.
I made this dialog thanks to Kwarde, are you using MySQL Database ?

Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)