PM error
#1

I've been making this PM command, but it keeps telling me that the given player isn't connected.
Code:
	if(!strcmp(cmd, "/pm"))
	{
	    new player;
		new message;
		if(sscanf(params, "ds", player, message)) return SendClientMessage(playerid,COLOR_WHITE,"  {FF0000}/PM {FFFF00}: Usage: {FF4040}/pm [player id] [message]{FFFF00}.");
    	if(IsPlayerConnected(player)==0) return SendClientMessage(playerid,COLOR_WHITE,"  {FF0000}/PM {FFFF00}: That player isn't connected.");
		if(player == playerid) return SendClientMessage(playerid,COLOR_WHITE,"  {FF0000}/PM {FFFF00}: You can't PM yourself.");
		else
		{
			new sendername[MAX_PLAYER_NAME];
			GetPlayerName(playerid,sendername,sizeof(sendername));
			new name[MAX_PLAYER_NAME];
			GetPlayerName(playerid,name,sizeof(name));
		    new string[128];
		    format(string,sizeof(string),"  {FF0000}/PM {FFFF00}: PM from {FF4040}%s{FFFF00}: {FFFFFF}%d",sendername,message);
			SendClientMessage(player,COLOR_WHITE,string);
			format(string,sizeof(string),"  {FF0000}/PM {FFFF00}: You've sent a PM to {FF4040}%s{FFFF00}: {FFFFFF}%d",name,message);
			SendClientMessage(player,COLOR_WHITE,string);
			return 1;
		}
	}
What's the problem?
Reply
#2

PHP Code:
if(!strcmp(cmd"/pm"))
    {
      if(
IsPlayerConnected(playerid))
        {
        new 
player;
        new 
message;
        if(
sscanf(params"ds"playermessage)) return SendClientMessage(playerid,COLOR_WHITE,"  {FF0000}/PM {FFFF00}: Usage: {FF4040}/pm [player id] [message]{FFFF00}.");
        if(
IsPlayerConnected(player)==0) return SendClientMessage(playerid,COLOR_WHITE,"  {FF0000}/PM {FFFF00}: That player isn't connected.");
        if(
player == playerid) return SendClientMessage(playerid,COLOR_WHITE,"  {FF0000}/PM {FFFF00}: You can't PM yourself.");
        else
        {
            new 
sendername[MAX_PLAYER_NAME];
            
GetPlayerName(playerid,sendername,sizeof(sendername));
            new 
name[MAX_PLAYER_NAME];
            
GetPlayerName(playerid,name,sizeof(name));
            new 
string[128];
            
format(string,sizeof(string),"  {FF0000}/PM {FFFF00}: PM from {FF4040}%s{FFFF00}: {FFFFFF}%d",sendername,message);
            
SendClientMessage(player,COLOR_WHITE,string);
            
format(string,sizeof(string),"  {FF0000}/PM {FFFF00}: You've sent a PM to {FF4040}%s{FFFF00}: {FFFFFF}%d",name,message);
            
SendClientMessage(player,COLOR_WHITE,string);
            return 
1;
        }
    } 
Reply
#3

Are you using the plugin version of sscanf? If so, you should see a warning in your server window: 'sscanf warning: strings without a length are deprecated ...'. Oh, and you're trying to assign a string to an integer which won't work either.

pawn Code:
new
        player,
    message[100];
   
    if(sscanf(params, "us[100]", player, message))
Should work. Still, assuming you're using the plugin.
Reply
#4

Are you dumb or blind?
Since when strcmp has params?
he has if(!strcmp(cmd, "/pm"))
and
if(sscanf(params, "ds", player, message)) return SendClientMessage(playerid,COLOR_WHITE," {FF0000}/PM {FFFF00}: Usage: {FF4040}/pm [player id] [message]{FFFF00}.");
Reply
#5

I suggest you to use ZCMD, And here is your short PM Command.

pawn Code:
COMMAND:pm(playerid, params[]) {
    new string[158];
    new string2[158];
    new TargetID;
    new SenderName[MAX_PLAYER_NAME];
    new ReceiverName[MAX_PLAYER_NAME];

    if(sscanf(params, "us", TargetID, string2)) {
        SendClientMessage(playerid, 0xF88017FF, "Correct Usage: /Pm (PlayerID/PartOfName) (Message).");
        SendClientMessage(playerid, 0xF88017FF, "Function: Will send an message to entered playerid.");
        return 1; }
    if(playerid != TargetID) return SendClientMessage(playerid, 0xFF0000FF, "Error: You cannot pm yourself!");
    if(!IsPlayerConnected(TargetID)) return SendClientMessage(playerid, 0xF88017FF, "Failed to send Private Message to entered PlayerID, Tip: Please check wether the player is connected Or the ID is wrong."); {
        GetPlayerName(playerid, SenderName, sizeof(SenderName));
        GetPlayerName(TargetID, ReceiverName, sizeof(ReceiverName));
        format(string, sizeof(string), "Private Message Sent to: %s(ID %d) Message:%s", ReceiverName, TargetID, string2);
        SendClientMessage(playerid, 0xF88017FF, string);
        format(string, sizeof(string), "Private Message From: %s(ID %d) Message: %s", SenderName, playerid, string2);
        SendClientMessage(TargetID, 0xF88017FF, string); }
    return 1; }
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)