SendClientMessage with variable state?
#1

Hi, I'm trying to make a command which sends me a message with all players with a variable on state true.

This is how my code looks:

Код:
if(strcmp(cmdtext,"/seeplayers",true) == 0)
{
	for(new i = 0; i <= MAX_PLAYERS; i++)
	{
	if(InEvent[i] == 1)//My variable
   	{
    	        new name[MAX_PLAYER_NAME], string[50+MAX_PLAYER_NAME];
		GetPlayerName(i, name, sizeof(name));
		format(string, sizeof(string), "%s", name);
		SendClientMessage(playerid, WHITE, string);
	}
  	}
   return 1;
}
But It's just sending empty messages.
Any help would be appreciated.

Thanks in advance.
Reply
#2

Check if the player is online using IsPlayerConnected(i), else it will probably print empty names for all the offline IDs.
Reply
#3

you could use IsPlayerConnected or you could simply add foreach and it automatically checks if the player is online or not + more faster and less memory consuming.
Reply
#4

If you want a better and cleaner code you should use foreach from the YSI y_iterate include.

pawn Код:
#include <YSI\y_iterate>

if(strcmp(cmdtext,"/seeplayers",true) == 0)
{
    foreach(Player, i) {
        if(InEvent[i] == 1)//My variable
        {
            new name[MAX_PLAYER_NAME], string[50+MAX_PLAYER_NAME];
            GetPlayerName(i, name, sizeof(name));
            format(string, sizeof(string), "%s", name);
            SendClientMessage(playerid, WHITE, string);
        }
    }
    return 1;
}
Reply
#5

Oh, my mistake!

It's working now.
Thanks a lot, guys!
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)