25.11.2013, 18:26
May I improve few things?
Declare variables when they're about to be used. In a case that it will return an error about the usage, we simply declared those arrays with no reason!
Commands such as this one with only text as parameter (1 parameter only) can be used with params (and isnull for the usage (error message)). By that, we get rid of an array with size of 100!
The normal method of for loop is slow in case not many players are online. It's much better to use foreach so you gain much speed!
The last one is about format. You used it inside the for loop so it will basically formats the same message over and over again. It's better to post it before the loop!
So the final result:
PS: Good tutorial!
Declare variables when they're about to be used. In a case that it will return an error about the usage, we simply declared those arrays with no reason!
Commands such as this one with only text as parameter (1 parameter only) can be used with params (and isnull for the usage (error message)). By that, we get rid of an array with size of 100!
The normal method of for loop is slow in case not many players are online. It's much better to use foreach so you gain much speed!
The last one is about format. You used it inside the for loop so it will basically formats the same message over and over again. It's better to post it before the loop!
So the final result:
pawn Code:
CMD:rconchat(playerid, params[])
{
if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid, 0xFFFFFFFF, "You are not an RCON admin.");
if(isnull(params)) return SendClientMessage(playerid, 0xFFFFFFFF, "Correct usage: /rconchat [text]");
new string[144], AdminName[MAX_PLAYER_NAME];
GetPlayerName(playerid, AdminName, sizeof(AdminName));
format(string, sizeof(string), "RCON CHAT: %s said: %s", AdminName, params);
foreach(new i : Player) if(IsPlayerAdmin(i)) SendClientMessage(i, 0xFFFFFFFF, string);
return 1;
}