asay command doubled message
#1

I've made a simple asay command that should be sent globally to everyone and have a color depending on the admin level.Level 1 admin has a blue colors, level 2 has red and level 3 has green.The problem is when i do /asay with multiple admins ingame, for example 2 it sends the message twice with different colors since he was lvl 2 and i was lvl 3.
CMD:
Код:
CMD:asay(playerid,params[])
{
	if(PlayerInfo[playerid][pAdmin] == 0) return SendClientMessage(playerid,COLOR_ERROR,"Error: {FFFFFF}Unknown command, type /cmds for the list of commands.");
	else
	{
		new text[200];
		if(sscanf(params,"s[200]",text)) return SendClientMessage(playerid,COLOR_GRAY,"Syntax: /asay [message]");
		format(text,sizeof(text),"Admin: %s",text);
		SendMessageToPlayers(text);
	}
	return 1;
}
Stock:
Код:
stock SendMessageToPlayers(text[])
{
	for(new i = 0; i < MAX_PLAYERS; i++)
	{
	if(PlayerInfo[i][pAdmin] == 1)
	{
		SendClientMessageToAll(COLOR_LEVEL1,text);
	}
	else if(PlayerInfo[i][pAdmin] == 2)
	{
  		SendClientMessageToAll(COLOR_LEVEL2,text);
	}
	else if(PlayerInfo[i][pAdmin] == 3)
	{
		SendClientMessageToAll(COLOR_LEVEL3,text);
	}
	}
	return 1;
}
Reply
#2

ofc that will happen because you are looping all the online players and checking who are admin lol. Remove the loop/break; it after sending the message.
Reply
#3

try this maybe will help
Код:
stock SendMessageToPlayers(text[])
{
	for(new i = 0; i < MAX_PLAYERS; i++)
	{
	if(PlayerInfo[i][pAdmin] == 1)
	{
		SendClientMessage(i, COLOR_LEVEL1,text);
	}
	else if(PlayerInfo[i][pAdmin] == 2)
	{
  		SendClientMessage(i, COLOR_LEVEL2,text);
	}
	else if(PlayerInfo[i][pAdmin] == 3)
	{
		SendClientMessage(i, COLOR_LEVEL3,text);
	}
	}
	return 1;
}
Reply
#4

Why do you need a loop? Is a single message sented by a single person. Check his admin level and send it as it should be. I dont see the point checking all the players admin level to send a message from one single person

Edit: Dont use the code from the person above, it will only send to admins
Reply
#5

Quote:
Originally Posted by Slawi
Посмотреть сообщение
try this maybe will help
Код:
stock SendMessageToPlayers(text[])
{
	for(new i = 0; i < MAX_PLAYERS; i++)
	{
	if(PlayerInfo[i][pAdmin] == 1)
	{
		SendClientMessage(i, COLOR_LEVEL1,text);
	}
	else if(PlayerInfo[i][pAdmin] == 2)
	{
  		SendClientMessage(i, COLOR_LEVEL2,text);
	}
	else if(PlayerInfo[i][pAdmin] == 3)
	{
		SendClientMessage(i, COLOR_LEVEL3,text);
	}
	}
	return 1;
}
I assume its only gonna send messages to admins, this should send the message to everyone.
Reply
#6

Quote:
Originally Posted by Mike861
Посмотреть сообщение
I assume its only gonna send messages to admins, this should send the message to everyone.
PHP код:
SendMessageToPlayers(text[])
{
    for(new 
0MAX_PLAYERSi++)
    {
        if(
PlayerInfo[i][pAdmin] < 1//if not admin
        
{
            
SendClientMessage(i, -1,text); //send message in white (-1) change the color to you'rs
        
}
        if(
PlayerInfo[i][pAdmin] == 1)
        {
            
SendClientMessage(iCOLOR_LEVEL1,text);
        }
        else if(
PlayerInfo[i][pAdmin] == 2)
        {
              
SendClientMessage(iCOLOR_LEVEL2,text);
        }
        else if(
PlayerInfo[i][pAdmin] == 3)
        {
            
SendClientMessage(iCOLOR_LEVEL3,text);
        }
    }
    return 
1;

Reply
#7

The color will depend on the level of the admin who executes the command? If yes, it is true that you do not need a loop. For only 1 parameter that is string, use isnull macro- no need for sscanf.
Max client message is 144 characters.
pawn Код:
CMD:asay(playerid, params[])
{
    if (PlayerInfo[playerid][pAdmin] == 0) return SendClientMessage(playerid, COLOR_ERROR, "Error: {FFFFFF}Unknown command, type /cmds for the list of commands.");
    if (isnull(params)) return SendClientMessage(playerid, COLOR_GRAY, "Syntax: /asay [message]");

    new text[145], color_of_text;

    switch (PlayerInfo[playerid][pAdmin])
    {
        case 1: color_of_text = COLOR_LEVEL1;
        case 2: color_of_text = COLOR_LEVEL2;
        case 3: color_of_text = COLOR_LEVEL3;
    }

    format(text, sizeof (text), "Admin: %s", params);
    SendClientMessageToAll(color_of_text, text);
    return 1;
}
Reply
#8

Quote:
Originally Posted by Mike861
Посмотреть сообщение
I assume its only gonna send messages to admins, this should send the message to everyone.
yes you right
i was think that he want the message show only for admins
Reply
#9

Quote:
Originally Posted by Calisthenics
Посмотреть сообщение
The color will depend on the level of the admin who executes the command? If yes, it is true that you do not need a loop. For only 1 parameter that is string, use isnull macro- no need for sscanf.
Max client message is 144 characters.
pawn Код:
CMD:asay(playerid, params[])
{
    if (PlayerInfo[playerid][pAdmin] == 0) return SendClientMessage(playerid, COLOR_ERROR, "Error: {FFFFFF}Unknown command, type /cmds for the list of commands.");
    if (isnull(params)) return SendClientMessage(playerid, COLOR_GRAY, "Syntax: /asay [message]");

    new text[145], color_of_text;

    switch (PlayerInfo[playerid][pAdmin])
    {
        case 1: color_of_text = COLOR_LEVEL1;
        case 2: color_of_text = COLOR_LEVEL2;
        case 3: color_of_text = COLOR_LEVEL3;
    }

    format(text, sizeof (text), "Admin: %s", params);
    SendClientMessageToAll(color_of_text, text);
    return 1;
}
Thanks, + rep.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)