SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Scripting Help

Reply
 
Thread Tools Display Modes
Old 27/06/2020, 03:31 PM   #1
KamilPolska
Huge Clucker
 
Join Date: May 2016
Location: Poland
Posts: 494
Reputation: 5
Default Help /admins

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.

KamilPolska is offline   Reply With Quote
Old 27/06/2020, 03:39 PM   #2
ilogbc
Little Clucker
 
Join Date: Mar 2020
Location: Germany
Posts: 11
Reputation: 0
Default Re: Help /admins

use https://wiki.sa-mp.com/wiki/Strcat
ilogbc is offline   Reply With Quote
Old 27/06/2020, 03:44 PM   #3
Lexless
Little Clucker
 
Join Date: May 2020
Posts: 38
Reputation: 14
Default Re: Help /admins

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;
}
Lexless is offline   Reply With Quote
Old 28/06/2020, 01:28 PM   #4
KamilPolska
Huge Clucker
 
Join Date: May 2016
Location: Poland
Posts: 494
Reputation: 5
Default Re: Help /admins

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;
}
KamilPolska is offline   Reply With Quote
Old 28/06/2020, 03:13 PM   #5
Kwarde
High-roller
 
Kwarde's Avatar
 
Join Date: Nov 2009
Location: The Netherlands
Posts: 2,735
Reputation: 1686
Default Re: Help /admins

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).
__________________
When the opportunity presents itself to flip-a da table, uh, you flip-a da table.

Discord: Kwarde#8009
Kwarde is offline   Reply With Quote
Old 28/06/2020, 05:55 PM   #6
KamilPolska
Huge Clucker
 
Join Date: May 2016
Location: Poland
Posts: 494
Reputation: 5
Default Re: Help /admins

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;
}
KamilPolska is offline   Reply With Quote
Old 28/06/2020, 06:13 PM   #7
Kwarde
High-roller
 
Kwarde's Avatar
 
Join Date: Nov 2009
Location: The Netherlands
Posts: 2,735
Reputation: 1686
Default Re: Help /admins

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.
__________________
When the opportunity presents itself to flip-a da table, uh, you flip-a da table.

Discord: Kwarde#8009
Kwarde is offline   Reply With Quote
Old 28/06/2020, 06:47 PM   #8
Chams
Big Clucker
 
Chams's Avatar
 
Join Date: May 2017
Location: United States
Posts: 81
Reputation: 10
Default Re: Help /admins

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
Chams is offline   Reply With Quote
Old 05/07/2020, 05:39 PM   #9
KamilPolska
Huge Clucker
 
Join Date: May 2016
Location: Poland
Posts: 494
Reputation: 5
Default Re: Help /admins

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.
KamilPolska is offline   Reply With Quote
Old 09/07/2020, 11:13 AM   #10
DarkMaster
Little Clucker
 
Join Date: Jun 2020
Posts: 17
Reputation: 2
Default Re: Help /admins

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 ?

DarkMaster is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How do I make this cmd work for both non-admins and admins but in a different way? In Pawn.CMD aKnoxx Scripting Help 2 02/05/2019 05:19 PM
PlayerPlaySound to admins when new report is up. and level 4 admins can read it only zrelly Scripting Help 12 07/09/2013 09:26 AM
Making it work both Admins and Rcon Admins JaKe Elite Scripting Help 7 31/05/2012 12:57 PM
/admins dialog Total online admins do help:( y@sin1 Scripting Help 10 14/01/2012 03:58 PM
[HELP]/admins <Show current admins online by ID, Name, Rank and Duty> Deal-or-die Help Archive 7 01/06/2011 11:00 AM


All times are GMT. The time now is 03:32 AM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.