will this ever work? is there a way to fix it?
#1

hello. is there a way to fix this code? is it fixable or is it impossible

Код:
stock SendAdminMessage(Message[])
	for(new i; i<MAX_PLAYERS; i++) {
	  if(IsPlayerAdmin(i)) {
			new name[MAX_PLAYER_NAME];
            new string[256];
			GetPlayerName(i, name, sizeof(name));
			format(string, sizeof(string), "%s used command: %s", name, Message);
			SendClientMessage(i,LIGHTBLUE, string);
			return 1; } }
Edit: i get 1 warning:

Код:
C:\SAMPSE~1\FILTER~1\manhunt.pwn(91) : warning 209: function "SendAdminMessage" should return a value
Pawn compiler 3.2.3664	 	 	Copyright © 1997-2006, ITB CompuPhase


1 Warning.
Reply
#2

pawn Код:
stock SendAdminMessage(Message[])
{
    for(new i; i<MAX_PLAYERS; i++)
    {
      if(IsPlayerAdmin(i))
        {
            new name[MAX_PLAYER_NAME];
            new string[256];
            GetPlayerName(i, name, sizeof(name));
            format(string, sizeof(string), "%s used command: %s", name, Message);
            SendClientMessage(i,LIGHTBLUE, string);
        }
    }
    return 1;
}
Reply
#3

The string doesn't need to be of size 256, as the maximum you'll ever output is 128. Also it would be a better idea to keep the declarations outside the function to save them being re-allocated each time.

Example:

pawn Код:
new name[MAX_PLAYER_NAME], string[128];

stock SendAdminMessage(Message[])
{
    for(new i; i<MAX_PLAYERS; i++)
    {
        if(IsPlayerAdmin(i))
        {
            GetPlayerName(i, name, sizeof(name));
            format(string, sizeof(string), "%s used command: %s", name, Message);
            SendClientMessage(i,LIGHTBLUE, string);
        }
    }
    return 1;
}
Reply
#4

thnx a lot
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)