PDA

View Full Version : PM problem


Chris'
03/03/2012, 03:04 PM
I really cant figure out what is wrong with this code, it doesent compile any errors, but when i type ingame /pm 0 text it says server unknown command, please help.


dcmd_pm(playerid, params[])
{
new id, text[128], iName[MAX_PLAYER_NAME], name[MAX_PLAYER_NAME], str[128];
if(sscanf(params, "us", id, text)) SendClientMessage(playerid, LIGHTBLUE, "USAGE: {FFFFFF}/pm [playerid] [text]");
else if(id == INVALID_PLAYER_ID) SendClientMessage(playerid, ORANGERED, "ERROR: {FFFFFF}Invalid PlayerID");
{
GetPlayerName(id,iName,sizeof(iName));
GetPlayerName(playerid, name,sizeof(name));
format(str,sizeof(str),"PM sent %s (ID: %d): %s",iName,id,text);
SendClientMessage(playerid,YELLOW,str);
format(str,sizeof(str),"PM From %s (ID: %d): %s",name,playerid,text);
SendClientMessage(id,ORANGE,str);
PlayerPlaySound(id,1085,0.0,0.0,0.0);
printf("PM Logger: %s (From: %s) (To: %s)",str, iName, name);
}
return 1;
}

Drebin
03/03/2012, 03:25 PM
dcmd_pm(playerid, params[])
{
new id, text[128], iName[MAX_PLAYER_NAME], name[MAX_PLAYER_NAME], str[128];
if(sscanf(params, "us", id, text)) return SendClientMessage(playerid, LIGHTBLUE, "USAGE: {FFFFFF}/pm [playerid] [text]");
if(id == INVALID_PLAYER_ID) return SendClientMessage(playerid, ORANGERED, "ERROR: {FFFFFF}Invalid PlayerID");
GetPlayerName(id,iName,sizeof(iName));
GetPlayerName(playerid, name,sizeof(name));
format(str,sizeof(str),"PM sent %s (ID: %d): %s",iName,id,text);
SendClientMessage(playerid,YELLOW,str);
format(str,sizeof(str),"PM From %s (ID: %d): %s",name,playerid,text);
SendClientMessage(id,ORANGE,str);
PlayerPlaySound(id,1085,0.0,0.0,0.0);
printf("PM Logger: %s (From: %s) (To: %s)",str, iName, name);
return 1;
}

?

Campbell-
03/03/2012, 03:28 PM
dcmd_pm(playerid, params[])
{
new id, text[128], iName[MAX_PLAYER_NAME], name[MAX_PLAYER_NAME], str[128];
if(sscanf(params, "us", id, text)) SendClientMessage(playerid, LIGHTBLUE, "USAGE: {FFFFFF}/pm [playerid] [text]");
else if(id == INVALID_PLAYER_ID) SendClientMessage(playerid, ORANGERED, "ERROR: {FFFFFF}Invalid PlayerID");
else
{
GetPlayerName(id,iName,sizeof(iName));
GetPlayerName(playerid,name,sizeof(name));
format(str,sizeof(str),"PM sent %s (ID: %d): %s",iName,id,text);
SendClientMessage(playerid,YELLOW,str);
format(str,sizeof(str),"PM From %s (ID: %d): %s",name,playerid,text);
SendClientMessage(id,ORANGE,str);
PlayerPlaySound(id,1085,0.0,0.0,0.0);
printf("PM Logger: %s (From: %s) (To: %s)",str, iName, name);
return 1;
}
}

Check if it works with the return in the else clause and make sure that you add an else clause after an if and else if clause.

Chris'
03/03/2012, 03:34 PM
When i type it, nothing happens, its just blank, and when i do /pm 0 it says Pm (id: 48)

]Rafaellos[
03/03/2012, 03:38 PM
dcmd_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, 0xFF0000FF, str);
format(str, sizeof(str), "PM From %s(ID %d): %s", Name1, playerid, str2);
SendClientMessage(id, 0xFF0000FF, str);
}
return 1;
}

try this...

Chris'
03/03/2012, 03:52 PM
This sends the message, but for some reason to playerid 42 i type /pm 0 text ti sends it to id 42

Markô
03/03/2012, 03:54 PM
Try this


dcmd_pm(playerid, params[])
{
new id, text[128], iName[MAX_PLAYER_NAME], name[MAX_PLAYER_NAME], str[128];
if(sscanf(params, "us", id, text)) SendClientMessage(playerid, LIGHTBLUE, "USAGE: {FFFFFF}/pm [playerid] [text]");
else if(id == INVALID_PLAYER_ID) SendClientMessage(playerid, ORANGERED, "ERROR: {FFFFFF}Invalid PlayerID");
{
GetPlayerName(id,iName,sizeof(iName));
GetPlayerName(playerid, name,sizeof(name));
format(str,sizeof(str),"PM sent %s (ID: %d): %s",iName,id,text);
SendClientMessage(playerid,YELLOW,str);
format(str,sizeof(str),"PM From %s (ID: %d): %s",name,playerid,text);
SendClientMessage(id,ORANGE,str);
PlayerPlaySound(id,1085,0.0,0.0,0.0);
printf("PM Logger: %s (From: %s) (To: %s)",str, iName, name);
return 1;
}
return 0;
}

]Rafaellos[
03/03/2012, 03:57 PM
This sends the message, but for some reason to playerid 42 i type /pm 0 text ti sends it to id 42

In my gamemode it works fine :S

Walsh
03/03/2012, 03:59 PM
Switch to ZCMD (http://forum.sa-mp.com/showthread.php?t=91354).

suhrab_mujeeb
03/03/2012, 04:32 PM
Under OnPlayerCommandText
dcmd(pm, 2, cmdtext);
This happens mainly due to the size of the command specified under the OnPlayerCommandText does not match the actual size of the command. ( size means the length of the command )