SA-MP Forums Archive
Private Messaging problem. - 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: Private Messaging problem. (/showthread.php?tid=565750)



Private Messaging problem. - Th3UnKnOwN - 01.03.2015

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.


Re: Private Messaging problem. - HY - 01.03.2015

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.