SA-MP Forums Archive
PM Command - 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)
+---- Forum: Help Archive (https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: PM Command (/showthread.php?tid=266571)



PM Command - ludesert - 05.07.2011

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 =)


Re: PM Command - [03]Garsino - 05.07.2011

Why aren't you using the u parameter...?


Re : PM Command - ludesert - 05.07.2011

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

And where do you think I should use it ?


Re: PM Command - Vince - 05.07.2011

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.


Re : PM Command - ludesert - 05.07.2011

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


Re: Re : PM Command - JaTochNietDan - 05.07.2011

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.


Re : PM Command - ludesert - 05.07.2011

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



Re: PM Command - JaTochNietDan - 05.07.2011

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.


Re : PM Command - ludesert - 05.07.2011

It returns "Player not found".


Re: Re : PM Command - [03]Garsino - 05.07.2011

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)!