27.06.2020, 15:31
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.
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;
}
#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; }
Why after entering /semi1 does not appear to me that I am a semi-administrator? |
- 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 |
#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; }
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;
}
This is how I would do it:
pawn Code:
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. |