Admins & Helper List help
#1

Hi, i've tried so many times to combine Admin & Helper list but i can't, it makes a random error when i try to combine and then compile it. i want to combine it just like:

when player do /admins

.::::: Administrators :::::.
Owner bla bla bla bla
Co-owner blablablabla
Basic admin blablabla

.::::: Helpers :::::.
Basic helper blablabla
Senior helper blabla bla

here's my code:

Код:
CMD:admins(playerid, params[])
{
	new string[128];
    if(PlayerInfo[playerid][pAdmin] >= 0) {
        SendClientMessageEx(playerid, COLOR_GRAD1, ".::::: Administrators :::::.");
        foreach(Player, i) {
            if(PlayerInfo[i][pAdmin] >= 2 && PlayerInfo[i][pAdmin] <= PlayerInfo[playerid][pAdmin]) {
                new sstring[128];
                new strFromFile[128];
                new month, day, year;
                new playern[MAX_PLAYER_NAME];
                GetPlayerName(i, playern, sizeof(playern));
                getdate(year, month, day);
                format(sstring,sizeof(sstring),"admins/rtokens/%s[%d'%d'%d]",playern,month,day,year);
                if(fexist(sstring)) {
                    new File: file = fopen(sstring, io_read);
                    if(file) {
                        fread(file, strFromFile);
                        fclose(file);
                        //rtoken = strval(strFromFile);
                    }
                }

                if(PlayerInfo[i][pAdminDuty] == 1)
                if(gPlayerLogged{playerid} != 0) {
                    if(PlayerInfo[i][pAdmin] == 1) {
                        format(string, sizeof(string), "- {99FF33}Junior Admin %s (ID: %d) (On-Duty)", GetPlayerNameEx(i),i);
                    }
                    else if(PlayerInfo[i][pAdmin] == 2) {
                        format(string, sizeof(string), "- {99FF33}Basic Admin %s (ID: %d) (On-Duty)", GetPlayerNameEx(i),i);
                    }
                    else if(PlayerInfo[i][pAdmin] == 3) {
                        format(string, sizeof(string), "- {99FF33}General Admin %s (ID: %d) (On-Duty))", GetPlayerNameEx(i),i);
                    }
                    else if(PlayerInfo[i][pAdmin] == 4) {
                        format(string, sizeof(string), "- {99FF33}Senior Admin %s (ID: %d) (On-Duty)", GetPlayerNameEx(i),i);
                    }
                    else if(PlayerInfo[i][pAdmin] == 5) {
                        format(string, sizeof(string), "- {99FF33}Lead Admin %s (ID: %d) (On-Duty)", GetPlayerNameEx(i),i);
                    }
                    else if(PlayerInfo[i][pAdmin] == 6) {
                        format(string, sizeof(string), "- {99FF33}Head Admin %s (ID: %d) (On-Duty)", GetPlayerNameEx(i),i);
                    }
                    else if(PlayerInfo[i][pAdmin] == 7) {
                        format(string, sizeof(string), "- {99FF33}Executive Admin %s (ID: %d) (On-Duty)", GetPlayerNameEx(i),i);
                    }
                    else if(PlayerInfo[i][pAdmin] == 8) {
                        format(string, sizeof(string), "- {99FF33}Server Manager %s (ID: %d) (On-Duty)", GetPlayerNameEx(i),i);
                    }
                    else if(PlayerInfo[i][pAdmin] == 9) {
                        format(string, sizeof(string), "- {99FF33}Co-Owner %s (ID: %d) (On-Duty)", GetPlayerNameEx(i),i);
                    }
                    else if(PlayerInfo[i][pAdmin] == 10) {
                        format(string, sizeof(string), "- {99FF33}Owner %s (ID: %d) (On-Duty)", GetPlayerNameEx(i),i);
                    }
                    else {
                        format(string, sizeof(string), "- Undefined Admin (ID: %d) %s", PlayerInfo[i][pAdmin], GetPlayerNameEx(i));
                    }
                }

		if(PlayerInfo[i][pAdminDuty] == 0)
                if(gPlayerLogged{playerid} != 0) {
                    if(PlayerInfo[i][pAdmin] == 1) {
                        format(string, sizeof(string), "- Junior Admin %s (ID: %d)", GetPlayerNameEx(i),i);
                    }
                    else if(PlayerInfo[i][pAdmin] == 2) {
                        format(string, sizeof(string), "- Basic Admin %s (ID: %d)", GetPlayerNameEx(i),i);
                    }
                    else if(PlayerInfo[i][pAdmin] == 3) {
                        format(string, sizeof(string), "- General Admin %s (ID: %d)", GetPlayerNameEx(i),i);
                    }
                    else if(PlayerInfo[i][pAdmin] == 4) {
                        format(string, sizeof(string), "- Senior Admin %s (ID: %d)", GetPlayerNameEx(i),i);
                    }
                    else if(PlayerInfo[i][pAdmin] == 5) {
                        format(string, sizeof(string), "- Lead Admin %s (ID: %d)", GetPlayerNameEx(i),i);
                    }
                    else if(PlayerInfo[i][pAdmin] == 6) {
                        format(string, sizeof(string), "- Head Admin %s (ID: %d)", GetPlayerNameEx(i),i);
                    }
                    else if(PlayerInfo[i][pAdmin] == 7) {
                        format(string, sizeof(string), "- Executive Admin %s (ID: %d)", GetPlayerNameEx(i),i);
                    }
                    else if(PlayerInfo[i][pAdmin] == 8) {
                        format(string, sizeof(string), "- Server Manager %s (ID: %d)", GetPlayerNameEx(i),i);
                    }
                    else if(PlayerInfo[i][pAdmin] == 9) {
                        format(string, sizeof(string), "- Co-Owner %s (ID: %d)", GetPlayerNameEx(i),i);
                    }
                    else if(PlayerInfo[i][pAdmin] == 10) {
                        format(string, sizeof(string), "- Owner %s (ID: %d)", GetPlayerNameEx(i),i);
                    }
                    else {
                        format(string, sizeof(string), "- Undefined Admin (ID: %d): %s", PlayerInfo[i][pAdmin], GetPlayerNameEx(i),i);
                    }
                }


                if(PlayerInfo[i][pBanAppealer]) strcat(string, " [BA]");
                if(PlayerInfo[i][pShopTech]) strcat(string, " [ST]");
                if(PlayerInfo[i][pBizMengm]) strcat(string, " [Biz]");
                if(PlayerInfo[i][pShopTech]) strcat(string, " [Honorary]");
                if(PlayerInfo[i][pBZ]) strcat(string, " [BZ]");
                if(PlayerInfo[i][pAP]) strcat(string, " [AP]");
                if(PlayerInfo[i][pPR]) strcat(string, " [PR]");
                if(PlayerInfo[i][pGmod] >= 1) strcat(string, " [GMOD]");
                if(PlayerInfo[i][pFmod] >= 1) strcat(string, " [FMOD]");
                if(PlayerInfo[i][pUndercover]) strcat(string, " [UC]");
                if(PlayerInfo[i][pTogReports]) strcat(string, " [SPEC MODE]");
                SendClientMessageEx(playerid, COLOR_GRAD2, string);
            }
        }
    }
    return 1;
}

CMD:helpers(playerid, params[])
{
	new string[128];
	if(gPlayerLogged{playerid} != 0) {
		SendClientMessageEx(playerid, COLOR_GRAD1, ".::::: Helpers :::::.");
		foreach(Player, i) {
			new sstring[128], rtokens = 0;
			new strFromFile[128];
			new month, day, year;
			new playern[MAX_PLAYER_NAME];
			GetPlayerName(i, playern, sizeof(playern));
			getdate(year, month, day);
			format(sstring,sizeof(sstring),"admins/catokens/%s[%d'%d'%d]",playern,month,day,year);
			if(fexist(sstring)) {
				new File: file = fopen(sstring, io_read);
				if(file) {
					fread(file, strFromFile);
					fclose(file);
					rtokens = strval(strFromFile);
				}
			}
			if(GetPVarInt(playerid, "HelperDuty") == 2)
			if(gPlayerLogged{playerid} != 0) {
				if(PlayerInfo[i][pHelper] == 1) {
					format(string, sizeof(string), "- {99FF33}Junior Helper %s (ID: %d) (On-Duty) (Help Requests Today: %d)", GetPlayerNameEx(i), i, rtokens);
				}
				else if(PlayerInfo[i][pHelper] == 2) {
					format(string, sizeof(string), "- {99FF33}Basic Helper %s (ID: %d) (On-Duty) (Help Requests Today: %d)", GetPlayerNameEx(i), i, rtokens);
				}
				else if(PlayerInfo[i][pHelper] == 3) {
					format(string, sizeof(string), "- {99FF33}Senior Helper %s (ID: %d) (On-Duty) (Help Requests Today: %d)", GetPlayerNameEx(i), i, rtokens);
				}
				else if(PlayerInfo[i][pHelper] >= 4) {
					format(string, sizeof(string), "- {99FF33}Head Helper %s (ID: %d) (On-Duty) (Help Requests Today: %d)", GetPlayerNameEx(i), i, rtokens);
				}
			}

			if(GetPVarInt(playerid, "HelperDuty") == 1)
			if(gPlayerLogged{playerid} != 0) {
  				if(PlayerInfo[i][pHelper] == 1) {
					format(string, sizeof(string), "- Junior Helper %s (ID: %d) (Help Requests Today: %d)", GetPlayerNameEx(i), i, rtokens);
				}
				else if(PlayerInfo[i][pHelper] == 2) {
					format(string, sizeof(string), "- Basic Helper %s (ID: %d) (Help Requests Today: %d)", GetPlayerNameEx(i), i, rtokens);
				}
				else if(PlayerInfo[i][pHelper] == 3) {
					format(string, sizeof(string), "- Senior Helper %s (ID: %d) (Help Requests Today: %d)", GetPlayerNameEx(i), i, rtokens);
				}
				else if(PlayerInfo[i][pHelper] >= 4) {
					format(string, sizeof(string), "- Head Helper %s (ID: %d) (Help Requests Today: %d)", GetPlayerNameEx(i), i, rtokens);
				}
				SendClientMessageEx(playerid, COLOR_GRAD2, string);
			}
		}
	}
	return 1;
}
So players no need to do /helpers if them want to see admins & helpers online.

can someone help me with that? dont worry about rep+ and big thanks from me.

thanks and sorry for my broken english.
Reply
#2

I have been trying to optimize your code and combine the two functions, but one thing I can't get my head around is this line:
Код:
// Line 7 in the script
if(PlayerInfo[i][pAdmin] >= 2 && PlayerInfo[i][pAdmin] <= PlayerInfo[playerid][pAdmin]) {
Because, later on you are calling PlayerInfo[i][pAdmin] == 1. So.. do you, or do you not want them shown? And I take it, you only want to show the admins with a level lower than the callers'?
Reply
#3

Quote:
Originally Posted by mamorunl
Посмотреть сообщение
I have been trying to optimize your code and combine the two functions, but one thing I can't get my head around is this line:
Код:
// Line 7 in the script
if(PlayerInfo[i][pAdmin] >= 2 && PlayerInfo[i][pAdmin] <= PlayerInfo[playerid][pAdmin]) {
Because, later on you are calling PlayerInfo[i][pAdmin] == 1. So.. do you, or do you not want them shown? And I take it, you only want to show the admins with a level lower than the callers'?
So if i want them shown i should change

Код:
if(PlayerInfo[i][pAdmin] >= 2 && PlayerInfo[i][pAdmin] <= PlayerInfo[playerid][pAdmin]) {
To:

Код:
if(PlayerInfo[i][pAdmin] >= 1 && PlayerInfo[i][pAdmin] <= PlayerInfo[playerid][pAdmin]) {
Like that?because i realized if(PlayerInfo[i][pAdmin] == 1) will not shown the level 1 admin (Junior Admin) right?if i didn't change it.

Quote:

And I take it, you only want to show the admins with a level lower than the callers'?

Yes you're right but can you make it to show the admins with a level higher and the helpers too? thank you
Reply
#4

Alright, then this code should work:
Код:
CMD:admins(playerid, params[])
{
	new string[128];
    if(PlayerInfo[playerid][pAdmin] == 0) return 0; // Block users that are not admin to load this function
	
	SendClientMessageEx(playerid, COLOR_GRAD1, ".::::: Administrators :::::.");
	foreach(Player, i) {
		if(PlayerInfo[i][pAdmin] > 0) {
			new sstring[128];
			new strFromFile[128];
			new month, day, year;
			new playern[MAX_PLAYER_NAME];
			GetPlayerName(i, playern, sizeof(playern));
			getdate(year, month, day);
			format(sstring,sizeof(sstring),"admins/rtokens/%s[%d'%d'%d]",playern,month,day,year);
			if(fexist(sstring)) {
				new File: file = fopen(sstring, io_read);
				if(file) {
					fread(file, strFromFile);
					fclose(file);
					//rtoken = strval(strFromFile);
				}
			}
			
			new rank[64];
			switch(PlayerInfo[i][pAdmin]) {
				case 1: rank = "Junior Admin";
				case 2: rank = "Basic Admin";
				case 3: rank = "General Admin";
				case 4: rank = "Senior Admin";
				case 5: rank = "Lead Admin";
				case 6: rank = "Head Admin";
				case 7: rank = "Executive Admin";
				case 8: rank = "Server Manager";
				case 9: rank = "Co-Owner";
				case 10: rank = "Owner";
				default: "Undefined Admin";
			}
			
			format(string, sizeof(string), "- {99FF33}%s %s (ID: %d) %s", rank, GetPlayerNameEx(i), i, (PlayerInfo[i][pAdminDuty] == 1 ? "(On-Duty)" : ""));

			if(PlayerInfo[i][pBanAppealer]) strcat(string, " [BA]");
			if(PlayerInfo[i][pShopTech]) strcat(string, " [ST]");
			if(PlayerInfo[i][pBizMengm]) strcat(string, " [Biz]");
			if(PlayerInfo[i][pShopTech]) strcat(string, " [Honorary]");
			if(PlayerInfo[i][pBZ]) strcat(string, " [BZ]");
			if(PlayerInfo[i][pAP]) strcat(string, " [AP]");
			if(PlayerInfo[i][pPR]) strcat(string, " [PR]");
			if(PlayerInfo[i][pGmod] >= 1) strcat(string, " [GMOD]");
			if(PlayerInfo[i][pFmod] >= 1) strcat(string, " [FMOD]");
			if(PlayerInfo[i][pUndercover]) strcat(string, " [UC]");
			if(PlayerInfo[i][pTogReports]) strcat(string, " [SPEC MODE]");
			SendClientMessageEx(playerid, COLOR_GRAD2, string);
		}
	}
	
	SendClientMessageEx(playerid, COLOR_GRAD1, " ");
	SendClientMessageEx(playerid, COLOR_GRAD1, ".::::: Helpers :::::.");
	foreach(Player, i) {
		if(PlayerInfo[i][pAdmin] > 0) {
			new sstring[128];
			new strFromFile[128];
			new month, day, year;
			new playern[MAX_PLAYER_NAME];
			GetPlayerName(i, playern, sizeof(playern));
			getdate(year, month, day);
			format(sstring,sizeof(sstring),"admins/catokens/%s[%d'%d'%d]",playern,month,day,year);
			if(fexist(sstring)) {
				new File: file = fopen(sstring, io_read);
				if(file) {
					fread(file, strFromFile);
					fclose(file);
					rtokens = strval(strFromFile);
				}
			}
			
			new rank[64];
			switch(PlayerInfo[i][pHelper]) {
				case 1: rank = "Junior Helper";
				case 2: rank = "Basic Helper";
				case 3: rank = "Senior Helper";
				case 4: rank = "Head Helper";
				default: "Undefined Helper";
			}
			
			format(string, sizeof(string), "- {99FF33}%s %s (ID: %d) %s (Help Requests Today: %d)", rank, GetPlayerNameEx(i), i, (GetPVarInt(i, "HelperDuty") == 2 ? "(On-Duty)" : ""), rtokens);
			SendClientMessageEx(playerid, COLOR_GRAD2, string);
		}
	}
	
    return 1;
}
I am a bit rusty, but it shouldn't give any problems If there are they are probably easy to fix.
Reply
#5

It gives me

Код:
D:\Exodus\Files\gamemodes\CIDNRP.pwn(39446) : error 001: expected token: "-string end-", but found "-identifier-"
D:\Exodus\Files\gamemodes\CIDNRP.pwn(39492) : error 001: expected token: "-string end-", but found "-identifier-"
At this

Код:
format(string, sizeof(string), "- {99FF33}%s %s (ID: %d) %s", rank, GetPlayerNameEx(i), i, (PlayerInfo[i][pAdminDuty] == 1 ? "(On-Duty)" : ""));
and this

Код:
format(string, sizeof(string), "- {99FF33}%s %s (ID: %d) %s (Help Requests Today: %d)", rank, GetPlayerNameEx(i), i, (GetPVarInt(i, "HelperDuty") == 2 ? "(On-Duty)" : ""), rtokens);
Reply
#6

Alright. So apparently my shorthand Notation is wrong or pawn doesn't support it. Instead do this:
Код:
new duty[26];
if(PlayerInfo[i][pAdminDuty] == 1) {
 duty = "(On-Duty)";
} else {
 duty = "";
}
format(string, sizeof(string), "- {99FF33}%s %s (ID: %d) %s", rank, GetPlayerNameEx(i), i, duty);
Код:
if(GetPVarInt(i, "HelperDuty") == 2) {
 duty = "(On-Duty)";
} else {
 duty = "";
}
format(string, sizeof(string), "- {99FF33}%s %s (ID: %d) %s (Help Requests Today: %d)", rank, GetPlayerNameEx(i), i, duty, rtokens);
Reply
#7

That's a compiler bug, replace these two:
pawn Код:
(PlayerInfo[i][pAdminDuty] == 1 ? "(On-Duty)" : "")
(GetPVarInt(i, "HelperDuty") == 2 ? "(On-Duty)" : "")
with:
pawn Код:
PlayerInfo[i][pAdminDuty] ? ("(On-Duty)") : ("")
GetPVarInt(i, "HelperDuty") == 2 ? ("(On-Duty)") : ("")
and consider changing that PVar to an array.

By the way, if you are not going to use rtoken at all then remove all that part because there isn't any reason of opening a file and reading from it without any action afterwards.

One last thing: declare any variable outside of the loop.
Reply
#8

Thank you so much for both of you, i'll give you both rep+ when my post reach minimal to give rep. don't worry i'll remember it .
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)