/w command
#1

okay so i made my first whisper command
and when i use it, it sends the message to all players and not those who are near them

here is my code
pawn Код:
CMD:w(playerid,params[])
{
    new string[128];
    for(new i = 0; i < MAX_PLAYERS; i++)
    {
        if(sscanf(params,"s[128]",params))
        {
           SendClientMessage(playerid,COLOR_ERROR,"USAGE: /w (Message)");
           return 1;
        }
        if(PlayerToPlayer(playerid, i, 10))
        {
           format(string,sizeof(string),"%s(%d) whispered : %s",GetName(playerid),playerid,params);
           SendClientMessageToAll(COLOR_PURPLE,string);
           return 1;
        }
    }
    return 1;
}
Reply
#2

Of course it sends it to all if you are using
pawn Код:
SendClientMessageToAll(COLOR_PURPLE,string);
Try
pawn Код:
SendClientMessage(i,COLOR_PURPLE,string);
Reply
#3

pawn Код:
CMD:w(playerid,params[])
{
    new string[128];
    for(new i = 0; i < MAX_PLAYERS; i++)
    {
        if(sscanf(params,"s[128]",params)) return SendClientMessage(playerid,COLOR_ERROR,"USAGE: /w (Message)");
        if(PlayerToPlayer(playerid, i, < 10))
        {
           format(string,sizeof(string),"%s(%d) whispered : %s",GetName(playerid),playerid,params);
           SendClientMessage(i,COLOR_PURPLE,string);
           return 1;
        }
    }
    return 1;
}
Try this. Not familiar with your functions.
Reply
#4

pawn Код:
CMD:w(playerid, params[]) {
    new
        szMessage[128];

    if(isnull(params) || strlen(params) > 128) // No need to use sscanf, it's just 1 value
        return SendClientMessage(playerid, COLOR_ERROR, "USAGE: /w [message]");

    for(new i = 0; i < MAX_PLAYERS; i++) {
        if(IsPlayerConnected(i) && PlayerToPlayer(playerid, i, < 10)) { // Check if they're connected & close enough
            format(szMessage, sizeof(szMessage), "%s(%d) whispered : %s", GetName(playerid), playerid, params);
            SendClientMessage(i, COLOR_PURPLE, szMessage); // Send the message only to the player who's close enough
        }
    }
    return 1;
}
Is this what you wanted? A message 'whispered' to all players within 10 distance units?
Reply
#5

Why do you use sscanf line inside the loop? If you type "/w", then it will send the usage message many times (as many as MAX_PLAYERS is defined). You don't even need sscanf for it.

pawn Код:
CMD:w(playerid, params[])
{
    if (isnull(params)) return SendClientMessage(playerid, COLOR_ERROR, "USAGE: /w (Message)");
   
    new
        string[128],
        Float: px,
        Float: py,
        Float: pz;
     
    format(string, sizeof (string), "%s(%d) whispered : %s", GetName(playerid), playerid, params);
    GetPlayerPos(playerid, px, py, pz);
    for (new i; i != MAX_PLAYERS; ++i) // foreach(new i : Player)
    {
        if (IsPlayerInRangeOfPoint(i, 10.0, px, py, pz)) SendClientMessage(i, COLOR_PURPLE, string);
    }
    return 1;
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)