SA-MP Forums Archive
Need Help with 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)
+--- Thread: Need Help with Pm command..:-/ (/showthread.php?tid=380624)



Need Help with Pm command..:-/ - Desi_Dude - 26.09.2012

I need help with /pm command

I am i suppose to add hmm.. such as if someone PM it should be like this They can either enter their (ID) or (Partoftheirname) or fullname..

Here is the code :
Код:
CMD:pm(playerid, cmdtext[])
{
    new
        idx = strfind(cmdtext, " ", true);
    if((cmdtext[0] == EOS) || ((cmdtext[0] == '\1') && (cmdtext[1] == EOS)) || (idx == -1)) {
        SendClientMessage(playerid,COLOR_LIGHTBLUE,"Usage: /pm [ID] [MESSAGE]");
        return 1;
    }
    if(cmdtext[idx + 1] == EOS) {
        SendClientMessage(playerid,COLOR_LIGHTBLUE,"Usage: /pm [ID] [MESSAGE]");
        return 1;
    }
    cmdtext[idx++] = EOS;
    new
        id = strval(cmdtext);
    if(!IsPlayerConnected(id)) {
        SendClientMessage(playerid,COLOR_LIGHTBLUE,"/pm : Wrong Player ID");
        return 1;
    }
    if(playerid == id) {
        SendClientMessage(playerid,COLOR_YELLOW,"You cannot PM yourself.");
        return 1;
    }
    new
        string[256];
    GetPlayerName(id, string, MAX_PLAYER_NAME);
    format(string, sizeof string, "[PM] Message send to %s(%d): %s", string, id, cmdtext[idx]);
    SendClientMessage(playerid, COLOR_LIGHTBLUE, string);

    GetPlayerName(playerid, string, MAX_PLAYER_NAME);
    format(string, sizeof string, "[OOCPM] Message from %s(%d): %s", string, playerid, cmdtext[idx]);
    SendClientMessage(id, COLOR_LIGHTBLUE, string);
    PlayerPlaySound(id, 1057, 0.0, 0.0, 0.0);

    printf("PM: %s", cmdtext[idx]);
    return 1;
}



Re: Need Help with Pm command..:-/ - Jarnu - 26.09.2012

Better use sscanf

sscanf here: https://sampforum.blast.hk/showthread.php?tid=120356

and following PM cmd
pawn Код:
CMD:pm(playerid, params[])
{
new str[256], str2[256], id, Name1[MAX_PLAYER_NAME], Name2[MAX_PLAYER_NAME];
if(sscanf(params, "us", id, str2))
{
SendClientMessage(playerid, 0xFF0000FF, "Usage: /pm <id> <message>");
return 1;
}
if(!IsPlayerConnected(id)) return SendClientMessage(playerid, 0xFF0000FF, "ERROR: Player not connected");
if(playerid == id) return SendClientMessage(playerid, 0xFF0000FF, "ERROR: You cannot pm yourself!");
{
GetPlayerName(playerid, Name1, sizeof(Name1));
GetPlayerName(id, Name2, sizeof(Name2));
format(str, sizeof(str), "PM To %s [ID %d]: %s", Name2, id, str2);
SendClientMessage(playerid, yellow, str);
format(str, sizeof(str), "PM From %s [ID %d]: %s", Name1, playerid, str2);
SendClientMessage(id, yellow, str);
}
return 1;
}
You can edit it according to your script.
Tested | trusted | works


Re: Need Help with Pm command..:-/ - Glint - 26.09.2012

Quote:
Originally Posted by Jarnu
Посмотреть сообщение
Better use sscanf

sscanf here: https://sampforum.blast.hk/showthread.php?tid=120356

and following PM cmd
pawn Код:
CMD:pm(playerid, params[])
{
new str[256], str2[256], id, Name1[MAX_PLAYER_NAME], Name2[MAX_PLAYER_NAME];
if(sscanf(params, "us", id, str2))
{
SendClientMessage(playerid, 0xFF0000FF, "Usage: /pm <id> <message>");
return 1;
}
if(!IsPlayerConnected(id)) return SendClientMessage(playerid, 0xFF0000FF, "ERROR: Player not connected");
if(playerid == id) return SendClientMessage(playerid, 0xFF0000FF, "ERROR: You cannot pm yourself!");
{
GetPlayerName(playerid, Name1, sizeof(Name1));
GetPlayerName(id, Name2, sizeof(Name2));
format(str, sizeof(str), "PM To %s [ID %d]: %s", Name2, id, str2);
SendClientMessage(playerid, yellow, str);
format(str, sizeof(str), "PM From %s [ID %d]: %s", Name1, playerid, str2);
SendClientMessage(id, yellow, str);
}
return 1;
}
You can edit it according to your script.
Tested | trusted | works
OMG please man indent your code.


Re: Need Help with Pm command..:-/ - Desi_Dude - 26.09.2012

what do you mean o.O


Re: Need Help with Pm command..:-/ - Cxnnor - 26.09.2012

pawn Код:
CMD:pm(playerid, params[])
{
    new string[128], message[128], id;
    if(sscanf(params, "uz", id, message))
    {
        SendClientMessage(playerid, -1, "SYNTAX: /pm [playerid] [message]");
    }
    else
    {
        if(IsPlayerConnected(id))
        {
            if(strlen(message) >= 1)
            {
                format(string, sizeof(string), "((PM to %s(ID: %d): %s)) ", GetName(id), id, message);
                SendClientMessage(playerid, 0xFFFF00FF, string);
                format(string, sizeof(string), "((PM from %s(ID: %d): %s)) ", GetName(playerid), playerid, message);
                SendClientMessage(id, 0xFFFF00FF, string);
            }
            else
            {
                SendClientMessage(playerid, -1, "SYNTAX: /pm [playerid] [message]");
            }
            else
            {
                SendClientMessage(playerid, -1, "That player is not connected.");
            }
    }
    return 1;
}



Re: Need Help with Pm command..:-/ - Jarnu - 26.09.2012

pawn Код:
if(sscanf(params, "uz", id, message))
z = ?

i heared of 's' not 'z' .. or its a mistake?


Re: Need Help with Pm command..:-/ - Desi_Dude - 12.10.2012

Thanks bhai +rep'd