PM command fail?
#1

Hey guys, +1 to my failure count
This time,I created a /pm command.
It fails.
Well,code:
pawn Код:
if(strcmp(cmd, "/pm", true) == 0)
    {
      new name[24],mString1[126],mString2[126],n300[24];
      GetPlayerName(playerid,name,24);
        tmp = strtok(cmdtext, idx);
        message = strrest(cmdtext, idx);
        if(strlen(tmp) == 0 || strlen(message) == 0) return SendClientMessage(playerid, RedCol, "USAGE: /pm [playerid] [message]");
        else if(!IsNumeric(tmp)) return SendClientMessage(playerid,RedCol,"ERROR: Invalid player ID.");
        else if(!IsPlayerConnected(strval(tmp))) return SendClientMessage(playerid,RedCol,"ERROR: Player is not connected.");
        else if(strval(tmp) == playerid) return SendClientMessage(playerid,RedCol,"ERROR: You cannot PM yourself.");
       
       
        else
        {
          format(mString1,126,"Message from %s(%d): %s",name,playerid,message);
          SendClientMessage(strval(tmp),YellowCol,mString1);
          GetPlayerName(strval(tmp),n300,24);
          format(mString2,126,"Message succesfully sent to %s.",n300);
          SendClientMessage(playerid,Yellow2Col,mString2);
        }
       
        return 1;
    }
Well the fail in here is that whenever I send a PM to a player,he only see the first word I've typed.
E.X If i type "/pm 1 hello how are you?" the player only see "hello".
I've tried to inlarge the strings,still same problem.
Any help appreciated.
Reply
#2

Might work:
Код:
if(strcmp(cmdtext, "/pm", true) == 0)
{
  	new name[24],mString1[126],mString2[126],n300[24];
  	GetPlayerName(playerid,name,24);
  	tmp = strtok(cmdtext, idx);

	if(strlen(tmp) == 0 ) return SendClientMessage(playerid, RedCol, "USAGE: /pm [playerid] [message]");
	if(!IsNumeric(tmp)) return SendClientMessage(playerid,RedCol,"ERROR: Invalid player ID.");
	if(!IsPlayerConnected(strval(tmp))) return SendClientMessage(playerid,RedCol,"ERROR: Player is not connected.");
	if(strval(tmp) == playerid) return SendClientMessage(playerid,RedCol,"ERROR: You cannot PM yourself.");



	format(mString1,126,"Message from %s(%d): %s",name,playerid, cmdtext[7]);
	SendClientMessage(strval(tmp),YellowCol,mString1);
	GetPlayerName(strval(tmp),n300,24);
	format(mString2,126,"Message succesfully sent to %s.",n300);
	SendClientMessage(playerid,Yellow2Col,mString2);
	
	return 1;
}
Reply
#3

Quote:
Originally Posted by DJDhan
Might work:
Код:
if(strcmp(cmdtext, "/pm", true) == 0)
{
  	new name[24],mString1[126],mString2[126],n300[24];
  	GetPlayerName(playerid,name,24);
  	tmp = strtok(cmdtext, idx);

	if(strlen(tmp) == 0 ) return SendClientMessage(playerid, RedCol, "USAGE: /pm [playerid] [message]");
	if(!IsNumeric(tmp)) return SendClientMessage(playerid,RedCol,"ERROR: Invalid player ID.");
	if(!IsPlayerConnected(strval(tmp))) return SendClientMessage(playerid,RedCol,"ERROR: Player is not connected.");
	if(strval(tmp) == playerid) return SendClientMessage(playerid,RedCol,"ERROR: You cannot PM yourself.");



	format(mString1,126,"Message from %s(%d): %s",name,playerid, cmdtext[7]);
	SendClientMessage(strval(tmp),YellowCol,mString1);
	GetPlayerName(strval(tmp),n300,24);
	format(mString2,126,"Message succesfully sent to %s.",n300);
	SendClientMessage(playerid,Yellow2Col,mString2);
	
	return 1;
}
Thanks I'll test as soon as I can.
Reply
#4

Well atleast he sees your greetings, eh?

lmaoo
Reply
#5

Quote:
Originally Posted by Tnt12340
Well atleast he sees your greetings, eh?

lmaoo
Wut? xD
Anyway,sorry DJDhan,but now it just sends "SERVER: Unknown command."
Reply
#6

If you know how, use dcmd and sscanf. Its a lot faster and easier to work with.
Reply
#7

Код:
if(!strcmp(cmd, "/pm", true))
{
	tmp = strtok(cmdtext, idx);
	if(!strlen(tmp)) return SendClientMessage(playerid, RedCol, "USAGE: /pm [playerid] [message]");
	new ID = strval(tmp);
	if(!IsNumeric(ID)) return SendClientMessage(playerid,RedCol,"ERROR: Invalid player ID.");
	if(!IsPlayerConnected(ID)) return SendClientMessage(playerid,RedCol,"ERROR: Player is not connected.");
	if(ID == playerid) return SendClientMessage(playerid,RedCol,"ERROR: You cannot PM yourself.");
	tmp = strrest(cmdtext, idx);
	if(!strlen(tmp)) return SendClientMessage(playerid, RedCol, "USAGE: /pm [playerid] [message]");
	new name[24],mString[190];
	GetPlayerName(playerid,name,24);
	format(mString,sizeof(mString),"Message from %s(%d): %s",name,playerid,tmp);
	SendClientMessage(ID,YellowCol,mString);
	GetPlayerName(ID,name,24);
	format(mString,sizeof(mString),"Message succesfully sent to %s.",name);
	SendClientMessage(playerid,Yellow2Col,mString);
	return 1;
}
Reply
#8

Quote:
Originally Posted by randomkid88
If you know how, use dcmd and sscanf. Its a lot faster and easier to work with.
Never mind about that,I'm using Kye's /pm from base.pwn.

EDIT: @Jefff- I believe that will work,I'll wait for my friend to come online and I'll test it with him,anyhow,for now thanks!
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)