27.05.2016, 20:21
Let's optimize it, shall we?
- foreach is recommended for player loops, if you don't want to use it then use atleast GetPlayerPoolSize.
- switch is faster than many if statements
- in order to send a message that no admins are online the loop MUST finish first.
- NEVER use return in loops unless you want to stop them
- foreach is recommended for player loops, if you don't want to use it then use atleast GetPlayerPoolSize.
- switch is faster than many if statements
- in order to send a message that no admins are online the loop MUST finish first.
- NEVER use return in loops unless you want to stop them
PHP код:
CMD:admins(playerid, params[])
{
new sendername[MAX_PLAYER_NAME], string[128], count;
SCM(pid, -1, "{FF6600}Online {FFFFFF}Admins");
for (new i = 0, j = GetPlayerPoolSize(); i <= j; i++) // foreach(new i : Player)
{
if (!IsPlayerConnected(i)) continue;
GetPlayerName(i, sendername, sizeof(sendername));
switch (Player[i][pAdmin])
{
case 1338: format(string, sizeof(string), "Server Founder: {FF0000}%s", sendername);
case 1337: format(string, sizeof(string), "Server Manager: {A31818}%s", sendername);
case 5: format(string, sizeof(string), "Server Mapper: {0080FF}%s", sendername);
case 4: format(string, sizeof(string), "Leader Coordinator: {6633CC}%s", sendername);
case 3: format(string, sizeof(string), "Server Guardian: {A173FF}%s", sendername);
case 2: format(string, sizeof(string), "Server Moderator: {5CFEADFF}%s", sendername);
case 1: format(string, sizeof(string), "Trial Admin: {94FEC9FF}%s", sendername);
}
SCM(pid, -1, string);
count++;
}
if (!count) SCM(pid, -1, "{08FC9A}There are no admins online.");
return 1;
}