message multiple
#1

Код:
CMD:warn(playerid, params[])
{
	if(PlayerInfo[playerid][pAdmin] == 0)
		return SendClientMessage(playerid, COLOR_RED, "ERROR: Insufficient Permissions!");
		
	new PID, str[128], reason[64], name[MAX_PLAYER_NAME], Adminname[MAX_PLAYER_NAME];
	if(sscanf(params, "us[64]", PID,reason))
		return SendClientMessage(playerid, COLOR_LIGHTGREEN, "Usage: /Warn [playerid] [reason]");

	if(!IsPlayerConnected(PID))
		return SendClientMessage(playerid, COLOR_RED, "Player is not connected!");

	playerWarn[PID] ++;
	GetPlayerName(playerid, Adminname, sizeof(Adminname));
	GetPlayerName(PID, name, sizeof(name));
	format(str, sizeof str, "Admin %s has warned %s, Reason: %s. [Warning %i/3]", Adminname, PID, reason, playerWarn[PID]);
	SendClientMessageToAll(COLOR_RED, str);
	format(str, sizeof str, "Admin %s has warned %s, Reason: %s. [Warning %i/3]", Adminname, PID, reason, playerWarn[PID]);
	SendClientMessageToAll(COLOR_RED, str);
	if(playerWarn[PID] > 2)
	{
		format(str, sizeof str, "%s has been kicked by server 3 warnings, Reason [%s].", name, reason);
			SendClientMessageToAll(COLOR_RED, str);
			SendClientMessage(PID, COLOR_RED, "You were warned three times and got kicked!");
		Kick(PID);
	}
	return 1;
}
Hey, the command works just fine and compiling as well but I'm getting a multiple message like :

Admin %s has warned %s, Reason: %s. [Warning %i/3]
Admin %s has warned %s, Reason: %s. [Warning %i/3]

Or:

%s has been kicked by server 3 warnings, Reason [%s]
%s has been kicked by server 3 warnings, Reason [%s]

I need to put the 'ClientMessage' out of the loop, anyone knows how?
Reply
#2

Not sure what you're asking if you could rephrase it but:

PID isn't a string. You're doing:
PHP код:
GetPlayerName(PIDnamesizeof(name)); 
but you aren't actually using name but PID instead.

Код:
format(str, sizeof str, "Admin %s has warned %s, Reason: %s. [Warning %i/3]", Adminname, PID, reason, playerWarn[PID]);
Replace it with "name".
Reply
#3

Quote:
Originally Posted by Arthur Kane
Посмотреть сообщение
Not sure what you're asking if you could rephrase it but:

PID isn't a string. You're doing:
PHP код:
GetPlayerName(PIDnamesizeof(name)); 
but you aren't actually using name but PID instead.

Код:
format(str, sizeof str, "Admin %s has warned %s, Reason: %s. [Warning %i/3]", Adminname, PID, reason, playerWarn[PID]);
Replace it with "name".
That isn't the problem here,

Let me show you that with an image:

https://imgur.com/a/C3SDX
Reply
#4

Here you are, +1 REP if I helped
PHP код:
CMD:warn(playeridparams[])
{
    if(
PlayerInfo[playerid][pAdmin] == 0)
        return 
SendClientMessage(playeridCOLOR_RED"ERROR: Insufficient Permissions!");
    new 
PIDstr[128], reason[64], name[MAX_PLAYER_NAME], Adminname[MAX_PLAYER_NAME];
    if(
sscanf(params"us[64]"PID,reason))
        return 
SendClientMessage(playeridCOLOR_LIGHTGREEN"Usage: /Warn [playerid] [reason]");
    if(!
IsPlayerConnected(PID))
        return 
SendClientMessage(playeridCOLOR_RED"Player is not connected!");
    
playerWarn[PID] ++;
    
GetPlayerName(playeridAdminnamesizeof(Adminname));
    
GetPlayerName(PIDnamesizeof(name));
    
format(strsizeof str"Admin %s has warned %s, Reason: %s. [Warning %i/3]"AdminnamePIDreasonplayerWarn[PID]);
    
SendClientMessageToAll(COLOR_REDstr);
    if(
playerWarn[PID] > 2)
    {
        
format(strsizeof str"%s has been kicked by server 3 warnings, Reason [%s]."namereason);
            
SendClientMessageToAll(COLOR_REDstr);
            
SendClientMessage(PIDCOLOR_RED"You were warned three times and got kicked!");
        
Kick(PID);
    }
    return 
1;

Reply
#5

Actually look at your code, you have 2 copies of it pretty sure it will duplicate.
Reply
#6

It's normal, you are sending the message to all once and then to the warned player again.

Add this at top of your script:

pawn Код:
stock SendClientMessageToAllEx(exception, color, const message[])
{
  for(new i; i<MAX_PLAYERS; i++)
  {
    if(IsPlayerConnected(i))
    {
      if(i != exception)
      {
        SendClientMessage(i, color, message);
      }
    }
  }
}
Then remove the line which sends the message to PID.
And change SendClientMessageToAll with SendMessageToAllEx with PID as first parameter
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)