CMD:pm(playerid, params[])
{
new targetid, string[258], tekst[128];
if(sscanf(params, "us[128]", targetid, tekst)) return SendClientMessage(playerid, COLOR_WHITE, "{3BB9FF}use: {FFFFFF}/pm < ID > < tekst >");
if(targetid == INVALID_PLAYER_ID) return SendClientMessage(playerid, COLOR_RED, "Wrong ID");
format(string, sizeof(string), "[PM][IN] %s: %s", PlayerName(playerid), tekst);
SendClientMessage(targetid, COLOR_YELLOW, string);
format(string, sizeof(string), "[PM][out] %s: %s", PlayerName(targetid), tekst);
SendClientMessage(playerid, COLOR_RED, string);
return 1;
}
if(!IsPlayerConnected(targetid)) return SendClientMessage(playerid, COLOR_RED, "Wrong ID"); |
CMD:pm(playerid, params[])
{
new targetid, string[258], tekst[128];
if(sscanf(params, "ds[128]", targetid, tekst)) return SendClientMessage(playerid, COLOR_WHITE, "{3BB9FF}use: {FFFFFF}/pm < ID > < tekst >");
if(targetid == INVALID_PLAYER_ID) return SendClientMessage(playerid, COLOR_RED, "Wrong ID");
format(string, sizeof(string), "[PM][IN] %s: %s", PlayerName(playerid), tekst);
SendClientMessage(targetid, COLOR_YELLOW, string);
format(string, sizeof(string), "[PM][out] %s: %s", PlayerName(targetid), tekst);
SendClientMessage(playerid, COLOR_RED, string);
return 1;
}
In your code you save targetid as "u", it can be a name so no "targetid = INVALID_PLAYER_ID" nor IsPlayerConnected(targetid) can slove it, change "u" to "d"
|
"u" allows sscanf to search for both names and ids.
And if the id or name doesn't exist, it sets the variable as INVALID_PLAYER_ID. So it has nothing to with "d" and "u" https://sampforum.blast.hk/showthread.php?tid=602923 Read the specifiers section. |
new id, mess[40];
if(sscanf(params, "us[40]", id, mess)) return SendClientMessage(playerid, -1, "{0008F7}USAGE: {FFFFFF}/PM ID MESSAGE");
if(!IsPlayerConnected(id)) return SendClientMessage(playerid, 0xCD0000FF, "Player is not connected");
if(DND[id] == 1) return SendClientMessage(playerid, 0xCD0000FF, "Player is on DND mode");
new PName[24];
GetPlayerName(id, PName, sizeof(PName));
new string[100], name[24];
GetPlayerName(playerid, name, sizeof(name));
format(string,sizeof(string),"{FCDF00}[PRIVATE MESSAGE] {8A887B}From %s(%d): {8C8656}%s", name, playerid, mess);
SendClientMessage(id, -1, string);
format(string,sizeof(string),"{FCDF00}[PRIVATE MESSAGE] {8A887B}To %s(%d): {8C8656}%s", PName, id, mess);
SendClientMessage(playerid, -1, string);