22.05.2016, 14:18
Then keep that script since you understand it properly but optimize it.
strtok and ReturnUser are very old and slow methods. sscanf is what you need!
"r" specifier is for "ID/Part Of Name" to players only ("u" includes NPCs too).
Assuming giveplayer, sendername and string have been declared in OnPlayerCommandText callback and they're not globals (I've them as local).
Last, but that's personal opinion only - having up to 1338 admin level is a bit ridiculous. 1-5 or even 1-10 seems acceptable.
strtok and ReturnUser are very old and slow methods. sscanf is what you need!
"r" specifier is for "ID/Part Of Name" to players only ("u" includes NPCs too).
Assuming giveplayer, sendername and string have been declared in OnPlayerCommandText callback and they're not globals (I've them as local).
Last, but that's personal opinion only - having up to 1338 admin level is a bit ridiculous. 1-5 or even 1-10 seems acceptable.
PHP код:
CMD:makeadmin(playerid, params[])
{
if (!PlayerInfo[playerid][pAdmin] && !IsPlayerAdmin(playerid)) return SendClientMessage(playerid, COLOR_GRAD1, "{09F7DF}DENIED: {ffffff}No access");
new para1, level;
if (sscanf(params, "ri", para1, level)) return SendClientMessage(playerid, COLOR_GRAD2, "{00E6FF}UTILIZARE:{FFFFFF} /makeadmin [IDJucator/ParteDinNume] [level(1-1338)]");
if (para1 == INVALID_PLAYER_ID) return SendClientMessage(playerid, COLOR_GRAD1, "Invalid player");
if (!(1 <= level <= 1338)) return SendClientMessage(playerid, COLOR_GRAD1, "Invalid level. It must be between 1 and 1338");
new giveplayer[MAX_PLAYER_NAME], sendername[MAX_PLAYER_NAME], string[144];
GetPlayerName(para1, giveplayer, sizeof(giveplayer));
GetPlayerName(playerid, sendername, sizeof(sendername));
PlayerInfo[para1][pAdmin] = level;
printf("AdmWarning: %s has promoted %s to a level %d admin.", sendername, giveplayer, level);
format(string, sizeof(string), " You have been promoted to a level %d admin by %s", level, sendername);
SendClientMessage(para1, COLOR_LIGHTBLUE, string);
format(string, 128, "{D11515}[AdmWarning]: {FF9203}%s {FFFFFF}has set {FF9203}%s {FFFFFF}to a level {FF9203}%d {FFFFFF}admin.", sendername, giveplayer, level);
ABroadCast(COLOR_YELLOW, string, 5);
return 1;
}