31.07.2010, 17:06
(
Последний раз редактировалось Toni; 19.09.2010 в 16:04.
)
Hi there, I'll show you have to make a simple PM command system using ZCMD (Click Me!) and sscanf.
First off, lets include zcmd (download it if you don't have it).
So now we can use zcmd!
Now, lets create the command pm.
Now that we have the actual command, we can start declaring new things to add.
We need to make those, so we don't get "Unknown Symbol".
So, next up is using sscanf to check if the player typed anything after "/pm"
Lets sort it out:
u = ID, or Name.
s = string.
{Float,_}:...
ID/Name = The ID/Name they inserted into their PM.
str2 = The message they inserted into their PM.
------------------------------------------------
So now that we have checked if they inserted a ID and Message, sscanf automatically assigns it to the declaration.
so no need to do str2 = strrest(params, idx). (Thank god ******).
Next we check if the player they entered is connected or not:
Now we check if they sent the PM to themselves, or another person.
So now we move on to sending the messages!
First off, we need to get the player's name, and the receiver's name.
Then, now that we have their names, we format the string (message) to send/receive.
And so, with all of this added, it should look something like this:
Hoped this helped!
| - The Toni - |
First off, lets include zcmd (download it if you don't have it).
pawn Код:
#include <zcmd>
Now, lets create the command pm.
pawn Код:
CMD:pm(playerid, params[])
{
return 1;
}
pawn Код:
new str[128], str2[128], id, Name1[MAX_PLAYER_NAME], Name2[MAX_PLAYER_NAME];
So, next up is using sscanf to check if the player typed anything after "/pm"
pawn Код:
if(sscanf(params, "us", id, str2))
{
SendClientMessage(playerid, 0xFF0000FF, "Usage: /pm <id/name> <message>");
return 1;
}
u = ID, or Name.
s = string.
{Float,_}:...
ID/Name = The ID/Name they inserted into their PM.
str2 = The message they inserted into their PM.
------------------------------------------------
So now that we have checked if they inserted a ID and Message, sscanf automatically assigns it to the declaration.
so no need to do str2 = strrest(params, idx). (Thank god ******).
Next we check if the player they entered is connected or not:
pawn Код:
if(!IsPlayerConnected(id)) return SendClientMessage(playerid, 0xFF0000FF, "ERROR: That player is not connected!");
//We did IsPlayerConnected(id)) because we are checking the player they want to send the pm too.
pawn Код:
if(playerid != id) return SendClientMessage(playerid, 0xFF0000FF, "ERROR: You cannot pm yourself!");
First off, we need to get the player's name, and the receiver's name.
pawn Код:
GetPlayerName(playerid, Name1, sizeof(Name2)); //The Sender's Name so we use (playerid).
GetPlayerName(id, Name2, sizeof(Name2)); //The Receiver's Name so we use (id).
Then, now that we have their names, we format the string (message) to send/receive.
pawn Код:
//This is where we use string #1 (str). Now that we have created, we float The Receiver's name, their ID, and the message!
format(str, sizeof(str), "PM To %s(ID %d): %s", Name2, id, str2);
//Now we send the sender a message repeating what they sent to the receiver:
SendClientMessage(playerid, 0xFF0000FF, str); //Notice its (playerid, not id)
//Now we repeat the first format, but we change it a little, this is the message getting sent to the receiver:
format(str, sizeof(str), "PM From %s(ID %d): %s", Name1, playerid, str2);
//Float Sender's Name, Sender's ID, and Sender's Message.
//After we have formated the message, we send it to the receiver!
SendClientMessage(id, 0xFF0000FF, Message); //Notice its (id, not playerid).
And so, with all of this added, it should look something like this:
pawn Код:
CMD:pm(playerid, params[])
{
new str[256], str2[256], id, Name1[MAX_PLAYER_NAME], Name2[MAX_PLAYER_NAME];
if(sscanf(params, "us", id, str2))
{
SendClientMessage(playerid, 0xFF0000FF, "Usage: /pm <id> <message>");
return 1;
}
if(!IsPlayerConnected(id)) return SendClientMessage(playerid, 0xFF0000FF, "ERROR: Player not connected");
if(playerid == id) return SendClientMessage(playerid, 0xFF0000FF, "ERROR: You cannot pm yourself!")
{
GetPlayerName(playerid, Name1, sizeof(Name1));
GetPlayerName(id, Name2, sizeof(Name2));
format(str, sizeof(str), "PM To %s(ID %d): %s", Name2, id, str2);
SendClientMessage(playerid, 0xFF0000FF, str);
format(str, sizeof(str), "PM From %s(ID %d): %s", Name1, playerid, str2);
SendClientMessage(id, 0xFF0000FF, str);
}
return 1;
}
| - The Toni - |