Making A Simple /PM command. -
AstonDA-G - 29.11.2011
Okay, this is my first tut, so sorry if it's bad.
First of all, I'm using
zcmd and
sscanf in this tutorial, so you need to download them if you haven't got them.
Once you have them, you need to add them in your script.
Code:
#include <sscanf>
#include <zcmd>
Okay, now we're ready to start the command. Now we need to create the command.
Code:
COMMAND:pm(playerid, params[])
{
return 1;
}
So, now we've got the command, we can make it do things, but firstly, we need to declare new things...
Code:
new id, string[128], string2[128], sender[MAX_PLAYER_NAME], reciever[MAX_PLAYER_NAME];
'id' will be the person to send the PM to, so with sscanf, we will detect if the sender hasn't put an id, or message.
Code:
if(sscanf(params, "us[75]", id, params[2])) return SendClientMessage(playerid, 0xFFFFFFFF, "Usage: /pm <id> <message>");
//params[2] is the text after the player has typed the id.
Now, we need to get the names of the sender and reciever, this is simple.
Code:
GetPlayerName(playerid, sender, sizeof(sender)); //sender will be playerid, the one who is typing the command.
GetPlayerName(id, reciever, sizeof(reciever)); //reciever will be the name of the player we send the PM to.
Next, we can format the two stringsthat are sent and recieved.
Code:
format(string, sizeof(string), "PM recieved from %s: %s", sender, params[2]); //sender's name, followed by the message he sent.
format(string2, sizeof(string2), "PM sent to %s: %s", reciever, params[2]); //reciever's name, followed by the message that this player wrote.
Everything is formatted, and now, we can send the two strings to the players.
Code:
SendClientMessage(id, 0xFFFFFFFF, string);
SendClientMessage(playerid, 0xFFFFFFFF, string2);
PLEASE NOTE: All of these messages will be sent in white. You can change the color if you want to.
And there we are, done. Hope this helped,
-Aston.
Re: Making A Simple /PM command. -
seanny - 29.11.2011
This is quite usefull, Rep+'ed
Re: Making A Simple /PM command. -
HyperZ - 29.11.2011
Change:
pawn Code:
if(sscanf(params, "us", id, params[2]))
To:
pawn Code:
if(sscanf(params, "us[75]", id, params[2]))
By the way, good tut for your first.
Re: Making A Simple /PM command. -
AstonDA-G - 29.11.2011
Quote:
Originally Posted by HyperZ
Change:
pawn Code:
if(sscanf(params, "us", id, params[2]))
To:
pawn Code:
if(sscanf(params, "us[75]", id, params[2]))
By the way, good tut for your first.
|
I didnt know i had to have a string length, none of my cmds do, but thankyou, and i'll change that now
Re: Making A Simple /PM command. -
Nodroz - 29.11.2011
Nice try for your first tutorial!
Could try to script a /r(eply) too ? That would be cool.