Help with pm command.
#1

I don't have errors, but it's not working.
Help!

CMDm(playerid, params[])
{
new id;
new message[600], str[1000];
new name[MAX_PLAYER_NAME];
new tname[MAX_PLAYER_NAME];
if(!IsPlayerConnected(id)) return SendClientMessage(playerid, -1, "ERROR:This player isn't in game.");
if(sscanf(params, "us", id, message)) return SendClientMessage(playerid, -1 , "Server: Usage, /pm [id] [message]");
GetPlayerName(playerid, name, sizeof(name));
GetPlayerName(id, tname, sizeof(tname));
format(Jstring, sizeof(Jstring), "Server: You had sent a private message to %s(%d): %s ", tname , id , message);
format(str, sizeof(str), "%s(%d) had sent you a private message: %s ", name , playerid, message);
SendClientMessage(id, -1, Jstring);
SendClientMessage(playerid, -1 , str);
return 1;
}
Reply
#2

Quote:
Originally Posted by ZToPMaN
Посмотреть сообщение
post
Make sure you always put code snippets into [.pawn] [/pawn] tags (remove the full stop in the first tag).

Also, reduce the size of your strings as they're unnecessarily large.

You need to check if the player is connected after calling the sscanf function (otherwise the value of 'id' is always 0 and will not correctly represent the player you want to message).
pawn Код:
CMD:pm(playerid, params[])
{
new id;
new message[128], string[200]; // reduce the size of the string if needed
new name[MAX_PLAYER_NAME];
new tname[MAX_PLAYER_NAME];

if(sscanf(params, "us", id, message)) return SendClientMessage(playerid, -1 , "Server: Usage, /pm [id]
[message]"
);
if(!IsPlayerConnected(id)) return SendClientMessage(playerid, -1, "ERROR:This player isn't in game.");
GetPlayerName(playerid, name, sizeof(name));
GetPlayerName(id, tname, sizeof(tname));
format(string, sizeof(string), "To %s (%d): %s ", tname , id , message);
SendClientMessage(id, -1,  string);
format(string, sizeof(string), "From %s (%d): %s", name , playerid, message);
SendClientMessage(playerid, -1 , string);
return 1;
}
Reply
#3

Hey, it still not working.
When ever i say /pm [any id except my id any online player , it says /pm id message.
also, when i told my friend to come ig and i was tring to use it, it was not working also.
Reply
#4

PHP код:
CMD:pm(playeridparams[])
{
    new 
str2[128], id;
    if(
sscanf(params"us[128]"idstr2)) return SendClientMessage(playeridCOLOR_WHITE"Usage: /pm [ID] [MESSAGE]");
    if(!
IsPlayerConnected(id)) return SendClientMessage(playeridCOLOR_WHITE"Player Isnt Connected");
    new 
Name1[MAX_PLAYER_NAME], Name2[MAX_PLAYER_NAME], str[128];
    
GetPlayerName(playeridName1sizeof(Name1));
    
GetPlayerName(idName2sizeof(Name2));
    
format(strsizeof(str), "((PM To %s: %s))"Name2str2);
    
SendClientMessage(playeridCOLOR_YELLOWstr);
    
format(strsizeof(str), "((PM From %s: %s))"Name1str2);
    
SendClientMessage(idCOLOR_YELLOWstr);
    return 
1;

Replace this with your command
Reply
#5

I know now what's the problem.
I checked the logs, and i found this error with sscanf, can any one tell me how can i fix this?
pawn Код:
[01:41:34] sscanf error: System not initialised.
Reply
#6

If you get this error, you need to make sure that you have recompiled ALL your scripts using the LATEST version of "sscanf2.inc". Older versions didn't really require this as they only had two natives - "sscanf" and "unformat", the new version has some other functions - you don't need to worry about them, but you must use "sscanf2.inc" so that they are correctly called. If you think you have done this and STILL get the error then try again - make sure you are using the correct version of PAWNO for example.
Reply
#7

It's working now, thanks alot all!.
Reply


Forum Jump:


Users browsing this thread: 3 Guest(s)