Private Messaging problem.
#1

I have found the error in the code, but I am not clever enough to find the solution.

pawn Код:
CMD:pm(playerid, params[])
{
     new pm1[128], pm2[128], text[128], targetid;
     if(!IsPlayerConnected(playerid)) return SendClientMessage(playerid, COLOR_RED, "[ERROR]: No one with that playerid is connected to the server!");
     if(targetid == playerid) return SendClientMessage(playerid, COLOR_RED, "[ERROR]: You can't PM yourself!");
     if(sscanf(params, "us[128]", targetid, text)) return SendClientMessage(playerid, COLOR_RED, "[USAGE]: /pm <playerid> <Message>");
     format(pm1, sizeof(pm1), "*PM SENT* %s[%d]: %s", PlayerName(playerid), playerid, text);
     format(pm2, sizeof(pm2), "*PM RECEIVED* %s[%d]: %s", PlayerName(playerid), playerid, text);
     SendClientMessage(playerid, COLOR_YELLOW, pm1);
     SendClientMessage(targetid, COLOR_YELLOW, pm2);
     return 1;
}
That is the code, and this is the problem.

pawn Код:
if(targetid == playerid) return SendClientMessage(playerid, COLOR_RED, "[ERROR]: You can't PM yourself!");
Is there any alternative to this? Everytime I use /pm 2 hi (My ID being 1 as I have a NPC in-game.) I get [ERROR]: You can't PM yourself.
Reply
#2

pawn Код:
CMD:pm(playerid, params[])
{
     new pm1[128], pm2[128], text[128], targetid;
     if(sscanf(params, "us[128]", targetid, text)) return SendClientMessage(playerid, COLOR_RED, "[USAGE]: /pm <playerid> <Message>");
    if(!IsPlayerConnected(playerid)) return SendClientMessage(playerid, COLOR_RED, "[ERROR]: No one with that playerid is connected to the server!");
     if(targetid == playerid) return SendClientMessage(playerid, COLOR_RED, "[ERROR]: You can't PM yourself!");
     format(pm1, sizeof(pm1), "*PM SENT* %s[%d]: %s", PlayerName(playerid), playerid, text);
     format(pm2, sizeof(pm2), "*PM RECEIVED* %s[%d]: %s", PlayerName(playerid), playerid, text);
     SendClientMessage(playerid, COLOR_YELLOW, pm1);
     SendClientMessage(targetid, COLOR_YELLOW, pm2);
     return 1;
}
First write sscanf function, then check if is player connected, or if target id it's yourself.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)