31.01.2011, 13:07
Using sscanf and zcmd:
Untested, but it should work.
pawn Код:
CMD:pm(playerid, params[]) {
new
szPlayerName[MAX_PLAYER_NAME], // Create a string to store a player name
szFormatString[120], // Create a string to format the message, 64 for the message and 24 for MAX_PLAYER_NAME
iPlayerID, // Create a variable for the returned player ID to be assigned to
szMessage[64]; // And for the message once split by sscanf
// Split the input that the user provided, split it in to the two variables created above.
if(sscanf(params, "us[64]", iPlayerID, szMessage)) return SendClientMessage(playerid, 0xFFFF00FF, "Incorrect usage! The usage is: /pm [playerid/name] [message]");
// Check whether the player is connected or not, sscanf returns INVALID_PLAYER_ID if it doesn't find a name/id connected with the criteria provided
if(iPlayerID == INVALID_PLAYER_ID) return SendClientMessage(playerid, 0xFFFF00FF, "That player is not connected");
// Get the name of the player who is sending the message, format it in a string with the message and send it to the player who is to be sent the PM
GetPlayerName(playerid, szPlayerName, MAX_PLAYER_NAME);
format(szFormatString, sizeof(szFormatString), "Message from %s: %s", szPlayerName, szMessage);
SendClientMessage(iPlayerID, 0xFFFF00FF, szFormatString);
// Send a message back to the person who sent it, to confirm that the message was sent
// Get the player's name who it was sent to, format that message and send it
GetPlayerName(iPlayerID, szPlayerName, MAX_PLAYER_NAME);
format(szFormatString, sizeof(szFormatString), "You sent this message to %s: %s", szPlayerName, szMessage);
SendClientMessage(playerid, 0xFFFF00FF, szFormatString);
// We're done here now. Let's return 1.
return 1;
}