PM Command
#1

Hello, I'm making a PM command from name.

The code is this :

pawn Код:
CMD:pm(playerid, params[])
{
        new reciever[25], message[100], id;
        if (sscanf(params, "r[25]s[100]", reciever, message))
        return SendClientMessage(playerid, 0xFF9900, "Usage: \"/PM <name/part of name> <message>\"");
        id = GetIdFromName(reciever);
        if (!IsPlayerConnected(id)) return SendClientMessage(playerid, 0xFF0000AA, "Player not found");

        new pname[MAX_PLAYER_NAME], msg[100], sendermsg[100];
        GetPlayerName(playerid, pname, sizeof(pname));

        format(msg, sizeof(msg), "PM from %s : %s", pname, message);
        SendClientMessage(id, 0xFFFF00AA, msg);

        format(sendermsg, sizeof(sendermsg), "Message sent !");
        SendClientMessage(playerid, 0xFFFF00AA, sendermsg);

        return 1;
}
With this stock :

pawn Код:
stock GetIdFromName(playername[]) // © by iPLEOMAX
{
    for(new i=0; i<MAX_PLAYERS; i++)
    {
        if(IsPlayerConnected(i) && !IsPlayerNPC(i))
        {
            new pname[MAX_PLAYER_NAME];
            GetPlayerName(i,pname,MAX_PLAYER_NAME);
            if(strfind(pname,playername,true) != -1 && strlen(playername) != 0)
            {
                return i;
            }
        }
    }
    if(strfind(playername, "0",true) != -1 && strlen(playername) <= 1) return 0;
    if(strval(playername) > 0 && strval(playername) <= MAX_PLAYERS) return strval(playername);
    return -1;
}
(And Zcmd stock).

So, my problem is that the reciever doesn't see the message. I explain : The sender recieves "Message sent !", the reciever just recieves "MP from /sender name/ :" and he doesn't have the message.

Why ? Thanks a lot for your answers =)
Reply
#2

Why aren't you using the u parameter...?
Reply
#3

I do'nt know ... But I think this wouldn't resolve my problem ?

And where do you think I should use it ?
Reply
#4

Ye, using GetIdFromName with sscanf makes absolutely no sense. When a (partial) playername is passed to sscanf, it automatically returns the player id (or INVALID_PLAYER_ID if not found). And Garsino: the r specifier works the same as the u specifier, with the exception that is does not accept NPC names.

pawn Код:
if (sscanf(params, "rs[100]", id, message))
Should work. Then use 'id' throughout your code and use GetPlayerName to get the name of the player.
Reply
#5

I have the same problem, the reciever doesn't recieve the message x)
Reply
#6

Quote:
Originally Posted by ludesert
Посмотреть сообщение
I have the same problem, the reciever doesn't recieve the message x)
Show us the command you ended up with after making the changes that didn't work.
Reply
#7

pawn Код:
CMD:pm(playerid, params[])
{
        new reciever[25], message[100], id;
        if (sscanf(params, "rs[100]", reciever, message))
        return SendClientMessage(playerid, 0xFF9900, "Usage: \"/PM <name/part of name> <message>\"");
        id = GetIdFromName(reciever);
        if (!IsPlayerConnected(id)) return SendClientMessage(playerid, 0xFF0000AA, "Player not found");

        new pname[MAX_PLAYER_NAME], msg[100], sendermsg[100];
        GetPlayerName(playerid, pname, sizeof(pname));

        format(msg, sizeof(msg), "PM from %s : %s", pname, message);
        SendClientMessage(id, 0xFFFF00AA, msg);

        format(sendermsg, sizeof(sendermsg), "Message sent !");
        SendClientMessage(playerid, 0xFFFF00AA, sendermsg);

        return 1;
}
Reply
#8

You're still not understanding what he said correctly, sscanf will automatically return the ID for you, it doesn't return a string with the "r" identifier, it returns an integer!

So change your command like so:

pawn Код:
CMD:pm(playerid, params[])
{
        new message[100], id;
        if (sscanf(params, "rs[100]", id, message))
        return SendClientMessage(playerid, 0xFF9900, "Usage: \"/PM <name/part of name> <message>\"");
        if (!IsPlayerConnected(id)) return SendClientMessage(playerid, 0xFF0000AA, "Player not found");

        new pname[MAX_PLAYER_NAME], msg[100], sendermsg[100];
        GetPlayerName(playerid, pname, sizeof(pname));

        format(msg, sizeof(msg), "PM from %s : %s", pname, message);
        SendClientMessage(id, 0xFFFF00AA, msg);

        format(sendermsg, sizeof(sendermsg), "Message sent !");
        SendClientMessage(playerid, 0xFFFF00AA, sendermsg);

        return 1;
}
Furthermore I suggest you read up on the sscanf documentation available over at the topic for the plugin.
Reply
#9

It returns "Player not found".
Reply
#10

Quote:
Originally Posted by ludesert
Посмотреть сообщение
It returns "Player not found".
The "r" parameter is case sensetive, the u parameter is not. In other words: If you use the "r" parameter you have to write the name exactly as it is (with capitals, etc)!
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)