[Tutorial] Making A Simple /PM command.
#1

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.
Reply
#2

This is quite usefull, Rep+'ed
Reply
#3

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.
Reply
#4

Quote:
Originally Posted by HyperZ
View Post
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
Reply
#5

Nice try for your first tutorial!

Could try to script a /r(eply) too ? That would be cool.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)