SA-MP Forums Archive
SendClientMessage with variable state? - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: SendClientMessage with variable state? (/showthread.php?tid=426904)



SendClientMessage with variable state? - Morten_Guado - 30.03.2013

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.


Re: SendClientMessage with variable state? - Basssiiie - 30.03.2013

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


Re: SendClientMessage with variable state? - kamzaf - 30.03.2013

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.


Re: SendClientMessage with variable state? - Harti - 30.03.2013

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;
}



Re: SendClientMessage with variable state? - Morten_Guado - 30.03.2013

Oh, my mistake!

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