Need a bit of help with /pm command
#1

Hello there,
I've been working on a /pm command using sscanf and zcmd and I bumped into something that I cant figure out quite yet.
The problem is with players that have similar nicknames.
Код:
if(!sscanf(params, "us["#STR_SIZE"]", id, message))
For example, John(1) and John32(2).
The command works if you send a pm with the id instead of name.
Now with this example, when sending a pm with their names or part of their names, it will only send to John, even when typing John32.
I've been scratching my head for a while now and I would appreciate it if someone would help me with coming up with some kind of code
for distinguishing similar nicknames in a similar manner to this:
Код:
if(similarnames)
  {
   SendClientMessage(playerid, 0xFF0000FF, "Too many similar names, please indicate id.");
  }
else
 {
 }
Here is the code for reference:
Код:
#include <a_samp>
#include <sscanf2>
#include <zcmd>
#define STR_SIZE 128


CMD:pm(playerid, params[])
{
	new id, Sender[MAX_PLAYER_NAME], Receiver[MAX_PLAYER_NAME];
 	new string[90], string2[90],message[STR_SIZE];
	if(!sscanf(params, "us["#STR_SIZE"]", id, message))
		{
		if(id != INVALID_PLAYER_ID)
		    {
		    if(playerid == id)
		        {
		        SendClientMessage(playerid, 0xFF0000FF, "You can't message yourself!");
		        }
			else
			    {
				GetPlayerName(playerid, Sender, sizeof(Sender));
				GetPlayerName(id, Receiver, sizeof(Receiver));
				format(string, sizeof(string), "PM: %s(%i): %s", Receiver, id, message);
				SendClientMessage(playerid, 0xFFE600AA, string);
				format(string2, sizeof(string2), "PM: %s(%i): %s", Sender, playerid, message);
				SendClientMessage(id, 0xFFE600AA, string2);
				}
		    }
		else
		    {
		    SendClientMessage(playerid, 0xFF0000FF, "Player not Connected.");
		    }
		}
	else
 		{
 		SendClientMessage(playerid, 0xFF0000FF, "Use: /pm [ID] [Message]");
		}
	return 1;
}
Reply
#2

Quote:
Originally Posted by RustyR
Посмотреть сообщение
Hello there,
I've been working on a /pm command using sscanf and zcmd and I bumped into something that I cant figure out quite yet.
The problem is with players that have similar nicknames.
Код:
if(!sscanf(params, "us["#STR_SIZE"]", id, message))
For example, John(1) and John32(2).
The command works if you send a pm with the id instead of name.
Now with this example, when sending a pm with their names or part of their names, it will only send to John, even when typing John32.
I've been scratching my head for a while now and I would appreciate it if someone would help me with coming up with some kind of code
for distinguishing similar nicknames in a similar manner to this:
Код:
if(similarnames)
  {
   SendClientMessage(playerid, 0xFF0000FF, "Too many similar names, please indicate id.");
  }
else
 {
 }
Here is the code for reference:
Код:
#include <a_samp>
#include <sscanf2>
#include <zcmd>
#define STR_SIZE 128


CMD:pm(playerid, params[])
{
	new id, Sender[MAX_PLAYER_NAME], Receiver[MAX_PLAYER_NAME];
 	new string[90], string2[90],message[STR_SIZE];
	if(!sscanf(params, "us["#STR_SIZE"]", id, message))
		{
		if(id != INVALID_PLAYER_ID)
		    {
		    if(playerid == id)
		        {
		        SendClientMessage(playerid, 0xFF0000FF, "You can't message yourself!");
		        }
			else
			    {
				GetPlayerName(playerid, Sender, sizeof(Sender));
				GetPlayerName(id, Receiver, sizeof(Receiver));
				format(string, sizeof(string), "PM: %s(%i): %s", Receiver, id, message);
				SendClientMessage(playerid, 0xFFE600AA, string);
				format(string2, sizeof(string2), "PM: %s(%i): %s", Sender, playerid, message);
				SendClientMessage(id, 0xFFE600AA, string2);
				}
		    }
		else
		    {
		    SendClientMessage(playerid, 0xFF0000FF, "Player not Connected.");
		    }
		}
	else
 		{
 		SendClientMessage(playerid, 0xFF0000FF, "Use: /pm [ID] [Message]");
		}
	return 1;
}
PHP код:
#include <a_samp>
#include <sscanf2>
#include <zcmd>
CMD:pm(playeridparams[])
{
    new 
idSender[MAX_PLAYER_NAME], Receiver[MAX_PLAYER_NAME];
    new 
string[90], string2[90],message[128];
    if(
sscanf(params"us[128]"idmessage)) return SendClientMessage(playerid0xFF0000FF"Use: /pm [ID] [Message]");
    if(
id == INVALID_PLAYER_ID || !IsPlayerConnected(id)) return SendClientMessage(playerid0xFF0000FF"Player not Connected.");
    if(
playerid == id) return SendClientMessage(playerid0xFF0000FF"You can't message yourself!");
    
GetPlayerName(playeridSendersizeof(Sender));
    
GetPlayerName(idReceiversizeof(Receiver));
    
format(stringsizeof(string), "PM: %s(%i): %s"Receiveridmessage);
    
SendClientMessage(playerid0xFFE600AAstring);
    
format(string2sizeof(string2), "PM: %s(%i): %s"Senderplayeridmessage);
    
SendClientMessage(id0xFFE600AAstring2);
    return 
1;

Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)