21.12.2019, 13:14
(
Last edited by l0gic; 21/12/2019 at 02:08 PM.
)
Start using foreach, makes loop writing much easier and efficent.
You may use server administrator rank names other places also, so you can define it globally.
You can also store players name into array, so you don't have to use GetPlayerName every time you want to use it.
Define dialog ID's with name, so in the future you will understand also, what have you written together or start using easyDialog, so everything related with dialogs can be in one place.
Every command doesn't need check if player is logged in.
Example code of checking if player is logged in or not, it depends what command processor you are using.
You may use server administrator rank names other places also, so you can define it globally.
You can also store players name into array, so you don't have to use GetPlayerName every time you want to use it.
Define dialog ID's with name, so in the future you will understand also, what have you written together or start using easyDialog, so everything related with dialogs can be in one place.
Every command doesn't need check if player is logged in.
Example code of checking if player is logged in or not, it depends what command processor you are using.
PHP Code:
public OnPlayerCommandReceived(playerid, cmd[], params[], flags){
if(!PlayerInfo[playerid][LoggedIn])return SendClientMessage(playerid, -1, "You must be logged in!"), 0;
return 1;
}
PHP Code:
#include <YSI_Data\y_iterate> //iterating through arrays
enum{
DIALOG_STAFF
};
static const aRankNames[][40]={
"",
"{FFFF00}Moderator",
"{008000}Administrator",
"{3366FF}Manager",
"{FF0000}RCON Admin"
};
getAdminRank(pid){
if(IsPlayerAdmin(pid)) return (sizeof(aRankNames) - 1);
return PlayerInfo[pid][AdminLevel];
}
getNameWithID(pid){
new s[32];
format(s, 32, "%s[%d]", PlayerData[pid][Name], pid);
return s;
}
CMD:staff(pid){
new rank,
bs[500];
foreach(new i : Player){
if(!(rank=getAdminRank(i)))continue;
format(bs, sizeof(bs), "%s%s | %s\n", bs, getNameWithID(i), aRankNames[rank]);
}
if(!strlen(bs))
return SendClientMessage(pid, -1, "No staff online!");
ShowPlayerDialog(pid, DIALOG_STAFF, DIALOG_STYLE_MSGBOX, "Server staff", bs, "Okay", "");
return 1;
}